VolT by empowerT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// VolT by empowerT https://www.tradingview.com/u/empowerT/
// ver 1.0
// modifications and 'VolT' concept © by empowerT
//
//@version=4

study(title="VolT by empowerT", shorttitle="VolT by empowerT", format=format.volume)

showMA = input(true)
slen=input(21, title="SMA Length")

vol1=input(1, title="Volume SMA Level #1 X")
vol2=input(2, title="Volume SMA Level #2 X")
vol3=input(5, title="Volume SMA Level #3 X")

v1 = volume* vol1
v2 = volume * vol2
v3 = volume * vol3

showv = input(true, title="Show Volume Levels?")

barColorsOnPrevClose = input(title="Color bars based on previous close", type=input.bool, defval=true)
palette = barColorsOnPrevClose ? close[1] > close ? color.red : color.green : open > close ? color.red : color.green
plot(showMA ? sma(v3,slen) : na, style=plot.style_area, color=color.new(color.aqua,75), title="Volume MA #3")
plot(showMA ? sma(v2,slen) : na, style=plot.style_area, color=color.new(color.blue,75), title="Volume MA #2")

plot(volume, color = color.new(palette,25), style=plot.style_columns, title="Volume")

plot(showMA ? sma(v1,slen) : na, style=plot.style_area, color=color.new(color.yellow,75), title="Volume MA #1")

var line voll1 = na
if showv
    voll1 := line.new(time + 115000, sma(v1,slen), time + 1000000, sma(v1,slen), color=color.new(color.green, 45), style=line.style_dotted, width=1, xloc = xloc.bar_time)
    label label1 = label.new(time + 175000, sma(v1,slen), tostring(vol1) + 'X', textcolor=color.new(color.green, 45), style=label.style_none, xloc = xloc.bar_time)
    line.delete(voll1[1])
    label.delete(label1[1])

var line voll2 = na
if showv
    voll2 := line.new(time + 115000, sma(v2,slen), time + 1000000, sma(v2,slen), color=color.new(color.green, 45), style=line.style_dotted, width=1, xloc = xloc.bar_time)
    label label2 = label.new(time + 175000, sma(v2,slen), tostring(vol2) + 'X', textcolor=color.new(color.green, 45), style=label.style_none, xloc = xloc.bar_time)
    line.delete(voll2[1])
    label.delete(label2[1])
    
var line voll3 = na
if showv
    voll3 := line.new(time + 115000, sma(v3,slen), time + 1000000, sma(v3,slen), color=color.new(color.green, 45), style=line.style_dotted, width=1, xloc = xloc.bar_time)
    label label5 = label.new(time + 175000, sma(v3,slen), tostring(vol3) + 'X', textcolor=color.new(color.green, 45), style=label.style_none, xloc = xloc.bar_time)
    line.delete(voll3[1])
    label.delete(label5[1])

var line vol = na
if showv
    vol := line.new(time + 1000, sma(v1,slen), time + 10000, sma(v1,slen), color=color.new(color.yellow, 5), style=line.style_dotted, width=1, xloc = xloc.bar_time)
    label label5 = label.new(time + 60000, volume, tostring((v1/(sma(v1,slen))*100), "##") +'%', textcolor=color.new(color.yellow, 5), style=label.style_none, xloc = xloc.bar_time)
    line.delete(vol[1])
    label.delete(label5[1])
