//PRC_Bull&Bear Volume on Price | indicator
//05.07.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam drawonlastbaronly=true
StartTime = 083000
// --- settings
ScaleFactor = 6
NbrBars=40
lookback= 120
// --- end of settings
hh=highest[lookback](high)
ll=lowest[lookback](low)
div = (hh-ll)/NbrBars
i=0
volsum=summation[lookback](volume)
startbar = barindex[lookback]
while i<NbrBars do
lrange=ll+div*i
hrange=lrange+div
volbull=0
volbear=0
for j = 1 to lookback do
if close[j]>=lrange and close[j]<=hrange then
if close[j]>open[j] then
volbull=volbull+volume[j]
else
volbear=volbear+volume[j]
endif
endif
next
bullbar = round((volbull*lookback)/volsum)*scalefactor
bearbar = round((volbear*lookback)/volsum)*scalefactor
drawrectangle(startbar,lrange,startbar+bullbar,hrange) coloured(46,139,87)
drawrectangle(startbar,lrange,startbar+bearbar,hrange) coloured(255,0,0)
if bullbar>bearbar then
drawtext("■",startbar+bullbar,(lrange+hrange)/2,Dialog,Bold,22) coloured(46,139,87)
else
drawtext("■",startbar+bearbar,(lrange+hrange)/2,Dialog,Bold,22) coloured(255,0,0)
endif
i=i+1
wend
drawvline(barindex[lookback])
return