Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel limit orders after x number of bars

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

    Cancel limit orders after x number of bars

    Hi,
    Below is part of my code from a strategy I created. I am calling an ATM strategy from within the code. I would like to be able to cancel the limit order if it's not filled in x number of bars or if price moves x number of ticks from the order. I haven't been able to figure out how to accomplish this. Any help would be appreciated.

    // Condition set 1
    if (orderId.Length == 0 && atmStrategyId.Length == 0 && ToTime(Time[0]) >= ToTime(StartHour, StartMinute, 0)
    && ToTime(Time[0]) < ToTime(EndHour, EndMinute, 0)
    && < My Condition>
    )
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit, Close[0], 0, TimeInForce.Day, orderId, "TwoBarHighLowATM", atmStrategyId);

    }



    Thanks

    #2
    Hello mlarocco,
    You can store the bar number on which the order was submitted and further check it. A sample code will be like:

    //in Variable
    Code:
    int currentBar = 0;
    //in OnBarUpdate
    Code:
    // Condition set 1
    if (orderId.Length == 0 && atmStrategyId.Length == 0 && ToTime(Time[0]) >= ToTime(StartHour, StartMinute, 0)
    && ToTime(Time[0]) < ToTime(EndHour, EndMinute, 0)
    && < My Condition>
    )
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Limit, Close[0], 0, TimeInForce.Day, orderId, "TwoBarHighLowATM", atmStrategyId);
    
    [B]currentBar = CurrentBar;[/B]
    }
    
    
    //cancel the order if not filled within the next 5 bars
    [B]if (orderId.Length > 0 && CurrentBar - currentBar > 5)[/B]
    {
        //do something
    }
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply, I will give it a try today.

      Comment


        #4
        One more question.... where you have //do something, what is the syntax to cancel the ATM orders?

        Thanks

        Comment


          #5
          Hello mlarocco,
          You can use the AtmStrategyCancelEntryOrder method to cancel the entry order. Please refer to our help guide to know more about it.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Thank you....

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X