I am developing a strategy and have come across some weird behaviour, and wanted to know if this is the expected behaviour, and if there is any way of circumventing this.
The strategy uses the swing indicator, and defines stop losses and take profit targets based on the swing values. The strategy supports multi instruments, by having a parameter where the user can input one or several symbols to be tested.
The problem here lies in the different behaviour when using the strategy by defining the instruments to use by setting them in the parameter, versus selecting an instrument from the left pane on the backtest window.
If I select instrument A from the pane, and leave my parameter empty, the stop loss of an opened position is updated on OnBarUpdate, before the end of day events are triggered, and the position is not closed at the previous stop loss, since the stop loss is updated before. If I insert an instrument in my parameter, that instrument is added, but the same position is closed before being able to update its stop loss.
For what I could detect in the backtest (using Kinetick end of day), it appears that the event OnBarUpdate is called for instrument 0 (BarsInProgress = 0), then the events for closing positions at stop losses, and then OnBarUpdate for the remaining instruments. This does not affect the working of the strategy when I select the instrument from the left pane, but if I use anything other than that, having my tested instruments with BarsInProgress != 0, their events are called too late, and the position is already closed by the time they recalculate the stop loss price based on the swing indicator.
Is this the usual behaviour of NinjaTrader? Is there a way to make the OnBarUpdate to be called for all the instruments, before triggering the event that closes the positions if their stop loss price has been reached?
What I want to be able to do is:
OnBarUpdate 0
OnBarUpdate 1
OnBarUpdate N
EndOfDayPositionsClose
instead of:
OnBarUpdate 0
EndOfDayPositionsClose
OnBarUpdate 1
OnBarUpdate N
Thank you in advance for your time.
Comment