Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder() cannot cancel orders when Strategy starts

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

    CancelOrder() cannot cancel orders when Strategy starts

    I am trying to test if the pre-existing pending buy orders can be canceled when Strategy starts.
    Here is what I did:
    (1) Manually submit a limited buy order through SuperDOM. This order is pending...
    (2) Start Strategy() which includes the following code:
    In OnStateChange():
    Existing order can be found using
    foreach (Order order in myAccount.Orders)
    ...
    {
    Print ("order =" + order); // it is confirmed this order is the correct pre-existing order
    CancelOrder(order);
    Print ("order =" + order); // nothing is printed here, so it looks like the order is canceled.
    }

    Later I can see this pre-existing order has not be cancelled. I also tried myCancelOrder = GetRealtimeOrder(order); it didn't work either. Adding the codes to OnBarUpdate() won't help.

    Could you tell what I may have done incorrectly? What's the correct way to cancel this order?
    Thanks in advance.
    Last edited by localappleseed; 09-20-2020, 05:45 PM.

    #2
    Hello localappleseed,

    CancelOrder() is a strategy method that can only cancel orders from the strategy.

    Continue using the addon approach and use the Cancel() method from the account.
    https://ninjatrader.com/support/help...nt8/cancel.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, Chelsea,

      Thanks for quick reply.
      I re-tested a limit order submitted from Strategy, then stopped and re-started Strategy. CancelOrder() still cannot work. Thanks.
      Last edited by localappleseed; 09-20-2020, 09:49 PM.

      Comment


        #4
        Hello localappleseed,

        The order would need to be submitted by the strategy while the strategy is running and the order is part of the strategy performance.

        For the order to be resumed, the Immediately submit start behavior would need to be used and the order be matched, or the order will automatically be cancelled when the strategy instance is re-enabled.
        https://ninjatrader.com/support/foru...182#post783182
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ervin, Today, 09:23 AM
        0 responses
        4 views
        0 likes
        Last Post ervin
        by ervin
         
        Started by HansLenders, Today, 09:15 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by sdauteuil, Today, 08:23 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by tonynt, Today, 08:27 AM
        3 responses
        20 views
        0 likes
        Last Post NinjaTrader_Heath  
        Started by mht2020, Today, 07:08 AM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X