//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
//////////////////////////////////////
sumSrcVol = summation[bars](src*volume)
sumVol = summation[bars](volume)
sumSrcSrcVol = summation[bars](pow(src,2)*volume)
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")