Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder cancel unfilled orders

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

    Strategy Builder cancel unfilled orders

    I'm using the strategy builder and can't seem to figure out a way to cancel an unfilled limit order. My strategy will enter a limit order at a specific price, but if the current price moves to far away from the limit order, I need a way to cancel that unfilled order. Is there a way to accomplish this in the Strategy Builder?

    #2
    Hello srtrader,

    Thanks for your post.

    There are no means to cancel orders in the Strategy Builder.

    Limit orders in the Strategy builder will automatically be canceled at the end of the bar they are submitted on.

    From the Managed Approach help guide page: "By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted"

    See this help guide page for more information about using the Managed Approach Methods: https://ninjatrader.com/support/help...d_approach.htm

    To accomplish this, you would need to unlock your script from the Strategy Builder by clicking the 'Unlock code' button. The CancelOrder() method could be used in an unlocked script to cancel a specified order.

    See this help guide page for more information about CancelOrder(): https://ninjatrader.com/support/help...ancelorder.htm

    And, see this reference sample: https://ninjatrader.com/support/help...thod_to_ca.htm

    Let me know if I may assist further.
    <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
      Thanks for the info! I'll definitely look into this more. Question on the Cancel Order code though. I see this example on the page you mentioned:

      if (CurrentBar > barNumberOfOrder + 5)
      CancelOrder(myEntryOrder);

      I'll be cancelling the order if price moves a certain distance away from my signal bar. I think I can figure that part out. The last line of this code where it refers to (myEntryOrder), is that what I need to put into my code or is "myEntryOrder" referring to what I have named that entry.

      This is what my code looks like for a long entry:
      EnterLongLimit(Convert.ToInt32(DefaultQuantity), LongEntry, @"LongTradeEntry");

      So to cancel this specific Limit order if parameters are met, would I just put CancelOrder(LongTradeEntry) ??

      Comment


        #4
        Hello srtrader,

        If you are using CancelOrder, you need to handle order objects.

        This would involve adding OnOrderUpdate, and assigning the Order object when the order parameter's Name property matches your signal name. Also, the Order object will need to be set to null when filled/canceled if you want to submit the order again. (Since the logic to submit the order makes sure the order object is null before the order is submitted) A null order object would then represent that the order is not active.

        The example Brandon linked includes some code to show order object handling.

        Brandon also mentions that from the Strategy Builder, limit and stop orders that are submitted with Enter/Exit methods will cancel if you do not call the method on the next bar.

        You could consider writing logic in Conditions and Actions that:
        1. Condition that sets a bool to true when you want the order to be active
        2. Condition that sets a bool to false when you want the order to be cancelled
        3. Condition that checks if the bool is true or false, and then submits the order
        Boolean variables can be added in the Inputs and Variables section of Strategy Builder.

        If you need more deliberate control than this, using unlocked code and CancelOrder would be the way forward.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        65 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X