The VWAP is a ratio that measures daily the total volume of trade in a security, as well as its average price. The volume-weighted average price can also be calculated over a given period.
This indicator calculate and plot the VWAP for the Weekly, Monthly and Yearly periods. It needs, of course, that the instrument has Volumes.
//PRC_VWAP weekly,monthly,yearly
//28.09.2016
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//calculation periods
if DayOfWeek=0 or (dayofweek[1]=5 and dayofweek<>5) then
weekbar=barindex
endif
if month<>month[1] then
monthbar=barindex
endif
if year<>year[1] then
yearbar=barindex
endif
once dWeekly=1
once dMonthly=1
once dYearly=1
dWeekly = max(dWeekly, barindex-weekbar)
dMonthly = max(dMonthly, barindex-monthbar)
dYearly = max(dYearly, barindex-yearbar)
VWAPweekly = SUMMATION[dWeekly](volume*typicalprice)/SUMMATION[dWeekly](volume)
VWAPmonthly = SUMMATION[dMonthly](volume*typicalprice)/SUMMATION[dMonthly](volume)
VWAPyearly = SUMMATION[dYearly](volume*typicalprice)/SUMMATION[dYearly](volume)
RETURN VWAPweekly as "VWAP Weekly", VWAPmonthly style(line,2) as "VWAP Monthly", VWAPyearly style(line,3) as "VWAP Yearly"