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 DawnTreader, 05-08-2024, 05:58 PM
            7 responses
            27 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by sgordet, Today, 05:24 AM
            0 responses
            8 views
            0 likes
            Last Post sgordet
            by sgordet
             
            Started by haas88, 03-21-2024, 02:22 AM
            18 responses
            211 views
            0 likes
            Last Post haas88
            by haas88
             
            Started by Board game geek, Today, 02:20 AM
            0 responses
            11 views
            0 likes
            Last Post Board game geek  
            Started by knighty6508, Today, 01:20 AM
            2 responses
            19 views
            0 likes
            Last Post knighty6508  
            Working...
            X