Y/Q/M/W aVWAP Bands
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © crypto_rife

//@version=5
indicator("VWAP Bands", overlay=true)

tf = input.timeframe("1M", "Time Frame", options=['1W', '1M', '3M', '12M'])
showVwap = input.bool(true, title="Show VWAP")
showDev = input.bool(true, title="Show VWAP St Dev Band")
stdev = input.int(1, title="St Dev")

bgColor = color.new(color.gray, 90)
borderColor = color.new(color.gray, 100)
lineColor = color.new(color.blue, 50)

t = time(tf)
start = na(t[1]) or t > t[1]

var pvwapLine = line(na)
var pvwapBox = box(na)

pvwap = float(na)
pupper = float(na)
plower = float(na)

[vwap, upper, lower] = ta.vwap(close, start, stdev)

pvwap := start ? vwap[1] : pvwap[1]
pupper := start ? upper[1] : pupper[1]
plower := start ? lower[1] : plower[1]

if (start)
    line.delete(pvwapLine)
    box.delete(pvwapBox)
    pvwapLine := line.new(x1=bar_index-1, y1=vwap[1], x2=bar_index+1, y2=vwap[1], extend=extend.right, style=line.style_dashed, color=lineColor)
    pvwapBox := box.new(bar_index, pupper, bar_index+1, (plower), extend=extend.right, border_color=borderColor, bgcolor=bgColor)

plot(vwap, title="VWAP", color=lineColor)
MU1=plot(upper, title="VWAP Upper Band", color=color.red, transp=100)
MD1=plot(lower, title="VWAP Lower Band", color=color.red, transp=100)
fill(MD1,MU1, color=bgColor, transp=93, title="Inner Band")