Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Transition from SetStopLoss to SetTrailStop after certain conditions are met??

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

    Transition from SetStopLoss to SetTrailStop after certain conditions are met??

    Hi,

    I would appreciate advice on how to accomplish the following in a strategy for backtesting....

    1) EnterLongLimit @ entryPrice
    2) SetStopLoss @ stopLossPrice
    3) define a trailStopPrice
    4) if (High[0] > entryPrice+(trailStopPrice-stopLossPrice)
    5) then change the stopLoss to a trailStop order
    6) else exit the position at the stopLossPrice

    The above basically describes a position with a fixed stop loss which becomes a trailing stop loss at a price trigger. I'm trying to figure out if I can simply change the order type or if I need to manually program a trailing stop within the strategy and use ExitLong(). I'd categorize my programming experience as advanced beginner, so a verbose reply is appreciated.

    Thanks

    #2
    AresBowman, you would need to custom program your trailstop then after a being a certain level in profit using the SetStopLoss method, as you could not use the SetStopLoss and SetTrailStop concurrently on the same position. Please find below a sample that would help to get you going:

    Comment


      #3
      Thanks Bertrand.

      Are there any benefits to programming a trailing SetStopLoss() versus using a conditional price statement to trigger an ExitLong()? It would seem the only fundamental difference between the two is that SetStopLoss() can be simulated?

      Comment


        #4
        In that sense the ExitLong() is simulated / hidden as well, as you only submit it once triggered. The biggest different is the order type used, the SetStopLoss creates a StopMarket order executing intrabar, where the ExitLong() would be submitted at the open of the next bar once the condition triggered.

        Comment


          #5
          It appears from the example you attached that the sequence of SetStopLoss and SetProfitTarget don't matter? For Example....

          if (Position.MarketPosition == MarketPosition.Flat)
          SetStopLoss();
          SetProfitTarget();
          if (trade condition met)
          EnterLong();

          I'm confused on how a stop loss or profit target can be set when there is no open position. And does the above still work if we have...

          if (Position.MarketPosition == MarketPosition.Flat)
          SetStopLoss("signal name");
          SetProfitTarget("signal name");
          if (trade condition met)
          EnterLong("signal name");

          Comment


            #6
            Correct, the sequence would not matter - if there's no position the Stop Loss or Target set would be ignored, that part is just needed to reset to an initial default value.

            Comment


              #7
              If I code the following

              SetStopLoss("signalName", CalculationMode.Ticks, 10, false);

              What is referenced for the tick offset (Position.AvgPrice)?

              If I have two unique entries, e.g. EnterLong("entry1") and EnterLong("entry2"), will the value held in Position.AvgPrice be the average of the two entry prices as the name suggests? If so how can I return the entry price for unique positions?

              Thanks

              Comment


                #8
                Hello AresBowman,

                Yes, it will use an average of your positions submitted with "signalName" to determine the stop loss level.

                If you want to return the entry price for individual orders, you have to work with IOrder objects at the IExecution level. This sample can help get you structure this:
                Using OnOrderUpdate() and OnExecution() methods to submit protective orders
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                633 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                567 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X