Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopLoss above open point of position

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

    StopLoss above open point of position

    Hi all,

    I would like to programm following strategy (description is for long position): When the position is on specific profit I want to move the SL above opening price of current position, but below this current profit. Let's say the current profit is 100 ticks and I would like to move the SL on level of 50 tick to assure that at least profit of 50 ticks will be achieved.

    I think it is similar to trailingstop, but I want to move SL above opening price only when specific profit is reached. SetStopLosl can not put exit order above the opening price of current position.

    Do you know how to do it? Is it feasible at all in Ninja Script?

    Thank you for your help.

    Best regards,

    Jozef

    #2
    You can do this in NinjaScript for sure. You have to write the code yourself, .. it can't be done using the wizard interface.

    Basiclly you just re-issue the setstoploss method with your new price. (make sure to use the Price format)

    Search the reference samples as well.

    Comment


      #3
      Thank you for your reply. That's what I am doing. I have following condition in my code:
      if(Position.MarketPosition==MarketPosition.Long){
      if(Position.GetProfitLoss(Close [0],PerformanceUnit.Currency) > 100) {
      SetStopLoss("Long",CalculationMode.Price,20,true);
      }
      }

      But this sets SL 20$ below the open position price and not below current close price (which I want to have).

      Thank you

      Comment


        #4
        When you do
        Code:
        [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Long"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],CalculationMode.Price,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
        It will set your stop loss at $20. What you want to put in instead of 20 is something like
        Code:
        Position.AvgPrice + 20 * TickSize
        or something similar that achieves what you want.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hello Josh,

          I tried your sugestion as following:
          if(Position.MarketPosition == MarketPosition.Long && Position.GetProfitLoss(Close[0],PerformanceUnit.Currency) > Revenue){
          double r = Position.AvgPrice + sLMove * TickSize;
          SetStopLoss(CalculationMode.Ticks,r);
          }

          In case of long position, the method SetStopLoss puts the SL as: open position price minus requested stoploss.I think, it cannot put the SL above open price of the current position.
          Or should I use the SetStopLoss different way?

          Thank you,

          Jozef

          Comment


            #6
            Don't use tick calculation mode. Just stick with the Price calculation mode.
            Code:
            [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]"Long"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],CalculationMode.Price,[/SIZE][/FONT][FONT=Courier New][SIZE=2]Position.AvgPrice + sLMove * TickSize[/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
            You should be able to place the stop above your entry price after the position has gained some ticks in profit. Like a trailing stop, nothing is preventing it from moving the stop above the entry price.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              FYI, I do this alot. All I do is use a negative value for the stop. It works beautifully.

              SetStopLoss(signal, 5); // means 5 ticks below the entry.

              SetStopLoss(signal, -5); // means 5 ticks above the entry.

              - Wayne

              Comment


                #8
                Josh, thank you for your help. It works exactly as you wrote.

                Thank you.

                Jozef

                Comment


                  #9
                  You're welcome. If you have any other questions feel free to post them.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

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