Announcement

Collapse
No announcement yet.

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 dpomhgbqwduk, Today, 08:55 PM
0 responses
5 views
0 likes
Last Post dpomhgbqwduk  
Started by GARZONJ, Today, 05:47 PM
2 responses
8 views
0 likes
Last Post GARZONJ
by GARZONJ
 
Started by babouin77, Today, 02:57 PM
1 response
17 views
0 likes
Last Post NinjaTrader_PatrickH  
Started by frasg, Today, 03:04 PM
1 response
8 views
0 likes
Last Post NinjaTrader_PaulG  
Started by tonynt, Today, 02:56 PM
1 response
8 views
0 likes
Last Post NinjaTrader_ChrisL  
Working...
X