Is it possible to have the code of vwap that starts its value at the begin of the week (for any time frame), in alternative starts in a fixed day. thanks
Non mi funziona se prendo solo la parte del codice che riguarda la settimana non ho il valore corretto e se provo a costruire le bande a più dev.std (altro obiettivo) non da risultati corretti.
It does not work if I take only the part of the code that concerns the week I do not have the correct value and if I try to build the bands with several dev.std’s (other objective) it does not return correct results.
Gabriele Battista – English only in the English speaking forum please. Please post in the Italian speaking forum if you want to communicate in Italian.
You can simply make the two unnecessary lines INVISIBLE using the properties of the indicator, once installed on the chart, without changing the code workings. Just replace the RETURN line to get rid of STYLE:
RETURN VWAPweekly as "VWAP Weekly", VWAPmonthly as "VWAP Monthly", VWAPyearly as "VWAP Yearly"
As for bands, you did not tell about your error, But there’s no reason not to be able to draw as many bands as you want (Band2UP/Band2DN, …), this is the same code modified (without removing any original calculation), with just 1 band and the RETURN line reflecting that addition:
//PRC_VWAP weekly,monthly,yearly
//28.09.2016
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
defparam calculateonlastbars=10000
//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)
Band1UP = VWAPweekly + ((std[20](VWAPweekly)) * 2.0) //UPPER band
Band1DN = VWAPweekly - ((std[20](VWAPweekly)) * 2.0) //UPPER band
RETURN VWAPweekly as "VWAP Weekly", VWAPmonthly as "VWAP Monthly", VWAPyearly as "VWAP Yearly",Band1UP,Band1DN
Standard deviation bands calculation of VWAP can be found in this indicator: VWAP intraday