No announcement yet.

Partner 728x90


Market order not filling

  • Filter
  • Time
  • Show
Clear All
new posts

    Market order not filling

    Hello forum,

    I'm having an issue with market orders not filling when testing in Backtest.

    I found this post helpful:

    However, it seems that I've found a new instance of the market order not filling. I've used the Visual Studio debugger to set breakpoints in both OnExecutionUpdate and OnOrderUpdate to confirm that all orders are canceled or filled and all order variables are set to null.

    Yet the new order still does not fill. This only happens in the same case as the post above, when the strategy attempts to enter on the bar immediately following an exit.

    Since the order does not fill there is no more trading for the duration of the time frame.

    Any ideas on how to fix this without forcing the strategy to wait a bar?
    NinjaTrader Ecosystem Vendor - QTradez

    Hello daq40,

    Thank you for your post.

    It seems that this could be caused by historical overfill. Historical overfill happens when multiple orders are placed that do not use OCO to tie them together. Using Exit method orders (ExitLongStopMarket/ExitLongLimit) is an example of this. Historical overfills occur when multiple orders are filled on the same bar which can put the strategy in the opposite direction and can result in a historical order getting stuck with a "Working" status. For example, if you have 1 long position and your strategy places 2 sell orders based on two separate conditions and the orders are placed on the same bar, you would end up 1 short when instead you were expecting to have 1 sell order place to end up in a flat position.

    A quick test could be done to confirm if this is caused by historical overfill. To test if this is historical overfill, you could set your strategy to use High Order Fill Resolution to submit orders to a single tick data series. This allows you to bring in intrabar granularity in an effort to have orders filled on separate fill bars that would otherwise be filled on the same bar. If you are using a Multi Time Frame strategy or using Tick Replay, you can submit orders to a single tick data series instead of using High Order Fill Resolution.

    Here is a help guide link about High Order Fill Resolution - rstandingOrderFillResolution

    If historical overfill is the issue, there are a few options to resolve this. You could have your strategy use Set methods instead of Exit methods ( SetStopLoss/SetProfitTarget instead of ExitLongStopMarket/ExitLongLimit ) which utilizes OCO. Or, you could have your strategy submit orders to a single tick data series as explained above.

    SetStopLoss -

    SetProfitTarget -

    Another option would be to use the Unmanaged Approach so you can use OCO freely with your order submissions. This way you can have one order canceled when the other fills on the same bar, without having the historical overfill encountered.

    Unmanaged Approach -

    Handling historical overfill using an unmanaged approach -

    If historical overfill is not the case, please send us a reduced version of your script demonstrating the order fill issues so we may further investigate.

    Please let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service


      Thanks Brandon,

      This may be the case. When this happens, I'm actually cancelling the normal stop and target orders and replacing them with new stop and target orders that are just 1 tick off the respective Bid and Ask. Basically strangling the position for a quick exit with a limit order.

      Considering it's backtest, I'm betting Ninja is looking at the whole bar and concluding that both orders were hit. So for the special case of Backtesting not on TickReplay, I'm best off just setting the stop side. It may be off a tick or two what happens in the live market, but having it built in to test with a handicap is the prudent thing to do.

      This gives me a clue to another issue I'm troubleshooting as well.

      Many Thanks!
      NinjaTrader Ecosystem Vendor - QTradez


      Latest Posts


      Topics Statistics Last Post
      Started by michaelsh, Today, 04:28 PM
      0 responses
      Last Post michaelsh  
      Started by Bmatarese, Today, 03:13 PM
      1 response
      Last Post NinjaTrader_ChrisL  
      Started by sdauteuil, Today, 12:32 PM
      4 responses
      Last Post NinjaTrader_Jesse  
      Started by Gaterz, 09-27-2020, 05:52 PM
      10 responses
      Last Post tcea9
      by tcea9
      Started by derivtrader, Today, 12:04 PM
      1 response
      Last Post NinjaTrader_Spencer