Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to move a StopLoss to BreakEven?

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

    How to move a StopLoss to BreakEven?

    Hi,

    When I go Long/Short in a strategy, I open 2 positions, both of them with the same StopLoss, but position 1 have ProfitTarget1 and position 2 have ProfitTarget2.
    What I need to do is, When ProfitTarget1 is achieved change the stoploss of the position 2 to BreakEven.
    Can you help me please?

    #2
    Hello ervin,

    Thanks for your post and welcome to the NinjaTrader forum!

    Can you clarify if you are using the strategy builder or coding directly in Ninjascript?

    Can you clarify what means/methods you are using for your stoploss? (IE: SetStopLoss())

    Comment


      #3
      Hi,
      I'm coding direcly in ninjascript.
      For my stop loss I'm using SetStopLoss, but if it is necesary I can change if you say me how.

      Comment


        #4
        Use a boolean variable called shiftstop and an int or double variable called breakeven, depending on if your stop is tick or price based.

        default shiftstop = false

        if shiftstop is false, stop loss is per your strategy

        if (conditions) are true, set shiftstop = true, and set stop loss to breakeven

        if position flattens, set shiftstop = false

        you will have to use the entry string names to designate which stop loss to move, in your case.

        Comment


          #5
          This logic I must to implement in OnBarUpdate rigth?
          Is there some event like "OnTargetReachedExecuted" (just for examole) or something like that where I can put the code to set stoploss to breakeven? If exist I just put the code there.

          Comment


            #6
            Also I have to save the price to put the breakeven into a vatiable rigth? Where is the price of the open position?

            Comment


              #7
              This logic I must to implement in OnBarUpdate rigth?
              Is there some event like "OnTargetReachedExecuted" (just for examole) or something like that where I can put the code to set stoploss to breakeven? If exist I just put the code there.
              The simplest way is probably put it in OnBarUpdate and use the same exit conditions for Position 1, in your case.

              Originally posted by ervin View Post
              Also I have to save the price to put the breakeven into a vatiable rigth? Where is the price of the open position?
              Position.AveragePrice

              Comment


                #8
                Hello ervin,

                Thanks for your reply.

                In the OnBarUpdate(), once your first order is closed, you can simply change the SetStopLoss() to the breakeven price. Please note that it is critical that you reset the SetStopLoss() to your original values before the next entry is made as the method will retain the last price used.

                You can use some script logic to set a bool when your Position.Quantity equals two. Then when the bool is true and Position.Quantity now is equal one to then set the stop at the breakeven value. You would also need to reset the bool when flat.

                Reference: https://ninjatrader.com/support/help...n_quantity.htm

                Comment


                  #9
                  Thank you, I'll try this later.
                  Sorry but let me insist, there are or there are not an event like "target achieved" or "on position close" or something like that?

                  Comment


                    #10
                    Originally posted by ervin View Post
                    Thank you, I'll try this later.
                    Sorry but let me insist, there are or there are not an event like "target achieved" or "on position close" or something like that?
                    No there are not.

                    Comment


                      #11
                      Hello ervin,

                      Thanks for your reply.

                      As member liquid150 advised there are no such methods. There are more advanced means of observing and controlling orders. I will link a couple of examples below:




                      Here is a link to all of the strategy example scripts: https://ninjatrader.com/support/help...?strategy2.htm

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Yesterday, 05:17 AM
                      0 responses
                      54 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      130 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      71 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      44 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      49 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X