In NT8 though, it seems that this has a different behaviour.
else if (State == State.Terminated) { Print(TestVariable); }
Firstly, upon compiling, this seems to be called 3 times.
Then in backtesting, after clicking Run, this is called once before the backtest starts. When it does this, it seems to print the value that TestVariable had after a previous backtest (i.e. non-zero). At the end of the backtest, this is called again (as expected this time), but prints a zero value (when it should have been non-zero).
When a strategy is run live however, no problems. No value is printed when the strategy is enabled (unlike when the backtest was run). After disabling the strategy, it returns a non-zero value - perfect.
So I'm not sure if this is a bug but going from what I was able to do in NT7, and the consistency between behaviours of Print() in OnTermination() between backtesting and live strategies, it seems to me that there might be an issue using Print() in OnStateChange() when State.Terminated in backtesting only.
Comment