I have 2 indicators where the difference is one has a List<T> and the other doesn't. The list has tags added to it and nothing else but it is giving out an error message:-
Error on calling 'OnBarUpdate' method on bar 14: 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.
The one without the list doesn't have any error messages. Can you please tell me what is wrong?
The code below uses the List<T>:-
if (CurrentBar < (level*2 + 10)) return;
// if( DemandLineCount == DemandLineMaxCount )
// {
// DemandLines.RemoveAt(DemandLines.Count-1);
// }
// Identify the first pivot low
if((Math.Min(Low[1],Close[2]) < Math.Min(Low[0],Close[1])) && (Math.Min(Low[1],Close[2]) < Math.Min(Low[2], Close[3])))
{
DemandPoint0 = Math.Min(Low[1],Close[2]);
DemandPoint0Y = CurrentBar-level;
// Draw.Dot(this, "DPDot"+CurrentBar, true, 1, DemandPoint0, Brushes.Red, true);
// Print(Time[0].ToString());
// Print("CurrentBara = " + CurrentBar.ToString());
}
// Hunting for a lower pivot low that has already occurred which meets the same pivot low condition and to draw a ray connecting the 2 points
for( int x = 1; x <= Math.Min(CurrentBar-4, 50); x++)
{
if ((Math.Min(Low[x], Close[x+1]) < Math.Min(Low[x-1], Close[x])) && (Math.Min(Low[x], Close[x+1]) < Math.Min(Low[x+1], Close[x+2])))
{
if (Math.Min(Low[x], Close[x+1]) < DemandPoint0)
{
DemandPoint1 = Math.Min(Low[x], Close[x+1]);
DemandPoint1Y = x;
string drawTag = "DPL" + CurrentBar;
Draw.Ray(this, drawTag, true, DemandPoint1Y, DemandPoint1, CurrentBar - DemandPoint0Y , DemandPoint0, Brushes.Pink, DashStyleHelper.Solid, 1);
DemandLineCount++;
DemandLines.Add(drawTag);
Print(Time[0].ToString());
Print("DemandLines Last Item = "+ DemandLines[DemandLines.Count-1]);
Print("DemandLines Last Item = "+ DemandLines[DemandLines.Count-2]);
// Print("x =" + x.ToString());
// Print("low[x] = " + Low[x].ToString());
// Print("low[1] = " + Low[1].ToString());
// Print("CurrentBar = " + CurrentBar.ToString());
// Print("DemandPoint0 = " + DemandPoint0.ToString());
// Print("DemandPoint0Y = " + DemandPoint0Y.ToString());
break;
}
}
}
if (CurrentBar < (level*2 + 10)) return;
// Identify the first pivot low
if((Math.Min(Low[1],Close[2]) < Math.Min(Low[0],Close[1])) && (Math.Min(Low[1],Close[2]) < Math.Min(Low[2], Close[3])))
{
DemandPoint0 = Math.Min(Low[1],Close[2]);
DemandPoint0Y = CurrentBar-level;
// Draw.Dot(this, "DPDot"+CurrentBar, true, 1, DemandPoint0, Brushes.Red, true);
// Print(Time[0].ToString());
// Print("CurrentBara = " + CurrentBar.ToString());
}
// Hunting for a lower pivot low that has already occurred which meets the same pivot low condition and to draw a ray connecting the 2 points
for( int x = 1; x <= Math.Min(CurrentBar-4, 50); x++)
{
if ((Math.Min(Low[x], Close[x+1]) < Math.Min(Low[x-1], Close[x])) && (Math.Min(Low[x], Close[x+1]) < Math.Min(Low[x+1], Close[x+2])))
{
if (Math.Min(Low[x], Close[x+1]) < DemandPoint0)
{
DemandPoint1 = Math.Min(Low[x], Close[x+1]);
DemandPoint1Y = x;
Draw.Ray(this, "DPL1"+CurrentBar, true, DemandPoint1Y, DemandPoint1, CurrentBar - DemandPoint0Y , DemandPoint0, Brushes.Pink, DashStyleHelper.Solid, 1);
// Print(Time[0].ToString());
// Print("x =" + x.ToString());
// Print("low[x] = " + Low[x].ToString());
// Print("low[1] = " + Low[1].ToString());
// Print("CurrentBar = " + CurrentBar.ToString());
// Print("DemandPoint0 = " + DemandPoint0.ToString());
// Print("DemandPoint0Y = " + DemandPoint0Y.ToString());
break;
}
}
}

Comment