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 andrewtrades, Today, 04:57 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        8 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X