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

ATR Trailing Stop

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

    ATR Trailing Stop

    Quick question on general ATR in Ninja...

    When we have ATR calculated, the value is in points, correct?

    ie: lets say that ATR(20)[0] = .5 that would be equal to 1/2 points... and in the case of the ES that would equal two ticks right?

    what if ATR(20)[0]= 0.45, and we wanted to do an Trailing stop of the 20period ATR... could we do something such as...

    Code:
    SetTrailStop("Some Signal Name", CalculationMode.Ticks, 4 * ATR(20)[0], false)
    and have a stop loss set at 1.8 ticks which I assume would be rounded to 2 ticks?

    or am I way off in left field here?

    #2
    Hi BigDog008, you can use Instrument.MasterInstrument.Round2TickSize to round this to the proper value for the instruments you run this on - http://www.ninjatrader-support.com/H...2TickSize.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      ok, also, is my logic sound in terms of doing an ATR trailing stop?

      i'm assuming that this trailing stop would be done under OnBarUpdate rather than during initialize

      Comment


        #4
        Correct for a dynamic one, please put it into the OnBarUpdate() section.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          You would do it under OnBarUpdate(). I would not know if this would be the behavior you were looking for. It will start with a stop loss at however many ticks the ATR calculates out to be. Remember, these need to be whole numbers for a tick offset. Then as the price goes up it will trail by the tick. When OnBarUpdate() comes along again, you will modify the stop to whatever the new ATR value is which may or may not be lower than whatever your trailing stop raised it to already. Then it would start trailing again from there.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            You would do it under OnBarUpdate(). I would not know if this would be the behavior you were looking for. It will start with a stop loss at however many ticks the ATR calculates out to be. Remember, these need to be whole numbers for a tick offset. Then as the price goes up it will trail by the tick. When OnBarUpdate() comes along again, you will modify the stop to whatever the new ATR value is which may or may not be lower than whatever your trailing stop raised it to already. Then it would start trailing again from there.

            is there a way to avoid having it lower or raise the trailing stop? meaning once it sets it trails till getting out of the trade?

            Comment


              #7
              If you use the SetTrailStop, it will automatically trail on a tick by tick basis - http://www.ninjatrader-support.com/H...TrailStop.html
              BertrandNinjaTrader Customer Service

              Comment


                #8
                and it won't update it on the next bar update correct? once its set, its set until it exits the trade?
                Code:
                   { 
                    Instrument.MasterInstrument.Round2TickSize(12.5);
                    SetTrailStop("Long A", CalculationMode.Ticks, 4 * 1.5 * (ATR(20)[0]), false);
                    SetTrailStop("Short A", CalculationMode.Ticks, 4 * 1.5 * (ATR(20)[0]), false);
                   }
                this is what I've done, Long A/Short A are my signal names, and I want my stoploss to be 1.5 * the ATR, and multiply by 4 to get the proper amount of ticks from the point value that is calculated...
                Last edited by BigDog008; 03-12-2009, 08:40 AM.

                Comment


                  #9
                  If you place it in the OnBarUpdate(), it will update bar by bar, also your ATR value...here's a snippet how to code your stop ATR value with the rounding -

                  Code:
                  [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] myATRStop = Instrument.MasterInstrument.Round2TickSize(ATR([/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2])[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]]);
                  [/SIZE][/SIZE]
                  You can use this then in SetTrailStop as the value...
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    If you place it in the OnBarUpdate(), it will update bar by bar, also your ATR value...here's a snippet how to code your stop ATR value with the rounding -

                    Code:
                    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] myATRStop = Instrument.MasterInstrument.Round2TickSize(ATR([/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2])[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]]);
                    [/SIZE][/SIZE]
                    You can use this then in SetTrailStop as the value...

                    I will still have to also multiply by 4 and whatever factor i choose (1.5 in this case) to get the proper number of ticks correct? or will I only have to multiply by my factor?

                    Comment


                      #11
                      BigDog008,

                      You will just have to try and use Print() to know what values are you getting and determine if those values are the correct ones you want.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        I guess next question for me is could I simply do a print(myATRStop) to print the values?


                        really appreciate your patience and help, its been a HUGE assistance for a noob programer like me

                        Comment


                          #13
                          BigDog008,

                          You would need to do this:
                          Code:
                          Print(myATRStop.ToString());
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by casabella, Today, 04:12 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post casabella  
                          Started by Ludwik, Today, 03:52 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post Ludwik
                          by Ludwik
                           
                          Started by wuannetraam, Today, 02:40 AM
                          0 responses
                          10 views
                          0 likes
                          Last Post wuannetraam  
                          Started by cyberpete76, 03-27-2023, 12:29 AM
                          7 responses
                          270 views
                          1 like
                          Last Post slightly  
                          Started by renewsaltwater, Today, 01:15 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post renewsaltwater  
                          Working...
                          X