// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.
0
International (CC BY-NC-SA 4.0) [Link]
// © LuxAlgo
//@version=5
indicator( 'Volume Delta Candles [LuxAlgo]'
, shorttitle='LuxAlgo - Volume Delta Candles'
, max_labels_count=500
, overlay=true
),n=bar_index
//------------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------{
tick = [Link] ('LTF' , 'Data from: ', options= [ 'Ticks' , 'LTF'
] )
res = [Link]( '1'
, tooltip= "Data from: 'LTF'\nAuto: 'Disabled'" )
auto = [Link] ( true , '' , inline='auto'
)
mlt = [Link] ( 1500 , ' Auto ' , inline='auto'
, tooltip="current TF divided by x\n\nData from: 'LTF'\nAuto: 'Enabled'")
prem = [Link] ( false , 'Premium' , tooltip= 'Premium Plan or
higher')
colUp = [Link] (#089981 , 'Up ' , inline='u', group='Intrabar
Delta')
colUp_ = [Link] (#f23645 , 'Up - ' , inline='u', group='Intrabar
Delta', tooltip= 'Up -\n-> bullish candle and - Delta' )
colDn = [Link] (#f23645 , 'Down' , inline='d', group='Intrabar
Delta')
colDn_ = [Link] (#089981 , 'Down +' , inline='d', group='Intrabar
Delta', tooltip='Down +\n-> bearish candle and + Delta')
option = [Link] ('full bar', 'Display' , options= ['half bar', 'full
bar'] )
dot = [Link] ( false , 'Show Previous Max Volume
Price' )
showTab= [Link] ( true , 'Show TF' , group= 'Table'
)
tabCol = [Link] (#b2b5beaa , 'Text Color' , group= 'Table'
)
sizeT = [Link] ([Link] , 'Size Table' , group= 'Table'
, options = [[Link], [Link], [Link], [Link]])
showD = [Link] ( false ,'Show details', group= 'Details'
)
INV = [Link](na,na)
CFG = chart.fg_color
isTick = tick =='Ticks'
isLTF = tick =='LTF'
//-----------------------------------------------------------------------------}
//UDT
//-----------------------------------------------------------------------------{
type bin
varip float p
varip float v
//-----------------------------------------------------------------------------}
//Variables
//-----------------------------------------------------------------------------{
varip float volBl = na
varip float volBr = na
varip float volNt = na
varip bin maxBl = [Link](na, 0)
varip bin maxBr = [Link](na, 0)
varip float vl = na
varip float cl = na
varip float dfP = na
varip float dfV = na
varip float TdfV = na
varip bool ticksAvailable = false
var table tab = na
//-----------------------------------------------------------------------------}
//Execution
//-----------------------------------------------------------------------------{
//Ticks
if isTick
if [Link]
maxBl.v := 0, maxBr.v := 0
cl := open , dfP := 0 // "open"
vl := volume, dfV := 0, TdfV := 0 // "volume" at first tick
volBl := 0 , volBr := 0, volNt := 0 // dfV
else
dfP := close - cl
dfV := volume - vl
switch
dfP > 0 =>
volBl += dfV, TdfV += dfV
if dfV > maxBl.v
maxBl.v := dfV, maxBl.p := close
dfP < 0 =>
volBr += dfV, TdfV += dfV
if dfV > maxBr.v
maxBr.v := dfV, maxBr.p := close
cl := close
vl := volume
//LTF
tfS = timeframe.in_seconds( res )
tfC = timeframe.in_seconds([Link])
rs = auto ? tfC / mlt : tfS
rs := prem ? rs : [Link](60, rs)
res := timeframe.from_seconds([Link](tfC, rs))
[bV, sV, nV, tV, aCl] = request.security_lower_tf(
[Link], res ,
[
close > open ? volume : 0
, close < open ? volume : 0
, close == open ? volume : 0
, volume
, close
] )
vSize = [Link]()
//Highest volume when price movement (neutral volume not included)
float maxV = na, float bVmax = na , float sVmax = na
if isLTF
bVmax := [Link]()
sVmax := [Link]()
indices = (bVmax > sVmax ? bV : sV).sort_indices([Link])
maxV := [Link]() > 0 ? [Link]([Link]()) : na
else
if maxBl.v != 0 or maxBr.v != 0
maxV := maxBl.v > maxBr.v ? maxBl.p : maxBr.p
// start Tick data
if not ticksAvailable and volBl > 0
ticksAvailable := true
isAllowed = isTick ? ticksAvailable : [Link]() > 0
if isAllowed and not isAllowed[1]
[Link](n, close, n, close + [Link], color=[Link],
style=line.style_dotted, extend=[Link])
ltf_Vup = [Link]()
ltf_Vdn = [Link]()
bullV = isTick ? volBl : ltf_Vup
bearV = isTick ? volBr : ltf_Vdn
abs = [Link](open - close)
min = [Link](open , close)
max = [Link](open , close)
avg = [Link](open , close)
vol = bullV + bearV
delta = bullV - bearV
norm = delta / volume
aNorm = [Link](norm)
pos = norm >= 0
float base = na
float value = na
value := option == 'half bar' ? avg + norm*abs/2 : pos ? min + aNorm*abs : max -
aNorm*abs
base := option == 'half bar' ? avg : pos ? min : max
css = close > open ? colUp : close < open ? colDn : CFG
cssD = [Link](norm > 0 ? close > open ? colUp : colDn_ : close < open ? colDn
: colUp_, 50)
//-----------------------------------------------------------------------------}
//Plot
//-----------------------------------------------------------------------------{
barcolor(INV) // use 'Bar's style' "Bars"
plotcandle(base, base, value, value, color = cssD, wickcolor = na , bordercolor =
na , display = [Link] - display.status_line)
plotcandle(open, high, low , close, color = na , wickcolor = css, bordercolor =
css , display = [Link] - display.status_line)
plotcandle(maxV, maxV, maxV , maxV , color = CFG , wickcolor = na , bordercolor =
CFG , display = [Link] - display.status_line)
plot (dot ? maxV : na , color = CFG , style=plot.style_circles ,
offset=1, display = [Link] - display.status_line)
plot (bullV ,
display = display.data_window)
plot (bearV ,
display = display.data_window)
//-----------------------------------------------------------------------------}
//Details
//-----------------------------------------------------------------------------{
volu = [Link](vol , [Link] )
delt = [Link](delta , [Link] )
perc = [Link](norm * 100, [Link])
if isAllowed and showD
[Link](
n
, high
, color=INV
, textcolor=CFG
, size=[Link]
, text=[Link](
"Volume: {0}\nDelta: {1}\n%: {2}"
, volu , delt, perc)
)
//-----------------------------------------------------------------------------}
//Table
//-----------------------------------------------------------------------------{
if showTab and isLTF
if [Link]
tab := [Link](position.top_right, 1, 1
, bgcolor=INV
)
if [Link]
[Link](0, 0, res, text_color=tabCol)
//-----------------------------------------------------------------------------}