Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting all positions with one SL

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

    Exiting all positions with one SL

    Hello

    I got a problem with exiting my positions...

    My actual strategy looks like this: there is a SL of 200 ticks, when the first position is opened. Then, if there are some conditions filled, another position is opened (pyramiding). Now I want to set the SL to 200 ticks below the NEW entry price, so when the loss on the newest position is 200 ticks, ALL positions in the same direction are exited.

    If I only use SetStopLoss(CalculationMode.Ticks, 200), this is only applied on each single position.

    So the aim is, that when one SL is triggered, all positions of the same direction are closed.

    How can I do that?

    Regards

    Sepp

    #2
    Hello,

    Thanks for the forum post.

    Each new order submitted will have its own stop loss submitted with SetStopLoss() set before the entry position.

    If you have SetStopLoss() set to 200 ticks. If I get in at 1000 price stop will be at 800 on the first position. If I get in at 1200 on the next order the stop would be placed at 1000.

    Just so that we are at the same page you want the stop submitted and to stay at 800 level? for the second scale in?

    I look forward to assisting you further.
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi Brett

      no, how I keep the stop on 800, I already found out.

      My aim now is to set the stop for both positions on 1000.

      Now that I'm thinking about... could this be solved by a ExitLongStop() order? (Long just for example)

      Thank you for your help!

      Regards

      Sepp

      Comment


        #4
        Originally posted by MasterSepp View Post
        Hi Brett

        no, how I keep the stop on 800, I already found out.

        My aim now is to set the stop for both positions on 1000.

        Now that I'm thinking about... could this be solved by a ExitLongStop() order? (Long just for example)

        Thank you for your help!

        Regards

        Sepp
        When you set the new stop loss, also calculate its price, then adjust the other Stops with CaclculationMode.Price to that price.

        Comment


          #5
          Dear koganam

          How can I adjust the other stop to the actual price? When a new position is entered (on the open of the bar) the stop should be adjusted to Open[0]-200 ticks. How can I express this in a price?
          And how can I adjust the old SL to the new level? That's my main problem. WHen I just enter SetStopLoss() it's only applicated on the newer entry, but not on the older. Even if I try it with naming the entries through string.SignalName and referring to this in the SL, it doesn't change anything...

          I'm still wondering, if I even need the StopLoss command... For example let's take the example before:
          1. position enters on 1000 -> SL is 800. Now the second position is entered at 1200. Now the "SL" should be on 1000, although this would mean breakeven for the first position...

          Comment


            #6
            Originally posted by MasterSepp View Post
            Dear koganam

            How can I adjust the other stop to the actual price? When a new position is entered (on the open of the bar) the stop should be adjusted to Open[0]-200 ticks. How can I express this in a price?
            And how can I adjust the old SL to the new level? That's my main problem. WHen I just enter SetStopLoss() it's only applicated on the newer entry, but not on the older. Even if I try it with naming the entries through string.SignalName and referring to this in the SL, it doesn't change anything...

            I'm still wondering, if I even need the StopLoss command... For example let's take the example before:
            1. position enters on 1000 -> SL is 800. Now the second position is entered at 1200. Now the "SL" should be on 1000, although this would mean breakeven for the first position...
            To adjust a Stop, you resubmit it, referenced by the same entry signal name, at the adjusted price.

            Let us assume that your first entry was called "BigLong" and you had
            Code:
             
            SetStopLoss("BigLong", CalculationMode.Ticks, 200, false);
            Then after you added the next entry, called "GimmeMore" let's say, you would calculate the new Stop as you have indicated. Without creating another variable, (I would, but I am just making a demo here), you would then adjust the first stop with:
            Code:
             
            SetStopLoss("BigLong", CalculationMode.Price, (Close[0] - 200 * TickSize), false);
            Open[0] makes little sense in this case, unless you have CalculateOnBarClose = false. Which is why I have used Close, not Open.
            Last edited by koganam; 09-02-2011, 02:41 PM. Reason: Changed code

            Comment


              #7
              I've already tried this one... what happens is, that every time it enters a position at the open of a new bar, it immediately exit the same position through the SL on the same level (open).

              The code snippet:

              SetStopLoss("Big Long", CalculationMode.Price, (Open[-1]-200*TickSize), false);

              Open[-1] because I'm currently only backtesting. So the signal for entering a position is triggered and the entry is on the open of the next bar - that's why I'm using Open[-1].

              Regards

              Sepp

              Comment


                #8
                Originally posted by MasterSepp View Post
                ... So the signal for entering a position is triggered and the entry is on the open of the next bar - that's why I'm using Open[-1].

                Regards

                Sepp
                And that is why you are exiting immediately. You need to read up on indexing as done by NT. Open[-1] is technically the Open of the NEXT bar. Trying to index on a future bar should cause some unexpected issues. You CANNOT access the next bar; it is in the future. And as I said, Open[0] does not make sense either unless you have CalculateIOnBarClose = false.
                Last edited by koganam; 09-04-2011, 12:44 PM. Reason: Corrected spelling

                Comment


                  #9
                  Well, I see... but how can I still manage this? I need to get an exit for all entries when Price < Open[-1]-200*TickSize. How can I get this without using SetStopLoss()?

                  Regards

                  Sepp

                  Comment


                    #10
                    Originally posted by MasterSepp View Post
                    Well, I see... but how can I still manage this? I need to get an exit for all entries when Price < Open[-1]-200*TickSize. How can I get this without using SetStopLoss()?

                    Regards

                    Sepp
                    I have already shown you how. Look at the code snippet I put into an earlier post. I do not know what else to say at this point, You cannot access a future bar because it is in the future. You cannot access any price data with a negative index.

                    Comment


                      #11
                      Originally posted by MasterSepp View Post
                      Well, I see... but how can I still manage this? I need to get an exit for all entries when Price < Open[-1]-200*TickSize. How can I get this without using SetStopLoss()?

                      Regards

                      Sepp
                      Even if you are backtesting, a value of -1 does not technically exist when the event is true.

                      You can use negative indexes for draw objects, but for anything else it would not be suggested as it can give you some unwanted results.
                      MatthewNinjaTrader Product Management

                      Comment


                        #12
                        Ok, sounds logical...

                        Is there at least a possibility to generate the signal on the entry of the position? This would mean, that the "Open[-1]" from before would be the Open[0]. Could I use this to generate a valid SL?
                        I'm referring here only to the backtesting, so no live trading. And always CalculateonBarClose = true. So would Open[0] still not work? Is there anything like OnEntryPosition()?

                        Regards

                        Sepp

                        Comment


                          #13
                          Not aware of an OnEntryPosition()

                          Well if you were looking for Open[-1] would you be able to use Close[0]? Would those not be similar in this context?
                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            MasterSepp, going back to your requirement in your opening post/topic line (one I need also), I did some research and coding.

                            I'm new to NT so hopefully one of the support folks here can comment on this approach pro and con wise

                            I've tested it out a bit, and it seems to work.

                            publicclass testallordersamestop : Strategy
                            {
                            #region Variables
                            private IOrder entryOrder = null;
                            #endregion

                            protectedoverridevoid OnBarUpdate()
                            {
                            if (Position.MarketPosition == MarketPosition.Flat) SetStopLoss(CalculationMode.Ticks,8);
                            entryOrder = EnterLong();
                            }

                            protectedoverridevoid OnExecution(IExecution execution)
                            {
                            if (entryOrder != null && entryOrder == execution.Order)
                            {
                            SetStopLoss(CalculationMode.Price,execution.Price -
                            8 * TickSize);
                            }
                            }
                            #region Properties
                            #endregion
                            Example: Testing on ES, with entries per direction = 3, simulated data feed
                            Entered first bar at 1378.50 (1 stop order at 1376.50)
                            Entered next bar at 1405.75 (2 stop order at 1403.75)
                            Entered next bar at 1436.25 (3 stop order at 1434.25)
                            2 bars after last order 3 stop loss orders filled at 1434.25, 8 ticks below the last order fill price.

                            Comment


                              #15
                              dojidubbs,

                              I see no issues with running this. However if you do see any unexpected results, please update this thread and I'm sure we can offer some clarification.
                              MatthewNinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              656 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              371 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              579 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X