Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order filled even after current bar closes

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

    Order filled even after current bar closes

    Hi tech experts.

    Referring to the attached image. 10 tick range on /ES.
    When Bar01 closes, I will submit a long limit order indicated by the blue horizontal line (5385.75).
    Price drops quickly and I got filled at Bar03 instead. By right, when the current bar (Bar02) closes, my order should be cancelled.

    If price ran up and Bar02 closes on its high, my order do get cancelled. (this behavior is desired).

    Any tips on how to solve this? I want a guaranteed order cancellation as long as Bar02 closes without filling my orders.

    Click image for larger version

Name:	image.png
Views:	80
Size:	40.8 KB
ID:	1313820

    #2
    Hello elirion,

    Was this a realtime or historical trade?

    This depends on how your script was coded, an order is only expired once the bar close is processed where you did not call the order method again. If that order has the ability to fill at that bar close it will instead of being expired. If this was a backtest then it would be shown as an execution on the following bar.

    Comment


      #3
      Hi Jesse,

      This happened real time and I only call the order method one time.

      Could this be a unique behavior of range bars ? Current bar will only be considered closed after price move out of the range (having already created the next bar) ?
      It so happens that my order got filled when the new bar is created, before the 'current' is closed.

      Comment


        #4
        Hello elirion,

        If the order filled before the bar closed that that is what happened, there would not be an expired order because the limit price was met. An order will only expire once a new tick comes in that creates a new bar and the order has not been filled yet.

        Comment


          #5
          Hi Jesse,
          Please look at my illustration again. The order was placed when bar02 was still active and filled at bar03.
          Based on your explanation, my order should have expired when bar03 is created (new tick comes in), but apparently it did not.

          I do not want a fill at bar03, what approach can i take ?

          Can i get hold of unique identifier of bar02, and once the current bar is not this ID anymore, i proceed to cancel my order ?
          Last edited by elirion; 08-12-2024, 12:04 PM.

          Comment


            #6
            Hello elirion,

            My reply was a direct response to your latest comment not your image.

            It so happens that my order got filled when the new bar is created, before the 'current' is closed.

            Before the current bar is closed is the key term here. That fill would be expected because the bar had not closed, the order would not have been marked to be expired.

            If you want to cancel orders yourself you would have to manually code the strategy and also use live until cancelled orders in addition to OnOrderUpdate/OnExecutionUpdate to collect order variables. Then you can use CancelOrder.

            Comment


              #7
              hi Jesse

              probably you can help me confirm this:

              when the next tick comes in, what happens first?

              a) new bar gets created or
              b) current bar closes or
              c) a and b happens at the same time in an atomic transaction that cannot be split

              this will help me with my redesign and debugging.


              Comment


                #8
                Hello elirion,

                The tick that closes the bar is the first tick of the next bar, that tick closes the bar. If that tick also was the right price to fill the limit it would be filled before the order expired. The order is only expired if it does not fill and a new bar is generated. If the order fills on any tick within the current bar it will fill and not be expired. Keep in mind that the expire is only relevant to NinjaTrader, a live order can be filled at any time based on the live market, there is no pending expiry on the exchange. NinjaTrader has to submit a cancel to expire the order which could happen after a fill so no cancel is observed but a fill happens instead.

                Comment


                  #9
                  Got it!!!
                  this helps, thanks so much )

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  50 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  126 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  69 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  42 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X