No announcement yet.

Partner 728x90


using trailing stops in Strategy builder

  • Filter
  • Time
  • Show
Clear All
new posts

    using trailing stops in Strategy builder


    I have been looking at this excellent video on the strategy builder

    unfortunately it stops just short of explaining how you would set up a trailing stop.

    I see at the end of the strategy menu there is a setting for trailing stop, but is there a tutorial how to set it up ?

    Many thanks

    Hello fredfred123,

    Thanks for opening the thread.

    I have created a demonstration video demonstrating how you can set up a Trail Stop and how it works when it is enabled.


    You may wish to further reference the SetTrailStop() method documentation page for a complete understanding of how the method that the Strategy Builder uses works. Additionally, Calculation modes can be referenced in our help guide as well.

    SetTrailStop() -

    Calculation Modes reference -

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service


      Thanks Jim, that was perfect!


        Would it be possible to demonstrate, using Strategy Builder in NT8, how to create a trailing stop where, for a long trade, price CLOSES below the Keltner midpoint line using a period of 7?

        Thank you.


          Hello Lightheart,

          Welcome to the forums!

          I don't have a demonstration for this specific task, but I may provide some further direction.

          SetTrailStop() can only be placed in the Stops and Targets section of the Strategy Builder and will be triggered after a position is entered. You could create your own trail stop behavior by creating a condition that checks if the Close price is greater/less than your Keltner Channel level and to set a bool to control your stop order.

          When that bool is true, you can submit a stop order to be offset from current Close price. Whenever OnBarUpdate() iterates and the bool is true, the stop will move.

          Keep in mind, using Calculate.OnBarClose will have Close[0] representing the bar that has just closed and Close[1] will represent the previous bar that has closed. Using Calculate.OnEachTick or Calculate.OnPriceChange will change this indexing so Close[0] will be the developing bar/tick, while Close[1] will represent the bar that has just closed.

          I have also attached a picture showing how a condition can be built that checks if Close[0] is greater than a Keltner Channel's midline.

          Please let me know if we can be of further assistance.
          Attached Files
          JimNinjaTrader Customer Service


            Jim (or anyone else),

            I am trying NinjaTrader 8 demo purely for bar by bar trade management.. I currently use ThinkOrSwim and it doesn't have these tools..I have tried creating a Simple strategy and no success yet..

            I enter trades manually and ideally the strategy recognizes a newly opened trade and starts managing the trade 15 minutes later by moving a trail stop 4 ticks above (for shorts) or below (for longs) the prior 15 minute bar... Still reading the manual..!



              Hello Rashid,

              A strategy will only be able to manage positions that are opened by that strategy unless the strategy uses "Adopt Account Position." If using Adopt Account Position, you could enter your position manually and then enable the strategy on that instrument/data series so the strategy begins managing that position.

              If you are using SetProfitTarget/SetStopLoss for the target and stop, these methods may not submit protective orders for an adopted position. I would recommend placing your own logic in Conditions and Actions that submits a profit target and stop loss with the Exit methods under Actions when the strategy position is not flat. I would advise to then have a bool that tells the strategy to submit orders for initial stop loss and when you need to switch to submitting your stop loss to a desired auto trail level.

              AdoptAccountPosition can be set when an unlocked strategy sets IsAdoptAccountPositionAware = true in State.SetDefaults.

              Adopt Account Position and other Start Behaviors can be referenced here -

              IsAdoptAccountPositionAware is documented here -

              If you do not wish to use AdoptAccountPosition, the strategy will have to open this position using it's own logic and then the strategy will be able to manage those positions.

              Please let us know if we can be of further assistance.
              JimNinjaTrader Customer Service


                Thanks Jim..


                  I have decided I want the strategy to handle the entry.. The first step to building this is I want to restrict the price range where the script should run.. I cannot get the script to simply draw lines if price is in a price range.. the sample strategies work fine.. attached are what I have done.. The last is where I input the price range.. Thanks for your help..

                  Attached Files


                    Hello Rashid Garuba,

                    Thanks for your question.

                    Your condition written checks if ZoneTop is less-than-or-equal-to the current Close price, AND ZoneBottom is greater-than-or-equal-to the current Close price. Are these values allowing this condition to become true? I have included a demonstration on setting up debugging prints in the Strategy Builder showing how you can monitor your logic as it is executing.

                    Debugging with the Strategy Builder -

                    Also to keep in mind when using drawing tools, if you reuse the same Drawing Tool tag, you will update the last Drawing Object that used that tag. To create unique drawing objects, you can add CurrentBar to the tag string.

                    For example:

                    Draw.Dot(this, "tag1"+CurrentBar.ToString(), true, 0, Low[0] - TickSize, Brushes.Red);

                    Let us know if you have any questions on interpreting the debug output.
                    JimNinjaTrader Customer Service


                      Hello everyone
                      I am new to this forum. I have a question.
                      this SetTrailStop() is to exit a position. I wonder if there is a SetTrailStop() to enter a position?.
                      Vinh Phan


                        Welcome to the forums VinhPhan!

                        Set methods are used to submit a preconfigured target/stop when an Enter method comes back as filled. They are used to protect your position only and would not be used to enter a position.

                        You could consider the following however:
                        1. In Conditions and Actions, check if the strategy is flat and place your Enter method for a stop or limit order at a price level that is controlled by a variable
                        2. Create another condition in Conditions and Actions that defines when you want to update the entry price for your order. When this condition becomes true, update your variable to the new price level you want it to reside.
                        Variables can be created in the Inputs and Variables page. To update a variable's value in an action block, you can create an action and select Misc > Set MyVariable. A double variable can be created which can hold the decimal values of a price level.

                        If you are new to using the Strategy builder, I suggest referencing our Strategy Builder 301 and Conditions and Actions tips page so you can see how the tool can be used and how various checks, like checking the strategy's position can be made.

                        Strategy Builder 301 (publicly available resource) —

                        Conditions examples —

                        Actions examples —

                        We look forward to assisting.
                        JimNinjaTrader Customer Service


                          HI - I would like to create a trailing stop strategy for trading US equities only. I enter my trades in SuperDOM manually and would like to include a custom stop strategy upon entering a trade. I'd like to enter a trail stop (@ the market) when price drops below the previous low of the 15 minute candlestick. Can you walk me through how to create this in the strategy builder module? thanks in advance.


                            Welcome to the forums Petro2458!

                            SetTrailStop can be used to create trailing stop loss with minimal effort.

                            If you would like to control the trailing stop yourself instead of using the default SetTrailStop, you can use logic in Conditions and Actions to control the stop loss so it trails as you would like. Please see the examples in the thread below which demonstrate creating auto breakevens and auto trails using Conditions and Actions in the Strategy Builder.


                            The example for trailing stop tracks the stop price the stop loss is moved to with the CurrentStopPrice variable and we keep track of a trigger when to move the stop loss with the CurrentTriggerPrice variable. When we are long and the CurrentTriggerPrice is exceeded, we update CurrentTriggerPrice and CurrentStopPrice to update the stop loss and set a new trigger to update the stop loss again.

                            I would suggest working with examples to get familiar with how you can make auto trails and auto breakevens, and then I may suggest adding a condition to switch your strategy into an "auto trail mode" when Close[0] is less tan Low[1].

                            You may also wish to have a look at the Breakeven strategy as well to see how it moves the stop loss depending on the strategy's "TriggerState" variable. You could create your own "TriggerState" logic to flip from breakeven behaviors into Auto Trail behaviors if you wish.

                            We look forward to assisting.
                            JimNinjaTrader Customer Service


                            Latest Posts


                            Topics Statistics Last Post
                            Started by bosajin, Yesterday, 09:15 AM
                            5 responses
                            Last Post NinjaTrader_Jim  
                            Started by Dolfan, Today, 12:24 PM
                            4 responses
                            Last Post NinjaTrader_Jim  
                            Started by WeyldFalcon, Today, 11:09 AM
                            4 responses
                            Last Post WeyldFalcon  
                            Started by DTSSTS, 08-10-2020, 09:48 AM
                            10 responses
                            Last Post DTSSTS
                            by DTSSTS
                            Started by NickyD, Today, 10:05 AM
                            2 responses
                            Last Post NickyD
                            by NickyD