i have got a little problem with a simple indicator that colour the last bar if it's an ENGULFING bar, but some day it dosen't work and in the output window i read this error :
"Error on calling 'OnBarUpdate' method for indicator 'Engulfing' 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."
The code is this :
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class Engulfing : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition Long
if (High[0] > High[1]
&& Low[0] < Low[1]
&& Close[0] > Open[0])
{
BarColor = Color.Green;
CandleOutlineColor = Color.Green;
}
// Condition Short
if (High[0] > High[1]
&& Low[0] < Low[1]
&& Close[0] < Open[0])
{
BarColor = Color.Red;
CandleOutlineColor = Color.Red;
}
}
#region Properties
#endregion
}
}
Can someone help me ? Where the error is ?
Thanks
Comment