This works fine to backtest, but when I set the Strategy Analyzer to optimize, the error "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object" appears.
I added some prints and the error appears in State.Configure. In State.Configure there is method that simply reads the timeframe of a strategy and adds a DataSeries.
I insist, it works fine for backtesting.
I paste the code:
protected override void OnStateChange()
{
{
Name = "MyOptimizerTakeProfis";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.ImmediatelySubmit;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
IsInstantiatedOnEachOptimizationIteration = false;
PositionType = 0;
IndType = @"Indicator1";
PercStopProfit = 0;
TakeProfits = 0;
TakeProf1 = 10;
TakeProf2 = 25;
}
else if (State == State.DataLoaded)
{
}
else if (State == State.Configure)
{
Instr = Instrument.FullName;
ReadMyTimeFrame();
AddDataSeries(BarsPeriodType.Minute, MyTimeFrame); //BIP = 1
Print("Configure 2");
}

Comment