protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Line, "ER"));
ATRperiod = 21;
ClosePeriod = 21;
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Print(Time[0].ToString());
double ATRvalue = ATR(ATRperiod)[0];
Print("current ATR value is" + ATRvalue.ToString());
Print (Close[0]);
Plot0.Set (Close[0]);
// Print (Close[ClosePeriod]);
// Closediff = Math.Abs (Close[0]- Close[ClosePeriod]);
// Print("current Closediff is" + Closediff.ToString());
// double ER = Math.Abs (Closediff / ATRvalue);
// Plot0.Set (ER);
// Print("ER" + ER.ToString());
The ATR function works fine; but If i use any value for Close[barsago] other than "0" i.e. current bar, the code won't work and I get this meassage in the log:
Error on calling the 'OnBarUpdate' method for indicator 'ER' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection.
I would be embarassed to admit how long I have spent on this without figuring out the problem
please help?
Comment