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

Altered trailing stop in Strategy Builder -- need help

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

    Altered trailing stop in Strategy Builder -- need help

    I'm trying to incorporate a trailing stop into my strategy that always sits at the open of the previous candle, so long as it closes further into profit, if it doesn't I want the trail function to ignore it until the next profit candle.

    so for example:

    Trade enter Long -- stop loss @ low of entry candle
    Next bar closes higher -- stop loss moves from entry candle low to new bar open
    Third bar closes lower (but doesn't hit SL) -- stop loss is unaffected (because candle didn't close in the trade direction)

    My question is, is it possible to program something like this in the strategy builder? if not, how would this be coded manually?

    Thanks for any help you can offer.

    Below is a visual representation of this from the entry to where the trade was stopped out.

    Click image for larger version  Name:	StopLossExample.PNG Views:	0 Size:	6.7 KB ID:	1079107
    Last edited by lunardiplomacy; 11-26-2019, 05:11 PM.

    #2
    I want to do the same, any advance on this?

    Comment


      #3
      Hi henryd333,
      I'm not sure, the very first condition can be coded. Who can know the low of the entry bar at the time of the entry?
      The strat could start with a stop at the low of the previous candle, or naked and the entry candle low stop would then only be set once the entry bar closed.
      The (custom) TrailingStop is possible, even with the StrategyBuilder. A variable (double) TrailingStop would be added, initialized at zero and then increased (Long) as needed on every bar while being in a trade, then reset to zero once the trade closed. The condition set for the trail logic is not awfully difficult. On which condition do you struggle?
      NT-Roland

      Comment


        #4
        I’m struggling with the trailing. I already got to place the stop loss at the low of the previous bar

        Comment


          #5
          Hi henryd333

          Originally posted by henryd333 View Post
          I’m struggling with the trailing. I already got to place the stop loss at the low of the previous bar
          I assume, you added a variable TrailStop, initialized it at zero and when your entry conditions were true, set TrailStop to Low[0], then entered the trade.
          TrailStop = Low[0]? Yes, if you use CalculateOnBarClose, your entry will be placed at the open of the next bar and your trade will initially be protected at the low of the most recent closed bar.
          Now, the update of that initial TrailStop is pending.

          On each bar, you would check if
          1) You market position is (still) long and
          2) Close[0] > Open[0], (trade is moving in the right direction) and one of the conditions below is true
          3a) Open[1] > TrailingStop or
          3b) Open[0] > Trailing Stop.

          3a would set the Trailing Stop to the Open one bar ago if greater than the TrailingStop you had before, thus trail with a little bit more distance.
          3b would set the Trailing Stop to the Open of the most recent closed bar, if greater than the previous TrailingStop.

          The TrailStop update itself would be done as follows:
          3a) TrailStop = Open[1], or
          3b) TrailStop = Open[0].

          Another Set would check, if the price dips below the TrailStop, if true, exit the trade and set the TrailingStop variable back to zero.

          NB: This is the most basic set-up of a TrailStop you can have. You can do a lot more, but I hope this gets you started.

          NT-Roland

          Comment


            #6
            Thank you it surely helps with the logic. I’ll try it and keep you posted.

            Comment


              #7
              Hello lunardiplomacy,

              Below is a link to an example of custom trailing action logic in the Strategy Builder.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              0 responses
              5 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              11 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
              5 views
              0 likes
              Last Post gentlebenthebear  
              Working...
              X