Volume Pressure Analysis - Overlay
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © veryfid

//@version=4
study("Volume Pressure Analysis", overlay = true)

spike = close - open <= 0 ? open - close  : close - open

avglength = input(30,"Lookback bars for Average",group = "General Settings")
avg = array.new_float(0)
for i = 1 to avglength
	array.push(avg, spike[i])

rvol = spike / array.avg(avg)

//plot(rvol)

avg2 = array.new_float(0)
for i = 1 to avglength
	array.push(avg2, volume[i])

rvol2 = volume / array.avg(avg2)
rvol3 = rvol - rvol2 > 0 ? rvol - rvol2 : na
rvol4 = rvol - rvol2 < 0 ? rvol - rvol2 : na
rvolsma = sma(volume,20)
float(rvol3)
float(rvol4)
//plot(rvol - rvol2, style = plot.style_columns, color = rvol - rvol2 > 0 ? color.teal : color.red)

sma1 = sma(rvol3, 20)
sma2 = sma(rvol4, 20)
//plot(sma(rvol - rvol2 < 0, 20))
plotshape(rvol4 < sma2 and open < close , color = color.yellow, style = shape.triangledown, location = location.abovebar)
plotshape(rvol4 < sma2 and open > close , color = color.yellow, style = shape.triangleup, location = location.belowbar)
plotshape(rvol3 > sma1 and open < close , color = #80deea, style = shape.triangleup, location = location.belowbar)
plotshape(rvol3 > sma1 and open > close , color = color.red, style = shape.triangledown, location = location.abovebar)

barcolor(rvol - rvol2 > sma1 and close > open ? #80deea : rvol - rvol2 > sma1 and open > close ? #ffcdd2 : na)