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

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 Kraken29, Today, 03:24 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by Skifree, Today, 11:47 AM
            5 responses
            19 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by ETFVoyageur, Today, 10:34 AM
            10 responses
            23 views
            0 likes
            Last Post ETFVoyageur  
            Started by traderzoso, 12-27-2020, 05:19 PM
            6 responses
            229 views
            0 likes
            Last Post lekor
            by lekor
             
            Started by ETFVoyageur, 05-18-2024, 12:45 AM
            4 responses
            29 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X