Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Cancel Initializing Orders

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

    How to Cancel Initializing Orders

    I have run into an issue with live/sim orders that can cause issue with cancelling orders.

    I create a market order via account.CreateOrder() and account.Submit(order). I also create a tp and sl order via account.CreateOrder(), but then I wait for the market order to become filled before calling account.Submit(tpOrder, slOrder).

    Once the tp and sl order are created and before they are submitted they end up in the Initialized state. If for some reason these order do not get placed, when I try to close my position I end up getting an error "Close operation failed". I am attempting to close my position by calling account.Flatten(Instrument) followed by account.CancelAllOrders(Instrument) when this error occurs.

    With a live account a second call to my close method to call account.Flatten(Instrument) followed by account.CancelAllOrders(Instrument) then succeeds, but leaves the cancel pending orders on the UI with no way to delete them...
    With a SIM account I am not able to close out the open market position and the cancel pending order also clutter the UI. I have to reset the account to get back to a good state.

    How can I correctly close/delete an order that is in the Initializing state?​
    Attached Files

    #2
    Hello Blaze212,

    The actions that you are doing together should be separate, flattening the account should only happen once you have called CancelAllOrders and confirmed that the orders were cancelled, if you do those actions at the same time you could have inflight executions.

    Comment


      #3
      Thanks for the quick reply.

      I separated that logic, which was non trivial... And it's still an issue.

      To remove any chance of multiple inflight orders, I tried removing the Flatten call entirely to only call account.CancelOrders(). I also tried just using the "x" in the orders tab to cancel the initialized orders, and both resulted in canceled pending orders...

      I still do not believe there is a way to cancel orders in the initializing state.

      Comment


        #4
        Hello Blaze212,

        If your logic is geting orders stuck to where they do not go past initialized that may be a logical problem with something you are doing. There are cases when using sim accounts that bad logic can cause stuck orders which also cannot be manually cancelled. It sounds like you may need to adjust your logic that is happening before trying to do any cancels if the orders do not move into a normal state like working or accepted.

        Comment


          #5
          I can refactor my logic to not initialize the TP and SL order when I initialize the market order and that should mitigate but not prevent the issue.

          So my logic would now be:
          1. Place market order
          2. Save TP and SL params at time of marker order placement
          3. Wait for market order to enter filled state
          4. Create TP and SL orders
          5. Place TP and SL order


          It would still be possible for a user to manually cancel the orders between step 4 and 5, in which case there are still order suck in initializing.

          Comment


            #6
            Hello Blaze212,

            Targets should only be submitted once the entry order fills, if you are submitting them at the same time as a market entry that will cause problems. If you use the Set methods like SetStopLoss, those should be called before the entry to prep the commands for after the fill, for any other type of target order you need to submit that once you are in a position or based on the entry order fill.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by futurenow, 12-06-2021, 05:49 PM
            18 responses
            878 views
            0 likes
            Last Post dj0ntz
            by dj0ntz
             
            Started by nailz420, 05-14-2025, 09:14 AM
            1 response
            116 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by NinjaTrader_Brett, 05-12-2025, 03:19 PM
            0 responses
            520 views
            1 like
            Last Post NinjaTrader_Brett  
            Started by domjabs, 05-12-2025, 01:55 PM
            2 responses
            83 views
            0 likes
            Last Post domjabs
            by domjabs
             
            Started by Morning Cup Of Trades, 05-12-2025, 11:50 AM
            1 response
            121 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Working...
            X