I'm having an error saying that i'm accessing a bar that is out of range. I don't get it since I only use current index 0.
"Indicator 'VWAR': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
"
Here is the code (the problem is when a call the vwap[0], because when I take it out it works)
1st indicator not working but the second is working and both call vwap[0],
1st
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Volume Weighted Average Range";
Name = "VWAR";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Purple, "PlotVWAR");
}
else if (State == State.DataLoaded)
{
vwap = new VWAP8();
}
}
protected override void OnBarUpdate()
{
if (Bars.IsFirstBarOfSession)
{
iCumVolume = VOL()[0];
iCumVolumeRange = VOL()[0] * (High[0] - Low[0]);
}
else
{
iCumVolume = iCumVolume + VOL()[0];
iCumVolumeRange = (iCumVolumeRange + (VOL()[0] *(High[0] - Low[0]))) ;
}
PlotVWAR[0] = (iCumVolumeRange / iCumVolume) + vwap[0] ;
}
2nd script working no problem
else if (State == State.DataLoaded)
{
vwap = VWAP8();
stdDev1 = StdDev(vwap,Period);
}
}
protected override void OnBarUpdate()
{
PlotVWAP[0] = vwap[0];
MinusVAR1[0] = vwap[0] - NumStdDev * stdDev1[0];
MinusVAR2[0] = vwap[0] - 2 *NumStdDev * stdDev1[0];
MinusVAR3[0] = vwap[0] - 3 * NumStdDev * stdDev1[0];
PlusVAR1[0] = vwap[0] + NumStdDev * stdDev1[0];
PlusVAR2[0] = vwap[0] + 2 * NumStdDev * stdDev1[0];
PlusVAR3[0] = vwap[0] + 3 * NumStdDev * stdDev1[0];
Thanks

Comment