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

Failed to cancel manually added orders

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

    Failed to cancel manually added orders

    I tried to cancel existing orders which I added manually through SuperDOM. CancelOrder() is called from OnStateChange(), it didn't work, do I have to call CancelOrder() from OnOrderUpdate()? What's the correct way to cancel existing orders?
    I am using the following code to cancel, both Prints are working and printed the same results. The order in SuperDOM is still there and it cannot be cancelled.

    if (State == State.SetDefaults)
    {
    // Find our Sim101 account

    lock (Account.All)
    myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");

    foreach (Order order in myAccount.Orders)
    {
    Print (" 111111 order = " + order);
    CancelOrder(order);
    Print (" 222222 order = " + order);
    }
    }

    #2
    Hello localappleseed,

    Thank you for your post.

    The CancelOrder() method should not be called in State.SetDefaults since the strategy will not have processed any orders at this point. Instead, CancelOrder() could be called when the State reaches State.Transition so that orders are canceled when the strategy transitions from processing historical data to real-time data. Please note, CancelOrder() will only cancel orders made by the strategy.

    CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm

    You may reference the SampleCancelOrder example script which demonstrates how to use CancelOrder().

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

    If you would like to cancel orders placed on an account outside of the strategy, you could use the AddOn approach to call <Account>.Cancel() when the script reaches a State of State.DataLoaded.

    Here is a help guide link about using <Account>.Cancel(). - https://ninjatrader.com/support/help...t8/?cancel.htm

    Additionally, to cancel entry and exit orders when a strategy is disabled, you could enable the 'Cancel entry orders when a strategy is disabled' and 'Cancel exit orders when a strategy is disabled' properties. To do so, please follow the instructions below.
    • In the Control Center, select Tools > Options > Strategies tab.
    • Under 'NinjaScript', select the boxes titled 'Cancel entry orders when a strategy is disabled' and 'Cancel exit orders when a strategy is disabled'.
    • Click OK.
    Please see this help guide link for more information — https://ninjatrader.com/support/help...riptProperties

    Let us know if we may further assist.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Yes, per your instruction, I changed to use myAccount.CancelAllOrders(order.Instrument), it worked.
      Super!. Thank you so much for your quick help.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      16 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      5 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X