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 NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X