I am working on an automated trading strategy that includes a trailing reversal order set at a specific price. My strategy calculates on each tick and I am testing it in market replay. The issue I’m having is that in certain volatile moments the strategy will close and give me this error message:
I have dealt with this problem in the past and simply implemented a check before the order is submitted to make sure we are not submitting a buystop above the ask and a sellstop below the bid. So I did this too in this code block in OnBarUpdate for short and long orders: * One note here is that the order submission code block only executes if the reversal order changes price hence the: (reversalPrice-currentReversalPrice) >=TickSize. This needs to happen so that the order isn’t always executed based on the bid/ask safety fallback.
However, it did not solve the problem. I tried adding additional checks or additional fallbacks in the OnOrderUpdate but nothing seemed to work. Here is also my log leading up to the error:
You can see that the safety check approves the order submission because the current ask is 267.75 which is below the reversalPrice. Then somewhere in-between that approval the price moves away and the order is rejected. Attached is also the bid/ask for these ticks and you can see the spread widens at that moment, but there should be many ticks where the order can be submitted: Time: 9:45 AM, Bid: 20261.75, Ask: 20267.75
Time: 9:45 AM, Bid: 20261.75, Ask: 20268
Time: 9:45 AM, Bid: 20262.5, Ask: 20268
Time: 9:46 AM, Bid: 20262.5, Ask: 20267.75 - Here the bar changes and the new order is submitted
Time: 9:46 AM, Bid: 20262.5, Ask: 20268
Time: 9:46 AM, Bid: 20262.5, Ask: 20268
Time: 9:46 AM, Bid: 20262.5, Ask: 20271.75
Time: 9:46 AM, Bid: 20262.5, Ask: 20271.75
Time: 9:46 AM, Bid: 20262.5, Ask: 20274.75
Time: 9:46 AM, Bid: 20262.5, Ask: 20275
Time: 9:46 AM, Bid: 20262.5, Ask: 20275
Time: 9:46 AM, Bid: 20262.5, Ask: 20275
Time: 9:46 AM, Bid: 20262.5, Ask: 20275
Time: 9:46 AM, Bid: 20262.5, Ask: 20275.75
Time: 9:46 AM, Bid: 20262.5, Ask: 20276
Time: 9:46 AM, Bid: 20262.5, Ask: 20276.25
Time: 9:46 AM, Bid: 20262.5, Ask: 20283.75
Interestingly, the bid stays the same the whole time, so I wonder if it doesn’t register as a “tick”.
If anyone has any ideas for solving this problem, I would be extremely grateful.

Comment