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

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

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    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.

    Leave a comment:


  • localappleseed
    started a topic Failed to cancel manually added orders

    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);
    }
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by Stanfillirenfro, Today, 07:23 AM
1 response
4 views
0 likes
Last Post NinjaTrader_Gaby  
Started by cmtjoancolmenero, Yesterday, 03:58 PM
2 responses
22 views
0 likes
Last Post cmtjoancolmenero  
Started by olisav57, Yesterday, 07:39 PM
1 response
9 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by cocoescala, 10-12-2018, 11:02 PM
7 responses
944 views
0 likes
Last Post Jquiroz1975  
Started by oviejo, Today, 12:28 AM
1 response
12 views
0 likes
Last Post NinjaTrader_Gaby  
Working...
X