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.
    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.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DayTradingDEMON, Today, 09:28 AM
        4 responses
        21 views
        0 likes
        Last Post DayTradingDEMON  
        Started by geddyisodin, Yesterday, 05:20 AM
        9 responses
        50 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by George21, Today, 10:07 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by Stanfillirenfro, Today, 07:23 AM
        9 responses
        24 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by navyguy06, Today, 09:28 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X