I get an IndexOutOfBounds Exception on the Value[0] = direction statement in the code below. CurrentBar = 15.
Why is there an issues in assigning a value to the Values series at this point ?
protected override void OnBarUpdate()
{
if(CurrentBar<15)
return;
int direction = 0; // 1 is green/up, -1 is red/down, 0 is neutral
ma1 = GetMovingAverageValue(Close, period1);
ma2 = GetMovingAverageValue(Open, period2);
ma3 = GetMovingAverageValue(Close, period3);
double max = Math.Max(Math.Max(ma1, ma2), ma3);
double min = Math.Min(Math.Min(ma1, ma2), ma3);
double dif = max - min;
double filter = ATR(14)[0] * (40/100);
if(ma1 > ma2 && dif > filter)
{
direction = 1;
BarBrush = Brushes.Green;
}
else if(ma2 > ma1 && dif > filter)
{
direction = -1;
BarBrush = Brushes.Red;
}
else
{
direction = 0;
BarBrush = Brushes.Gray;
}
Value[0] = direction;
}

Comment