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

Indicator Based Stop-loss Strategy

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

    Indicator Based Stop-loss Strategy

    I'd like to build a stop loss strategy around 2 indicators: ATR and St.Err. but am not sure where to start. Initially I'd like to place a stop loss at an ATR below my entry and then once price crosses an ATR past each standard error band have the stop loss move to trail the band so that on a good price move it ultimately ends up trailing the outer band. Easier said than done? Thanks.

    #2
    Hello jak479,

    Thanks for your post and welcome to the NinjaTrader forums!

    Are you coding directly in Ninjascript or are you working with the Strategy Builder?

    I'm not sure I understand what you are trying to do, can you provide a chart screenshot marked up to provide a visual example?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the welcome. If it's doable in strategy builder that's my first choice. Here is a chart.

      Ok so in this chart you can see where I entered a long trade and my stop loss.

      Step 1 of the strategy would have the system place the stop loss at 1 ATR below entry.
      On the chart, the stop loss is 50 cents lower, corresponding to 1 ATR which is being tracked at the top of the window.

      Step 2 would trigger when the price bar closes 1 ATR above the lower blue band using whatever the dynamic ATR number is for that moment. Then the stop order would move up to track the band.

      Step 3 would trigger when the price bar closes 1 ATR above the gold band and then proceed to track it.

      Step 4 would similarly trigger and move the stop to the top blue band, but in this case I would only want it to track as long as the slope is positive.

      Hope that makes sense.
      Attached Files

      Comment


        #4
        Hello jak479,

        Thanks for your reply and clarifications.

        You should be able to do this in the Strategy Builder and it will require using bool type variables to control the "steps" and double type variables to hold the current value of the ATR when you place the entry order. You might think of the steps as being "sets" and using different bool variable for each set so that you can logically control the sequencing as you described.

        While we cannot create this for you, or provide debugging services, here is a general description of what you would need to do. I'll add some educational references at the end.

        For example, in one set you have your entry conditions and there you would save the current value of the ATR into a double type variable and set a bool variable true. In another set you would check that you are in a market position (see link below), check that the bool is true and then place the Exit stop order at the (strategy>Position average price) plus (or minus) the saved ATR value. You would also set another bool true that would get you into the next set (Step 2). Likewise for steps 3 and step 4.

        For slope, you can find that Under the Misc folder.

        Note 1: The exit order will automatically be canceled if it is not filled on the bar that it is placed. This means that you have to continually submit the exit order and the bools along with the market position check will help you to do that.

        Note 2: You didn't mention a profit target and perhaps you do not need one but to clarify when you are using stop exit you would have to use an exit limit order for the profit target. You cannot use the Stops and profit targets window as this would be a conflict.


        References:





        Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
        Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
        Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm


        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Got it working! Thanks for the help!

          Comment


            #6
            I suspect I need to debug my stoploss order entry. What I would like to do is mark up the chart to show where the system has placed its stop orders. Is there a way to do this?

            Comment


              #7
              Hello jak479,

              Thanks for your reply.

              In another set you can check the market position and if long (or short) you can draw a marker, such as a dot/square/triangle at the Yvalue of Position.AveragePrice plus (or minus) the ATR value.



              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Will the drawing show up on backtesting? I only see entries and exits, no indicators on the chart.

                Comment


                  #9
                  Hello jak479,

                  Thanks for your reply.

                  Yes, however, to see a marker at every instance you would have to provide a unique tag name for the object. If the same tag name is used the previously drawn object is automatically removed to make way for the new object. This is the default behavior in the Strategy Builder( using the same tag names), so you would only see the latest occurrence.

                  The other requirement is the Y location, (Price location), to display the object. Typically you would want to relate this to a price on the chart such as above or below the bar so that it is visible. By default, this value would be 0 so you may be drawing them but at a price of 0 unless you have put in a price reference

                  I've attached a short video on how to be able to see all of the markers and well as how to adjust them to place on the chart: https://paul-ninjatrader.tinytake.co...MF8xMTMwNTc0MA

                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Very helpful video. Resulting dots are very helpful in figuring out what is going on. Thanks!


                    Click image for larger version

Name:	NQ 03-21 (1 Minute) 2020_12_18 (12_04_27 AM).png
Views:	621
Size:	40.1 KB
ID:	1133173

                    Comment


                      #11
                      Hello jak479,

                      Thanks for your reply.

                      Yes, using draw markers can be very helpful when debugging. It is common to use them to indicator when a "set" is true. By using different colors (or different objects) and placing them at different y location offsets you can see bar by bar what set it true and when.

                      Glad you found the video helpful!

                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        In this trade, there are about 10 ticks of value that got left on the table. I am having trouble configuring the exit to correct this. What I would like to do is have an exit order placed when the gold St. Err bar starts to reverse its direction. I can't quite figure out how to place it in condition builder. Appreciate your help.
                        Attached Files

                        Comment


                          #13
                          Hello jak479,

                          Thanks for your reply.

                          Is the screenshot of a live trade or a trade made on historical data?

                          What is the Calculate setting of the strategy? (Calculate.OnBarClose, Calculate.OnPriceChange, or Calculate.OnEachTick)

                          "What I would like to do is have an exit order placed when the gold St. Err bar starts to reverse its direction." In your screenshot I don't see a gold bar. Are you referring to the 4:00 bar or the longer 4:01 bar?

                          Can you provide a screenshot of your exit condition?
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            The screenshot reflects historical data. The strategy calculates on each tick. Sorry for the confusion. I meant to state the gold regression line not the 4:01 exit bar. So ideally I would like to make it so an exit order gets submitted when the channel turns south which is at approximately 3:40.

                            Comment


                              #15
                              Hello jak479,

                              Thanks for your reply.

                              You could compare the current bar value of the lower band to the previous bar value of the lower band and see if it is less indicating perhaps a reversal. This may be too reactive as only two bars are considered.

                              You could use the Misc>Slope and use the std error bands (pick one of the 3 plots) as the input series. A negative value of slope would indicate falling. The slope allow you o specify how many bars to use for the slope calculation. So you can use Misc>Slope> indicators>std error (pick a plot), less, Misc>numeric value> 0

                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gentlebenthebear, Today, 01:30 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by Kaledus, Today, 01:29 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              13 responses
                              45 views
                              0 likes
                              Last Post frankthearm  
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              56 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Working...
                              X