Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Easiest way to maintain limit order open across multiple bars

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

    Easiest way to maintain limit order open across multiple bars

    Hi everyone,

    I know this has been discussed a couple of times but I just can't get it to work. What is the easiest way to place a limit order that will stay open in a strategy that is tick-based, please? I have a simple strategy with a few lagging indicators and parabolic stop loss configured and it works like a charm. The two limit orders, one is names golong and one is named goshort. All orders are unique, max 1 entry per direction and 1 trade in total allowed.

    All I would like is to have a parameter to keep the trade open for, say 2 bars.
    Can anybody point me into the right direction please?

    Code:
    all the initial code...
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    // Set 1
    ...
        EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentAsk(0), @"golong");
    
    // Set 2
    ...
        EnterShortLimit(Convert.ToInt32(DefaultQuantity), GetCurrentAsk(0), @"goshort");
    
    }

    #2
    Hello Oracletrades,

    Thank you for the post.

    Are you manually coding this or using the builder?

    If you are manually coding this you could use the IsLiveUntilCancelled overload set for the entry limit methods. That marks the order to not be cancelled unless you cancel it or it fills.

    If you used the builder you would need to use logic to maintain the order. That generally would involve using some kind of variable so you can keep a condition open for as long as the variable is true.

    Once I know how you are coding this we could go into further details where needed.

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse, thanks for the offer to help. I would do this in code. I only use the strategy builder to provide the basic strategy architecture and then I move to the code.

      Comment


        #4
        Hello

        Thanks for confirming that.

        You could use the overloads which have IsLiveUntilCancelled or you could use logic to hold the orders open. It depends on your goals and how you wanted to design the strategy. If you wanted the order to remain open until filled or you specifically cancel it then you can use IsLiveUntilCancelled:

        EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)


        To otherwise keep an order open you would have to keep calling EnterLongLimit for each bar where the order needs to be live. A variable would generally be used for that use case, a bool variable would be the most simple way. In your entry set you would flip a bool to true rather than calling EnterLongLimit. In another set you could check if the bool is true, if so submit the EnterLongLimit as long as that variable is true.


        I look forward to being of further assistance.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello Oracletrades,

          ...
          If you used the builder you would need to use logic to maintain the order. That generally would involve using some kind of variable so you can keep a condition open for as long as the variable is true.
          ...

          I look forward to being of further assistance.
          Can you provide some more detail about doing this in strategy builder?

          Comment


            #6
            Hello Gimbalto,

            You can find an example of that concept in the following post: https://ninjatrader.com/support/foru...rategy-builder

            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            39 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            19 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            26 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            44 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            37 views
            0 likes
            Last Post CarlTrading  
            Working...
            X