Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How exactly is Market Order fills calculated during a backtest?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How exactly is Market Order fills calculated during a backtest?

    I have a strategy which submits a market order at the close of a bar, but I often see the fill itself being above or below the actual close.

    So my question is, how does NT fill market orders in a backtest? What's the logic behind it?

    Thanks in advance.

    #2
    StockStalker, the Strategy Analyzer will fill market orders at the open of the next bar, not on the close. So for an example, if you have a cross over on bar 1, the code will pick it up on bar 2 and submit the orders, which will be filled at the open of bar 3.
    AustinNinjaTrader Customer Service

    Comment


      #3
      That's true, but I forgot to mention the strategy has multiple timeframes to achieve intrabar granularity (tick by tick chart + bar chart)

      So the strategy sees this bar closing and the next one open, and then submits a market order which gets filled intrabar via the tick by tick chart.

      So the question then is, how do market orders get filled when you have a tick-by-tick underlying chart like this?

      Comment


        #4
        StockStalker, if you want the order to be executed on the secondary series, you must submit it to that series (secondary bar series = bar index 1):
        Code:
        // EnterLong(int barsInProgressIndex, int quantity, string signalName)
        EnterLong(1, 1, "enter long one contract on the secondary series");
        AustinNinjaTrader Customer Service

        Comment


          #5
          Austin, thanks for the response. I understand what you're saying here, and I am aware of that.

          Let me rephrase my question...
          How does NT calculate Market order fills in a backtest on a 1-tick linechart?

          Comment


            #6
            Stock, the order is submitted to be filled on the open of the next bar update. For 1 tick charts, the open = high = low = close, so it would be filled at that tick price.

            OnBarUpdate() processes all bar series in chronological order, and if a timestamp is the same for two series, I believe it processes the lowest index first. This means the order will be filled at the next available OnBarUpdate() for the series you submitted it to.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Austin, this makes sense

              Thanks for the help

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CaptainJack, 05-29-2026, 05:09 AM
              0 responses
              373 views
              0 likes
              Last Post CaptainJack  
              Started by CaptainJack, 05-29-2026, 12:02 AM
              0 responses
              241 views
              0 likes
              Last Post CaptainJack  
              Started by charlesugo_1, 05-26-2026, 05:03 PM
              0 responses
              207 views
              1 like
              Last Post charlesugo_1  
              Started by DannyP96, 05-18-2026, 02:38 PM
              1 response
              293 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 05-11-2026, 05:56 AM
              0 responses
              253 views
              0 likes
              Last Post CarlTrading  
              Working...
              X