Hi,
I'm trying to code pine script indicator "TheVWAP Boulevard" into AFL. This indicator actually identifies last 3 highest volume days for the given lookback period and draws horizontal lines at VWAP levels on those days. Below image shows the indicator and also the link for Tradingview indicator (TheVWAP Boulevard — Indicator by TheVWAP — TradingView India).
I'm facing multiple issues while trying to code.
- The lookback period is changing while I'm zooming in or out
- Instead of given lookback period , the code is identifying the highest volume days on the entire chart
- Horizontal lines on the vwap levels are appearing only till lookback period
Attaching the code output image for your reference
Any help or guidance is highly appreciated
_SECTION_BEGIN("VWAPB");
// Lookback period of one year
Lookback = 252;
// Calculate the highest volume days
VolumeArray = V;
VolumeArray = IIf(BarIndex() < Lookback, 0, VolumeArray); // exclude the current day from consideration
// Find the highest volume days
HighestVolume1 = 0;
HighestVolume2 = 0;
HighestVolume3 = 0;
for (i = Lookback; i < BarCount; i++)
{
HighestVolume1 = IIf(VolumeArray[i] > HighestVolume1, VolumeArray[i], HighestVolume1);
}
for (i = Lookback; i < BarCount; i++)
{
HighestVolume2 = IIf(VolumeArray[i] > HighestVolume2 AND VolumeArray[i] < HighestVolume1, VolumeArray[i], HighestVolume2);
}
for (i = Lookback; i < BarCount; i++)
{
HighestVolume3 = IIf(VolumeArray[i] > HighestVolume3 AND VolumeArray[i] < HighestVolume2, VolumeArray[i], HighestVolume3);
}
Volume1 = V == HighestVolume1;
Volume2 = V == HighestVolume2;
Volume3 = V == HighestVolume3;
for (i = Lookback; i < BarCount; i++)
{
if (V[i] > HighestVolume1) {
HighestVolume3 = HighestVolume2;
HighestVolume2 = HighestVolume1;
HighestVolume1 = V[i];
} else if (V[i] > HighestVolume2) {
HighestVolume3 = HighestVolume2;
HighestVolume2 = V[i];
} else if (V[i] > HighestVolume3) {
HighestVolume3 = V[i];
}
}
Volume1 = IIf(V == HighestVolume1, 1, 0);
Volume2 = IIf(V == HighestVolume2, 1, 0);
Volume3 = IIf(V == HighestVolume3, 1, 0);
// Plot markers on the highest volume days
PlotShapes(IIf(Volume1, shapeSmallUpTriangle, shapeNone), colorGreen, 0, H, Offset=-15);
PlotShapes(IIf(Volume2, shapeSmallUpTriangle, shapeNone), colorYellow, 0, H, Offset=-25);
PlotShapes(IIf(Volume3, shapeSmallUpTriangle, shapeNone), colorOrange, 0, H, Offset=-35);
// Calculate VWAP for each day
VWAP1 = Sum(C * Volume1, Lookback) / Sum(Volume1, Lookback);
VWAP2 = Sum(C * Volume2, Lookback) / Sum(Volume2, Lookback);
VWAP3 = Sum(C * Volume3, Lookback) / Sum(Volume3, Lookback);
// Plot horizontal lines at VWAP levels of the highest volume days
Plot(VWAP1, "VWAP 1", colorBlue, styleLine);
Plot(VWAP2, "VWAP 2", colorBlue, styleLine);
Plot(VWAP3, "VWAP 3", colorBlue, styleLine);
PlotShapes(IIf(Volume1, styleLine, shapeNone), 0, VWAP1, 0, colorBlue);
PlotShapes(IIf(Volume2, styleLine, shapeNone), 0, VWAP2, 0, colorBlue);
PlotShapes(IIf(Volume3, styleLine, shapeNone), 0, VWAP3, 0, colorBlue);
//Plot Chart
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
_SECTION_END();