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 soyjesus, Today, 06:07 AM
        0 responses
        5 views
        0 likes
        Last Post soyjesus  
        Started by Atomic, 09-26-2022, 09:01 AM
        4 responses
        63 views
        0 likes
        Last Post Atomic
        by Atomic
         
        Started by Atomic, Today, 05:13 AM
        0 responses
        13 views
        0 likes
        Last Post Atomic
        by Atomic
         
        Started by llanqui, 09-25-2022, 07:14 AM
        8 responses
        55 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by laocoon, Yesterday, 08:31 AM
        2 responses
        54 views
        0 likes
        Last Post laocoon
        by laocoon
         
        Working...
        X