Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

order cancellation in lower time frame

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

    order cancellation in lower time frame

    Hi!
    I have the following strategy (unmanaged approach) on a 5 min chart:

    A Stop Buy order 1 pip over the High of a range. The stop buy order should be cancelled as soon as the range is broken to the downside.

    The problem: If one bar breaks the range downward and upward the stop buy order gets filled but should be cancelled.

    I tried to cancel the pending order in a lower time frame (1 min) but thats not possible because the order is already filled, although the buy point was not hit yet!

    So how to cancel the pending entry order?

    Thanks, DH

    #2
    DH, you would need to debug the event / bar event update sequence seen by your strategy, if you try to do this from the 5 bars close in backtesting there would not be enough granularity available to do the order cancelleation as you desire as it all happens in one 5 min bar correct?

    Comment


      #3
      Yes, it all happens in one 5 min bar. That's why I tried to cancel the order in a lower time frame. But as soon as I get the first 1 min bar the order is already filled, but should not be filled at this point.

      Comment


        #4
        From the perspective of the closed 5 min bars in backtesting it likely would be filled then, you would need to debug with Prints / TraceOrders to understand the event sequence your code runs through to arrive at this result.

        Comment


          #5
          Well, either I do something very wrong or there is a bug in back testing.

          On the attached picture you see a 5 min chart (the primary series) with the trade which should not execute on the upper side and a 1 min chart on the lower side.

          All trades are handled in the 1 min time frame.

          At 22:30, at the end of the range, a stop buy was entered.
          At 22:33, the range was broken to the downside and the pending entry order should get cancelled. But at this time, the entry order was already filled! Also the corresponding SL and TP orders have already been entered (at OnOrderUpdate)!

          It looks like that it is not possible to handle trades in a lower time frame than the primary data series.

          Please advise.
          Thanks, DH
          Attached Files

          Comment


            #6
            DH008, so you're sending those orders directly to the BIP = 1 or do you only submit them on the BIP 1 event? Would it be possible to send me the strategy to reproduce here on our end? You can mask any proprietary logic used if sensitive for you.

            Thanks,

            Comment


              #7
              Bertrand,
              you pointed me in the right direction!

              Thats a bit embarrassing now, but I have to admit, a coding error of mine caused the problem:

              The variable I used for "SubmitOrder(barsInProgressIndex,..)" was not maintened well, it always was zero, so I submitted all orders to the primary series....

              Thanks for your time and sorry to bother you with such a stupid mistake.
              DH

              Comment


                #8
                No worries DH008, happy to hear you were able to trace it down - have a good weekend.

                Comment


                  #9
                  On more problem came up:

                  Same setup as befor:
                  - primary data series 5 min
                  - entry trades in 1 min
                  - SL, TP and order state set in OnExecution

                  I have a filled short order which hits the take profit (TP) at the 7:51 bar (the first OnExecution in the output window). At this moment (OnExecution) the order state is set to flat.

                  After this event (!), in OnBarUpdate, the order state is already flat at the 7:50 1 min bar (line 5 in the output window)!

                  For that reason an 2. order is entered but should not because in reality the system is still short with the first position.

                  So what am I doing wrong here?
                  Attached Files

                  Comment


                    #10
                    You see the position update on the next OnBarUpdate() call after the execution, here the 1min series in your strategy, so expected outcome. Nothing you do really incorrect here but you would need to add a check to ensure in those cases an additional 5 min / primary bars is seen before the new potential trade is entered.

                    Comment


                      #11
                      I don't get it.
                      Why is the TP execution at 7:51 processed before the 1-min OnBarUpdate at 7:50?

                      Comment


                        #12
                        You print Time[0] from the OnExecution() correct? That would not be relevant as it would not be the time of the execution then but the time of the last processed bar, can you please try printing the IExecution.Time instead for comparison?

                        Comment


                          #13
                          I print Time[0] and Execution.Time in the same line of the output.
                          Time[0]: 7:50
                          Execution.Time: 7:51

                          Comment


                            #14
                            Thanks, that seems correct - there's no bars object tied to the OnExecution(), you just print the last OnBarUpdate() processed bar at this point, which is the 7:50 bar, not the 7:51 one where the execution actually happens.

                            Comment


                              #15
                              I know but I think you dont get my point, maybe I did not explain well:
                              In the output window: If the execution happens at 7:51, how is it possible that 2 lines later the OnBarUpdate at 7:50 (!) already knows what happend at 7:51?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              669 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              378 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              581 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X