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

Question about this.WaitOnCancelConfirmationSeconds

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

    Question about this.WaitOnCancelConfirmationSeconds

    Hi everyone,

    I've been getting some progress with my automatic trading strategy, but I've noticed that sometimes there will be old working sell stop orders that should have been cancelled by the strategy, and I realize that sometimes a CancelOrder (using unmanaged orders) doesn't always succeed the first time issued.

    I've tried using a do while loop like this

    do
    {
    CancelOrder(ExitOrder)
    } while (ExitOrder.OrderState != OrderState.Cancelled);

    but that just makes my program freeze, even if I use System.Threading.Thread.Sleep(1000); to make it wait between cancel commands.

    So I found there is this:

    this.WaitOnCancelConfirmationSeconds but I can't find anything about it in the help file. Can someone let me know if this is something that can be used with my UnManaged order handling to make sure my cancelled orders are really cancelled?

    Thanks!

    #2
    Hello RunnerX,

    Thank you for your post.

    There is no documentation on WaitOnCancelConfirmationSeconds as it is a unsupported item in NinjaScript.

    However, I can say this is an int that reports the number of seconds the system has waited for the confirmation of the cancel order command to be confirmed.

    You could use it in the following context to check if the number of seconds has exceeded 2 seconds:
    Code:
    if(WaitOnCancelConfirmationSeconds > 2)
    			{
    				Print(WaitOnCancelConfirmationSeconds);
    			}
    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you for that information; I think I can put that to use. I do have another question while you're around though:

      I could use a little more understanding about confirming that unmanaged orders have in fact been cancelled. I find that my automatic strategy does cancel any pending buystop entry orders and sellstop exit orders most of the time, but this past week I've found two instances where old sellstop exits from previous trades earlier in the week are still sitting as Accepted orders in the sim101 account even though the strategy would have called for their cancellation. My coding is simple and it's only calling cancellation in a few controlled instances, so I'm suspecting that the order itself is failing to be cancelled because of a data server outage or something like that.

      I'd try to look this up myself but I can't always search these forums effectively for what I'm looking for, so I was wondering if you could direct me to either an existing thread about these matters, or if you have any information yourself about

      1) under what conditions can CancelOrder() commands fail and leave the order as Accepted, and

      2) is there a conventional way to ensure that unmanaged orders truly are cancelled before moving on? (See how I tried to do it in my Do-While loop but that method broke the program)

      Thank you!
      Last edited by RunnrX; 04-17-2013, 01:21 PM. Reason: formatting of text layout for reading-ease

      Comment


        #4
        Hello RunnrX,

        Thank you for your response.

        1) This should not be occurring on the SIM101 account. Please go to Tools > Options > Strategies > NinjaScript > Order Handling, what options are enabled? Both Cancel Entry and Exit order options?

        2) Using the IOrder object would be the conventional approach to this.

        Please go to Tools > Options > Data > Repair Database and then restart NinjaTrader. Please let me know if these cancellations continue to fail.

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello RunnrX,

          Thank you for your response.

          1) This should not be occurring on the SIM101 account. Please go to Tools > Options > Strategies > NinjaScript > Order Handling, what options are enabled? Both Cancel Entry and Exit order options?

          I have both set to exit, however, the entry and exit orders I'm referring to are being left uncancelled while the strategy is still running, even though there are definite CancelOrder commands being issued from the strategy (I am not resetting it or disabling it). Perhaps this means that I do have a code logic error then - I will look more closely at it.


          Originally posted by NinjaTrader_PatrickH View Post
          2) Using the IOrder object would be the conventional approach to this.

          Please go to Tools > Options > Data > Repair Database and then restart NinjaTrader. Please let me know if these cancellations continue to fail.
          I have been using IOrder objects to manage my orders, and so far have only needed to do checks for if they're null, accepted, filled, etc. I guess I could make up a new type of check with boolean variables saying on the next strategy cycle, "if (CancelAttempted == true && ExitOrder.OrderState != OrderState.Cancelled) {reissue the cancel order}

          Thanks for the idea about repair database. I'll do that when I get home, and then it may take a day or two for the next test results to come back - I'll update this thread if it continues to have an issue - thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,769 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          30 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          943 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          10 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          7 views
          0 likes
          Last Post rocketman7  
          Working...
          X