Error on calling 'OnBarUpdate' method for indicator 'SwingIndex' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Can anyone help?
Code as follow:
#region Variables
private bool _initialized = false;
private int dailylimit = 10000;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.Orange, "SwingIndex"));
Add(new Line(Color.DarkViolet, 0,""));
Overlay = false;
}
protected override void OnBarUpdate()
{
if (!_initialized)
_initialized = true;
double R1 = Math.Abs(High[0] - Close[1]);
double R2 = Math.Abs(Low[0] - Close[1]);
double R3 = Math.Abs(High[0] - Low[0]);
double R4 = Math.Abs(Close[1] - Open[1]);
double K = Math.Max(R1, R2);
double R ;
double X ;
double T = dailylimit;
if (R1 >= Math.Max(R2, R3))
{
R = R1 - R2/2 + R4/4;
}
else if (R2 >= Math.Max(R1, R3))
{
R = R2 - R1/2 + R4/4;
}
else
{
R = R3 + R4/4;
}
if (CurrentBar == 0)
Value.Set(Input[0]);
else
{
X = (Close[0] - Close[1]) + (Close[0] - Open[0])/2 + (Close[1] - Open[1])/4;
Value.Set(50 * (X/R) * (K/T));
}
}
Comment