Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Filled before Execution?

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

    Order Filled before Execution?

    Hi,

    I've spent hours studying the docs and searching the forum and still don't understand the timing and relationship between IOrder.Time, IExecution.Time and IOrder.OrderState.

    I did read in one forum post that:
    Order placement logic essentially happens at the end of each bar
    Order submission logic essentially runs at the beginning of each bar
    But I don't see how this explains what I'm seeing.

    I'm backtesting a single symbol in the Strategy Analyzer using a 5 minute "Last" price strategy with the following code snippet:
    protected override void OnExecution(IExecution execution) {
    Print(execution.Order.Time +
    " -- " + execution.Order.OrderState +
    " -- " + execution.Time);
    }

    This prints the following line to the output window:
    8/2/2011 7:45:00 AM -- Filled -- 8/2/2011 7:50:00 AM

    The order is marked as "Filled" at 7:45, but the Fill does not actually happen until 7:50.

    How can the Order be marked "Filled" an entire bar before the Execution?

    PS
    CalculateOnBarClose=false is the last line of my Initialize method (although my understanding is this doesn't have any effect during backtesting).
    Last edited by pcafstockf; 09-30-2011, 12:29 PM.

    #2
    Hello pcafstockf,

    Welcome to the NinjaTrader forums. Is 7:45 the signal bar - the bar the condition evaluates true? And then the order is filled on the 7:50 bar? This would fall in line with expectations: Condition evaluates true > Order submitted to next bar.

    The source code for backtesting fills is here, and may help you a bit on what is going on internally:
    Documents\NinjaTrader 7\bin\custom\type\@DefaultFillType, @LiberalFillType
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      Thanks for the speedy response.

      I did forget to mention that this is a Market order.

      Yes, I invoke ExitShort("Test") from OnBarUpdate when Time[0] was equal to 7:45.
      The overall chain of events is logical to me.

      * What I'm not understanding, is why the OrderState is set to "Filled" during the 7:45 (signal) bar, even though the Order isn't actually filled until the 7:50 bar?

      When OnExecution is invoked:
      BOTH Time[0] and IOrder.Time are 7:45. However, IExecution.Time seems to be set to a *future* time that has not yet happened (according to Time[0]).

      Comment


        #4
        This is an historical environment, so everything is simulated.
        This time isn't the execution time:
        execution.Order.Time

        This property is the last time the order changes state. The order changes state on the signal bar. For the time on a fill, execution.Time is the property you need. OnExecution is always called after OnOrderUpdate(). There's internal strategy logic that is run after OnOrderUpdate, but before OnExecution, and why you would see different values between Order.Time and execution.Time.
        Last edited by NinjaTrader_RyanM1; 09-30-2011, 03:30 PM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by pcafstockf View Post
          Hi Ryan,

          Thanks for the speedy response.

          I did forget to mention that this is a Market order.

          Yes, I invoke ExitShort("Test") from OnBarUpdate when Time[0] was equal to 7:45.
          The overall chain of events is logical to me.

          * What I'm not understanding, is why the OrderState is set to "Filled" during the 7:45 (signal) bar, even though the Order isn't actually filled until the 7:50 bar?

          When OnExecution is invoked:
          BOTH Time[0] and IOrder.Time are 7:45. However, IExecution.Time seems to be set to a *future* time that has not yet happened (according to Time[0]).
          That sounds about right in a backtest.

          The order reflects its current state, so what you are seeing is:

          At 7:50 when the execution is reported (at the end of the bar), the order that was placed at 7:45 has been filled.

          You may need to try this realtime in Sim. That will give you a more accurate picture, especially as, when live, OnExecution() does happen intrabar, and reflects it.

          Comment


            #6
            Ryan, koganam,

            Thanks guys, I think I get it.

            I believe the following is true only when performing historical backtesting:

            First OnBarUpdate is invoked, and Time[0] is truly 7:45.
            Then OnOrderUpdate is called a few times (to reflect the state transitions), AND even though Time[0] equals 7:45 for each call, the meaning is really "sometime between 7:45 and 7:50".
            Then OnExecution is called for any Fills that would occur "between 7:45 and 7:50"
            Finally OnBarUpdate is invoked with Time[0] truly equal to 7:50 and the call chain repeats.

            Like koganam suggested, I hadn't thought about the call chain in the context of missing intrabar data.

            Please let me know if I misunderstood the "between 7:45 and 7:50" thing.

            Thanks so much for your help and patience.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            574 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X