Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Trailing Stop after X pips profit

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

    Trailing Stop after X pips profit

    Hi there, I would like to program the following SL condition using the Strategy Builder (not coding, as I want to retain ability to modify my strategy in the GUI).

    Upon open trade

    SET stop 20 pips

    If current bar close > 5 pips above entry (for LONG, or 5 pips below entry for SHORT)

    SET trailing stop 10 pips

    How could I accomplish this? Appreciate if anybody could help. Essentially, I want conditional trailing stop conditions like with the manual trader but without coding them.. can that be done with some boolean logic?

    #2
    Hi Oracletrades,
    I don't think it is possible to send a stop order (20 pips) AND a (conditional) trailing stop order (10 pips only if market moved > 5 pips) to the market using the Strategy Builder.
    However, if you accept
    i) to manage your stop(s) internally,
    ii) to send the Exit order to the market only after the respective Stop condition is met (e.g. Close[0] < TrailingStop),
    iii) the (resulting) delay between Exit condition being met and the Exit execution at the next candle (or tick),
    it can be accomplished using the StrategyBuilder ONLY.

    User Inputs (int): 1) SL_Pips, 2) ActivateTrail_Pips, 3) TrailSL_Pips.
    User variables (double): 1) Initial_SL, 2) TrailActivateLevel, 3) TrailStop.

    If you are Long and BarsSinceEntryExecution = 1,
    i) set Initial_SL to the Execution Price (e.g. Open [1]) - SL_Pips.
    ii) set TrailActivateLevel to Execution Price (e.g. Open[1]) + ActivateTrail_Pips,
    Then, check if the TrailingStop price needs to be updated while you are long.
    If Price (e.g. Close[0] > TrailActivateLevel AND(!) Price (e.g. (Close[0]) - TrailSL_Pips > TrailStop,
    i) set/update TrailStop to Price (e.g. Close(0]) - TrailSL_Pips.
    Then, just check, if the Price (e.g. Close[0] is smaller than either i) Initial_SL or ii) TrailStop. If Yes, send an exit order to the market AND(!) reset Initial_SL, TrailActivateLevel and TrailStop. Attached, see an illustrative example (print to Output Window) using SL of 200, ActivateTrail of 50 and TrailSL of 100.
    NT-Roland
    Attached Files

    Comment


      #3
      Hello Oracletrades, thanks for your post.

      It's not possible to have a conditional stop loss from the builder using the stop and target section. You would need to unlock the strategy and do set an initial stop loss of 20 pips, then check the condition withing OnBarUpdate and call SetStopLoss once again to set it at the new level. Or you can do this manually with exit orders as NT-Roland describes (I did not test this though, so it would need to be developed and tested).

      Best regards.
      Chris L.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Waxavi, Today, 02:10 AM
      0 responses
      3 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      9 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by elirion, Today, 01:36 AM
      0 responses
      4 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by gentlebenthebear, Today, 01:30 AM
      0 responses
      4 views
      0 likes
      Last Post gentlebenthebear  
      Working...
      X