Subsequent to this, I am facing a strange problem with VWAP and MVWAP plotting.
I find that in 5 minute chart, some consecutive VWAP values are zero. Based on McAllan’s code, I tried to code in such a way that if the previous values are zero, code will omit the zero value and take up the last non-zero value. This will take care of upto 4 zero values
But in some cases, I am finding that VWAP is getting picked up as zero but in other cases, its OK.
Also once the MVWAP value is getting zero, it is staying as zero value throughput. Not able to avoid this by coding. If someone help coding this properly, that will be of great help. I am not able to figure out what can be the correct expression to take care off this type of scenarios.
Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_BEGIN("Volume At Price");
/*
f=14;
VWAP=Sum(V*C,f)/Sum(V,f);
*/
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 091500, BarIndex());
TodayVolume = Sum(V,Bars_so_far_today);
VWAP = Sum(C * V, Bars_so_far_today ) / TodayVolume; // Redundant IIF() removed
VWAP = IIf(Nz(VWAP) == 0, IIf(Nz(Ref(VWAP, -1))==0, IIf(Nz(Ref(VWAP, -2))==0, IIf(Nz(Ref(VWAP,-3))==0,Ref(VWAP,-4),Ref(VWAP,-3)),Ref(VWAP,-2)),Ref(VWAP,-1)), VWAP);
Plot (VWAP,"VWAP",colorOrange, styleThick);
Plot(EMA(vwap,50), "MVWAP", colorblue, styleThick);
_SECTION_END();
