Announcement

Collapse
No announcement yet.

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 asgegre, Today, 05:10 AM
      0 responses
      1 view
      0 likes
      Last Post asgegre
      by asgegre
       
      Started by asgegre, Today, 03:07 AM
      0 responses
      4 views
      0 likes
      Last Post asgegre
      by asgegre
       
      Started by MarkTee, Today, 02:53 AM
      0 responses
      5 views
      0 likes
      Last Post MarkTee
      by MarkTee
       
      Started by ldjaisohy, Today, 12:59 AM
      0 responses
      5 views
      0 likes
      Last Post ldjaisohy  
      Started by TheCatTrader, Yesterday, 04:52 PM
      1 response
      9 views
      0 likes
      Last Post s.kinra
      by s.kinra
       
      Working...
      X