And trying to understand the right places to initialize custom variables for historical backtests. I'm running into some cases where my variables seem to lose values. I'm sure this is just because I don't understand the order of state changes and where I need to set things.
So I added this code to OnStateChange in a strategy:
Print(DateTime.Now + ": Current State is State." + State);
8/24/2018 11:55:39 PM: Current State is State.SetDefaults 8/24/2018 11:55:39 PM: Current State is State.SetDefaults 8/24/2018 11:55:39 PM: Current State is State.Terminated Disabling NinjaScript strategy 'Barz - BuyDay SellDay/146636207' 8/24/2018 11:55:39 PM: Current State is State.Configure 8/24/2018 11:55:39 PM: Current State is State.Terminated 8/24/2018 11:55:39 PM: Current State is State.DataLoaded 8/24/2018 11:55:39 PM: Current State is State.Historical 8/24/2018 11:55:39 PM: Current State is State.Transition Enabling NinjaScript strategy 'Barz - BuyDay SellDay/146636207' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes 8/24/2018 11:55:39 PM: Current State is State.Realtime
Questions:
* Why does the Terminated state occur after Configure and before DataLoaded? How should I understand the Terminated state? Is it when the object is shutting down or when the strategy is shutting down? And if the latter then why does it run before DataLoaded?
* In which state should I initialize custom variables for backtests so that they get reset with each new backtest?
Comment