Just tried building my first strategy. The startegy looks at price change (close vs close[-1]) and uses input var to define an intervall.
I get this error message when I try to enable it in a chart.
Strategy 'lctrial': Error on calling 'OnBarUpdate' method on bar 1: 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.
...but I´m only accessing -1 bars back?
See code below.
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
Upprpocent = 1.02;
Maxprocent = 1.13;
Stddev = 1;
Closeniva = 0.5;
Omsattning = 400000;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Close[0] >= (Close[-1] * Upprpocent) )
&& (Close[0] <= (Close[-1] * Maxprocent) ))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
// Set 2
if ((Close[0] <= (Close[-1] * Upprpocent) )
|| (Close[0] >= (Close[-1] * Maxprocent) ))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
}
Comment