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

using trailing stops in Strategy builder

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

    using trailing stops in Strategy builder

    Hi

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

    Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Builder.2:45 Opening a Strategy Builde...


    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

    #2
    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.

    Demo: https://www.screencast.com/t/IXoV3FnFr

    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() - https://ninjatrader.com/support/help...ttrailstop.htm

    Calculation Modes reference - https://ninjatrader.com/support/help...ndTargetValues

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

    Comment


      #3
      Thanks Jim, that was perfect!

      Comment


        #4
        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.

        Comment


          #5
          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

          Comment


            #6
            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..!

            Thanks

            Comment


              #7
              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 - https://ninjatrader.com/support/help...ccountPosition

              IsAdoptAccountPositionAware is documented here - https://ninjatrader.com/support/help...itionaware.htm

              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

              Comment


                #8
                Thanks Jim..

                Comment


                  #9
                  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

                  Comment


                    #10
                    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 - https://www.screencast.com/t/8uvjfM8h

                    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

                    Comment


                      #11
                      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?.
                      Thanks
                      Vinh Phan

                      Comment


                        #12
                        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) — https://www.youtube.com/watch?v=_KQF2Sv27oE

                        Conditions examples —https://ninjatrader.com/support/help...on_builder.htm

                        Actions examples — https://ninjatrader.com/support/help...us/actions.htm

                        We look forward to assisting.
                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          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.

                          Comment


                            #14
                            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

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Barry Milan, Today, 10:35 PM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by WeyldFalcon, 12-10-2020, 06:48 PM
                            14 responses
                            1,428 views
                            0 likes
                            Last Post Handclap0241  
                            Started by DJ888, Yesterday, 06:09 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            40 views
                            0 likes
                            Last Post jeronymite  
                            Started by bill2023, Today, 08:51 AM
                            2 responses
                            16 views
                            0 likes
                            Last Post bill2023  
                            Working...
                            X