Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel limit orders with assessment OnEachTick

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

    Cancel limit orders with assessment OnEachTick


    Dear community and NT team,

    I am building a strategy that uses an indicator that is updated OnEachTick.

    The logic is simple to enter:
    if condition 1 then limit long
    if condition 2 then limit short
    else then cancel limit long and short

    However, i am unable to cancel the orders the limit orders. Once one of the limit orders is created i can't cancel in the same bar if the indicator say to not enter..

    I am trying with CancelOrder but i might be missing something... Can someone help?

    For reference, adding the piece of the code that i am working currently:

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if (Close[0] >= HHH1 - 5
    && ProjectedVolume < SMA(Volume, 10)[0]
    )
    {
    entryOrder = EnterShortLimit(2, HHH1 + EntryFactorS, @"MMDS1");
    //EnterShortLimit(2, HHH1 + EntryFactorS, "MMDS1");
    }

    else if (Close[0] <= LLL1 + 5
    && ProjectedVolume < SMA(Volume, 10)[0]
    )
    {
    entryOrder = EnterLongLimit(2, LLL1 - EntryFactorL, @"MMDL1");
    //EnterLongLimit(2, LLL1 - EntryFactorL, "MMDL1");
    Print("enter order");
    }
    else
    {
    CancelOrder(entryOrder);
    Print("need to cancel working orders");
    }

    }​



    #2
    Hello linkcou,

    Thanks for your post.

    You could assign entryOrder to the Order object in OnOrderUpdate() to ensure the assignment occurs when expected. This is more reliable than assigning Order objects in OnBarUpdate(), as the assignment is not guaranteed to be complete if it is referenced immediately after submitting.

    Here is a reference sample from the help guide demonstrating the use of CancelOrder(): SampleCancelOrder: https://ninjatrader.com/support/help...thod_to_ca.htm

    See this help guide page for more information about CancelOrder() and sample code: https://ninjatrader.com/support/help...ancelorder.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you, Brandon.
      I added the OnOrderUpdate in the code. I will try to run it later when the market opens again to see if it works correctly.
      I will let you know if it doesnt work.
      Thanks for the quick answer!
      Best,

      Comment


        #4
        Hi Brandon,

        I added the piece of code for the OnOrderUpdate (see attached). However, I see that the order is not cancelled when the conditions are false... any idea what i am doing wrong?

        Thanks!
        Attached Files

        Comment


          #5
          Hi Brandon, never mind! i just found the answer.
          Thanks for your help on this one.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          77 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          40 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          63 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          63 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          53 views
          0 likes
          Last Post CarlTrading  
          Working...
          X