Stop Orders Above Market Order Rejected Error 

Part 1 - Historical Execution

Hello guys!

I bet you have received this frustrating message a few times whilst using NinjaTrader!

“Sell stop or sell stop limit orders can’t be placed above the market. Strategy submitted an order that generated the following error - order rejected. Strategy has sent cancel requests, attempted to close the position and terminated itself.”

Pretty frustrating isn’t it? There are a few occasions when they occur and in this short article, I will talk about one of them. 

Let’s imagine your strategy has the following logic. We are executing on bar close and if the bar closes and we get an entry signal we enter the market using a market order like this:

So when the green bar closed in the above example, we received an entry signal and entered by market. Please note that for the sake of simplicity of understanding let’s stay in the context of backtesting which means we are not talking about NinjaTrader market replay, simulation or live market mode. We are strictly talking about on bar execution during a historical backtest.

During historical backtests NinjaTrader will fill your market orders by the open price therefore we get filled by the open of the red bar. What happens next is very interesting. Let’s imagine that our strategy is designed to place a stop loss at the level of the initial stop and initialize 2 profit targets as shown on the picture once the entry occurs.

Also, we would like to move the stop loss to breakeven once we hit a profit target 1. This is a very straight forward set up that can, however, cause errors during historical backtest and replay or live as well. I will talk about the replay situation in further posts so stay tuned and subscribe!

Now, when bar 1 (the green one) closes we know nothing yet however when the second bar closes (the red one) we find out that 

  1. We have entered the market by open price

  2. We have hit our profit target 1

  3. We need to move our stop to break even

  4. Our close price is below the stop!!!

So once the bar has closed NinjaTrader finds out that it needs to place a stop above the close of the current bar! Now, you might say this is not possible during a live market situation because the market would have been high up hitting the profit target and we would have had no problem adjusting our stop but stay tuned and subscribe to find out how to fix this issue on the live market as well. It is a little bit different but much harder to spot! It took me ages to debug that issue.

So what is the solution for the historical backtest? One possible solution is to look at the close price of the bar before moving the stop to break even and stay with the initial stop if the close is below it. However, this can lead to the following situation:

We were expecting the situation on the right but can get the situation on the left. This can have a huge impact on our backtesting results. There are however various ways to solve this issue that can be better than we will talk in our further blog posts so stay tuned and subscribe!