I'm playing around in NT8 with a NinjaScript strategy entering a new position immediately after a previous trade is closed, sometimes even in the same direction.
Re-enter logic is positioned in "OnExecutionUpdate" and fires off immediately after a TakeProfit or StopLoss is executed and it may or may not reverse the direction of the next trade based on user input or some other logic.
Code Snippets (example):
if ( order.Name == "Profit target" && order.OrderState == OrderState.Filled && order.OrderAction == OrderAction.Sell )
{EnterLong (0, Convert.ToInt32(MyQuantity),"MySignalName");}
or ...
if ( order.Name == "StopLoss" && order.OrderState == OrderState.Filled && order.OrderAction == OrderAction.Sell )
{EnterShort (0, Convert.ToInt32(MyQuantity),"MyOtherSignalName");}
Interestingly, in a backtest, the price at which the next trader is entered is DIFFERENT depending on the direction of the subsequent trade.
Whenever the direction doesn't change, I get the SAME price for the subsequent trade (closing price of previous trade = opening price of next trade).
However, when the direction changes, the subsequent trade is sometimes priced completely different in a backtest although it get's the exact same time stamp as the closing of the previous trade (see Trade 3, 5, 10, 14 in the attached).
Is that expected behaviour? If Yes, how to avoid this in a backtest? I know, I can always run all backtests on ticks, but that is extremely resource consuming, particularly if coupled with complex optimizations. Is there really no other fix?
With an ATM Strategy, one can handle the reverse in ONE order, but to my knowledge, ATM strategies don't work in backtests.
Thus, what is the best approach to handle TURNING the position in ONE(!) order in a backtest or to ensure SAME price otherwise?
Thanks for pointing me in the right direction.
NT-Roland
Comment