0% found this document useful (0 votes)
21 views4 pages

VOLUMESUITE2A

Uploaded by

originspica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

VOLUMESUITE2A

Uploaded by

originspica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

//@version=5

indicator("VolumeSUITE2B", overlay=true, format=format.volume)

// User Inputs
lowerTimeframeTooltip = "The indicator scans lower timeframe data to
approximate up and down volume used in the delta calculation. By
default, the timeframe is chosen automatically. These inputs override
this with a custom timeframe.\n\nHigher timeframes provide more
historical data, but the data will be less precise."
useCustomTimeframeInput = input.bool(false, "Use custom timeframe",
tooltip=lowerTimeframeTooltip)
lowerTimeframeInput = input.timeframe("1", "Timeframe")

// Hollow Candle Customizations


customColorUp = input.color(color.green, "Color for Positive Volume")
customColorDown = input.color(color.red, "Color for Negative Volume")
customTransparency = input.int(70, "Transparency (0-100)")

// Chart Candle Customizations


chartCandleColor = input.color(color.blue, "Color for Chart Candle
Median")
hollowCandleColor = input.color(color.purple, "Color for Hollow Candle
Median")

// Net Volume Label Customizations


labelColorUp = input.color(color.green, "Net Volume Label Color for
Positive")
labelColorDown = input.color(color.red, "Net Volume Label Color for
Negative")
labelPosition = input.string("Above", "Net Volume Label Position",
options=["Above", "Below"])
labelSizeEnabled = input.bool(true, "Enable Net Volume Label Size")
labelSize = input.int(12, "Net Volume Label Size", minval=1, maxval=24)
labelBackgroundColor = input.color(color.black, "Net Volume Label
Background Color")

// Volume Calculation Function


upAndDownVolume() =>
float posVol = 0.0
float negVol = 0.0
var bool isBuyVolume = true

switch
close > open => isBuyVolume := true
close < open => isBuyVolume := false
close > close[1] => isBuyVolume := true
close < close[1] => isBuyVolume := false

if isBuyVolume
posVol += volume
else
negVol -= volume
posVol + negVol

var lowerTimeframe = switch


useCustomTimeframeInput => lowerTimeframeInput
timeframe.isseconds => "1S"
timeframe.isintraday => "1"
timeframe.isdaily => "5"
=> "60"

// Request Lower Timeframe Data


diffVolArray = request.security_lower_tf(syminfo.tickerid,
lowerTimeframe, upAndDownVolume())

// Calculate High, Low, and Cumulative Volume


getHighLow(arr) =>
float cumVolume = na
float maxVolume = na
float minVolume = na

for item in arr


cumVolume := nz(cumVolume) + item
maxVolume := math.max(nz(maxVolume), cumVolume)
minVolume := math.min(nz(minVolume), cumVolume)

[maxVolume, minVolume, cumVolume]

[maxVolume, minVolume, lastVolume] = getHighLow(diffVolArray)

// Calculate Medians
CHARTCANDLEMEDIAN = (high + low) / 2
VOLUMECANDLEMEDIAN = (maxVolume + minVolume) / 2

// Calculate NetVolume
NetVolume = maxVolume - minVolume

// Reference Previous Day's Close


previousClose = request.security(syminfo.tickerid, "D", close[1])

// Proportional Scaling Factor


scalingFactor = input.float(1.0, "Scaling Factor (0.0 to 100.0)",
step=0.1) / 100.0

// Determine Proportional Sizes


rawHollowCandleSize = (NetVolume * scalingFactor) / previousClose
hollowCandleSize = math.max(rawHollowCandleSize, 0.001) // Ensure size
is not zero

// Calculate Candle Body Sizes


candleBodyHigh = CHARTCANDLEMEDIAN + hollowCandleSize
candleBodyLow = CHARTCANDLEMEDIAN - hollowCandleSize

// Colors for Hollow Candles


colorUp = lastVolume > 0 ? customColorUp : na
colorDown = lastVolume < 0 ? customColorDown : na

// Plot the CHARTCANDLEMEDIAN for reference with customization


plot(CHARTCANDLEMEDIAN, title="Chart Candle Median",
color=chartCandleColor, linewidth=2, style=plot.style_stepline)

// Plot customized color candles for HOLLOWCANDLEMEDIAN


plot(VOLUMECANDLEMEDIAN, title="Hollow Candle Median",
color=hollowCandleColor, linewidth=2, style=plot.style_stepline)

// Convert integer size to predefined label size


labelSizeConverted = labelSize <= 8 ? size.small :
labelSize <= 12 ? size.normal :
size.large

// Display NetVolume Label with customization


if labelSizeEnabled
label.new(x=bar_index, y=labelPosition == "Above" ? high : low,
text=str.tostring(NetVolume), color=labelBackgroundColor,
textcolor=color.white, style=label.style_label_down,
size=labelSizeConverted)
else
labelColorBold = lastVolume > 0 ? color.green : color.red
label.new(x=bar_index, y=labelPosition == "Above" ? high : low,
text=str.tostring(NetVolume), color=na, textcolor=labelColorBold,
style=label.style_label_down, size=size.normal)

// Plot hollow candles


plotcandle(open=candleBodyLow, high=high, low=low, close=candleBodyHigh,
color=color.new(color.white, customTransparency), // Body is
white with transparency for hollow effect
wickcolor=lastVolume > 0 ? customColorUp : customColorDown,
bordercolor=lastVolume > 0 ? customColorUp : customColorDown,
title="Volume Intel")
// Cumulative Volume Check
var float cumVol = 0.0
cumVol := na(volume) ? cumVol : cumVol + volume
if barstate.islast and cumVol == 0
runtime.error("The data vendor doesn't provide volume data for this
symbol.")

// Plot real-time dots on chart median


plotshape(series=CHARTCANDLEMEDIAN, location=location.absolute,
color=color.blue, style=shape.circle, size=size.small, title="Chart
Median Dot")

// Plot real-time triangles on hollow chart median


plotshape(series=VOLUMECANDLEMEDIAN, location=location.absolute,
color=color.purple, style=shape.triangleup, size=size.small,
title="Hollow Chart Median Triangle")

You might also like