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

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 margandi, 12-18-2019, 12:45 PM
        3 responses
        414 views
        0 likes
        Last Post IsaacBillion  
        Started by flightbooking, Today, 08:22 AM
        0 responses
        1 view
        0 likes
        Last Post flightbooking  
        Started by flightbooking, Today, 08:20 AM
        0 responses
        2 views
        0 likes
        Last Post flightbooking  
        Started by roblogic, 11-25-2022, 07:04 AM
        4 responses
        29 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by dibDab, Today, 03:58 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Emily  
        Working...
        X