Early Relative Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EasyTradingSignals

//@version=4
//This indicator attempts to show what the relative volume is per current e.g. minute to the relative volume of the previous candle's average minute 
//This means that instead of having to wait to see if the volume of the current bar is greater than the previous one, you can get an early indication if it is greater
study(title="Early Relative Volume", shorttitle="ETS ERV", format=format.volume, resolution="")
showMA = input(false)
barColorsOnPrevClose = input(title="Blue bars if candle body and volume bigger", type=input.bool, defval=true)

secondsLeft = barstate.isrealtime ?
     (time_close - timenow) / 1000 :
     na
     
timeDiff = time[1] - time[2]
barSeconds = timeDiff / 1000
     
//Calc relative volume
vcurr = volume/(barSeconds-secondsLeft)
vprev = volume[1]/barSeconds

//Calc relative candle body size
pcurr = abs(open-close)/(barSeconds-secondsLeft)
pprev = abs(open[1]-close[1])/barSeconds

palette = vcurr < vprev ? color.silver : barColorsOnPrevClose ? pcurr > pprev ? color.blue : #66FFFF : #66FFFF
plot(volume, color = palette, style=plot.style_columns, title="Volume")

palettep = volume[1] < volume[2] ? color.silver : barColorsOnPrevClose ? abs(open[1]-close[1]) > abs(open[2]-close[2]) ? color.blue : #66FFFF : #66FFFF
plot(volume[1], color = palettep, style=plot.style_columns, title="Volume", offset=-1)

plot(showMA ? sma(volume,20) : na, style=plot.style_line, color=color.blue, title="Volume MA")


