//PRC Rolling VWAP
//version = 0
//06.03.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
///inputs
src = customclose
minBarsInput = 10
stdevMult1 = 1
stdevMult2 = 1.5
stdevMult3 = 2.5
showbands = 1
//////BARS TO CALCULATE VWAP/////////
if gettimeframe < 86400 then
bars = minbarsinput
elsif gettimeframe >= 86400 and gettimeframe < 604800 then
bars = MAX(22,minbarsinput)
elsif gettimeframe = 604800 then
bars = MAX(round(90/5),minbarsinput)
else
bars = MAX(round(252/22),minbarsinput)
endif
//////////////////////////////////////
if dayofweek>=dayofweek[1] then
barsweek=barsweek+1
sumSrcVol = summation[min(bars,barsweek)](src*volume)
sumVol = summation[min(bars,barsweek)](volume)
sumSrcSrcVol = summation[min(bars,barsweek)](pow(src,2)*volume)
else
barsweek=0
sumSrcVol = (src*volume)
sumVol = (volume)
sumSrcSrcVol = (pow(src,2)*volume)
endif
rollingvwap = sumSrcVol / SumVol
variance = sumSrcSrcVol / SumVol - pow(rollingvwap,2)
variance = max(0,variance)
stDev = sqrt(variance)
if showbands then
upperband1 = rollingVwap + stDev*stdevMult1
lowerband1 = rollingVwap - stDev*stdevMult1
upperband2 = rollingVwap + stDev*stdevMult2
lowerband2 = rollingVwap - stDev*stdevMult2
upperband3 = rollingVwap + stDev*stdevMult3
lowerband3 = rollingVwap - stDev*stdevMult3
else
upperband1 = undefined
lowerband1 = undefined
upperband2 = undefined
lowerband2 = undefined
upperband3 = undefined
lowerband3 = undefined
endif
return rollingvwap as "rollingVwap" coloured("orange"),upperband1 as "upperband1"coloured("red"),lowerband1 as "lowerband1"coloured("red"),upperband2 as "upperband2"coloured("yellow"),lowerband2 as "lowerband2"coloured("yellow"),upperband3 as "upperband3"coloured("green"),lowerband3 as "lowerband3"coloured("green")