Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error: Order in state FILLED cannot be canceled affected Order: But 100 [email protected]

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

    Error: Order in state FILLED cannot be canceled affected Order: But 100 [email protected]

    Hi, Support,

    My Strategy is frozen and has to be re-started. Check the logs, found these:
    Error: Order in state FILLED cannot be canceled affected Order: But 100 [email protected]

    Could you please suggest what I can do to avoid this error? Also can I configure such a way that the strategy can ignore these type of errors?

    Thanks a lot in advance.


    #2
    Hello localappleseed, thanks for writing in.

    The strategy sent a cancel order request for an order that was already in a terminal state (filled). Orders can not be canceled if they are in states Filled, PartFilled, or Cancelled. This seems to be an improper use of the CancelOrder() method in the script. We have a full example of using CancelOrder here:

    https://ninjatrader.com/support/help...thod_to_ca.htm

    To ignore errors like this one, you would need to set RealtimeErrorHandling to RealtimeErrorHandling.IgnoreAllErrors and handle order rejections in the OnOrderUpdate override. There is an example here on the documentation page:

    https://ninjatrader.com/support/help...orhandling.htm

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris, Your response is clear and very helpful. This should guide me to the solution. Thanks indeed.

      Comment


        #4
        More questions:
        When further looking into the logs, here are the sequences of the event leading to the error:

        12:34:34 New state = 'Working' Instrument
        12:34:34 submitted an order that generated the following error 'Unable to change order'. Strategy has sent cancel request. attempted to close
        12:34:34 Order cannot be replaced
        12:34:34 New State = 'Accepted' Instrument
        12:34:34 Order in state FILLED cannot be canceled affected Order. But 100 [email protected]

        The order was successfully filled at 12:34:34. It looks to me an change order (or CancelOrder) was submitted while the previous order was being filled. It is a timing issue. In your example, before cancel order was submitted, the code only checks "null" and "CurrentBar > barNumberOfOrder". These checks are normal but doesn't help in my case.

        In my case, before ChangeOrder() was called, I already checked the state was "Working" Instrument. When the ChangeOrder was submitted, the code hasn't received the signal of order being filled.

        Please let me know what you think. Thanks again.




        Comment


          #5
          Hello localappleseed, thanks for your reply.

          It sounds like a case of order overfill. We have an description of what this is and what to do about it here in this post from our colleague Jim:
          I have read the doc and the forum posts on this topic, but still have some questions. I would like to address the following questions assuming a strategy that has a single logical position on with both stops and targets linked via OCO (could be multiple stop/targets). All orders are unmanaged, and total order qty on both sides



          In this case, if the order was a live order and you had an in-flight execution problem, the strategy should either not place a CancelOrder command so quickly after an order submission, or handle the overfill in an unmanaged strategy in OnOrderUpdate.

          Best regards,
          -ChrisL
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            I have a similar problem, where the order is placed, doesn't fill and then after x seconds I cancel the order. However, in the early part of the day it often happens that as I am placing the cancel request, the order fills, causing TD Ameritrade to throw the error that a filled order can not be cancelled. The issue is, in the log I actually can see that I received the error message BEFORE I receive the FILLED callback. This seems like a TD Ameritrade issue, but I still need to handle it. However, I would rather not handle it by just ignoring all the errors... Is there anyway for me to intercept that error message in OnOrderUpdate and then tell Ninjatrader to ignore just that one message?

            Thanks,

            Jon

            Comment


              #7
              Hi Jon, thanks for posting.

              Please send me your Log and Trace files so I can analyze the order submission:

              You can do this by going to the Control Center-> Help-> Email Support

              Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

              Please reference the following ticket number in the body of the email: 2833125 ATTN ChrisL
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,610 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              9 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              19 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              6 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              16 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X