ATR Trailing Stop

ATR Trailing Stop

Hi all !

At the request of one of my readers of my website, I created this code : the ATR Trailing Stop.

I have not found any ProRealTime code of this indicator over the internet, so I created myself this code today.

I apologize if you already have a same code.

The ATR trailing stop is an indicator which, as its name suggests, uses the Average True Range as a trailing stop.

In this code, I did choose a period p = 14, but feel free to change it.

How to calculate the ATR trailing stop (ATRts) ?

The ATRx is defined by the closing price which is subtracted (uptrend) or added (in downtrend) 3.5 x ATR.

In uptrend (close > ATRts), if ATRx of the day is greater than the ATRx of the day before, the ATRts takes the value of the ATRx.

But if this ATRx day is lower than the day before, the ATRts is unchanged.

Therefore: the ATRts can only increase or stay the same in uptrend.

Of course, the rules are the opposites for a downtrend.

A simple indicator, and effective for trading!

Notice that it reminds closely the « SuperTrend » of Olivier Seban…

Here is the code (please insert it on the main graph) :

 

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. mbaker15 • 11/16/2016 #

    Hi,
    Could you help me add this to my swing trading code?
    Mark
    defparam cumulateorders = false

    REM Money Management
    Capital = 2500 // initial capital at launch of the strategy
    Risk = 2.5 // risk in percent

    REM Calculate contracts
    equity = Capital + StrategyProfit
    maxrisk = round(equity*(Risk/100))

    REM defining moving averages
    EMA5 = exponentialaverage[20]
    EMA100 = exponentialaverage[150]
    EMA200 = exponentialaverage[200]
    hh = highest[20](high)
    ll = lowest[20](low)

    // -- case BUY
    if EMA5 crosses over EMA200 then
    stoploss = (close-ll)/pointsize
    stoplevel = (close-ll)
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    BUY PositionSize SHARES AT MARKET
    endif

    // -- case SELL
    if EMA5 crosses under EMA200 then
    stoploss = (hh-close)/pointsize
    stoplevel = (hh-close)
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    SELLSHORT PositionSize SHARES AT MARKET
    endif

    // -- trades exit
    if EMA5 crosses under EMA100 then
    SELL AT MARKET
    endif
    if EMA5 crosses over EMA100 then
    EXITSHORT AT MARKET
    endif

    SET STOP LOSS stoplevel
    SET TARGET PROFIT 100

     

  2. Laurent7533 • 11/16/2016 #

    Bonjour,
    J’aimerais utiliser cet indicateur dans un autre indicateur mais quand j’utilise la commande CALL ” ATR TRAILING STOP”, ça ne marche pas. Je ne comprends pas pourquoi ça ne marche pas. Une idée ?

    • Degardin Arnaud • 11/16/2016 #

      Ajoute ceci à la strategie pour gerer les sorties dans le proorder:
      //ATR TRAILING STOP
      // Période
      p = 14

      // Average True Range X
      ATRx = AverageTrueRange[p](close) * 3.5

      // Inversion de tendance
      IF close crosses over ATRts THEN
      ATRts = close – ATRx
      ELSIF close crosses under ATRts THEN
      ATRts = close + ATRx
      ENDIF

      // Cacul de l’ATRts lors de la même tendance
      IF close > ATRts THEN
      ATRnew = close – ATRx
      IF ATRnew > ATRts THEN
      ATRts = ATRnew
      ENDIF
      ELSIF close < ATRts THEN
      ATRnew = close + ATRx
      IF ATRnew ATRts THEN
      SELL AT MARKET
      ENDIF

      IF SHORTONMARKET and close < ATRts THEN
      BUY AT MARKET
      ENDIF

  3. Degardin Arnaud • 11/16/2016 #

    pardon…
    IF LONGONMARKET and close < ATRts THEN
    SELL AT MARKET
    ENDIF

    IF SHORTONMARKET and close > ATRts THEN
    BUY AT MARKET
    ENDIF

  4. Doctrading • 11/16/2016 #

    Bonjour à tous,
    Pour une raison que j’ignore, le code ne fonctionne plus tel quel.
    Il fonctionne de nouveau avec ceci :

    Je n’ai pas d’explication.
    Cordialement,

  5. Doctrading • 11/16/2016 #

    // Inversion de tendance
    IF close[1] ATRts and close < ATRts THEN
    ATRts = close + ATRx
    ENDIF

  6. s00071609 • 11/16/2016 #

    Hi Guys Quick question regarding the above indicator. First of all is the below code correct for trailing STOP using the above indicator
    I have uploaded the indicator and named it ATRSTOP and used this code. When order is entered before the market turns bearish, and indicator just start to form the upper resistance, the price moves down and then it gets whipsawed at the prior bull support line. If i am understanding this correctly I believe this is what is happening. Any help would be great, thanks,

  7. s00071609 • 11/16/2016 #

    This is the code, could not insert in with ADD PRT

    //ATR STOP TRAIL FOR STU
    ATRts = CALL “ATRSTOP”
    //IF LONGONMARKET and close ATRts THEN
    BUY AT MARKET
    ENDIF

  8. dvlukic • 11/16/2016 #

    Hi Doctrading,
    How do I make the indicator overlay on the price series like on your screenshot?
    Thanks
    Dave

  9. Guibourse • 11/16/2016 #

    Hi ! I am asking once again for your help : would it be possible to use the ATR as a “take profit” ? In an uptrend for example it would create a line above the price… Thanks a lot !!

  10. Tradingrob • 11/16/2016 #

    Many thanks for the indicator, however if the price is below the indicator, then the indicator’s line must also be colored red as a stop loss signal for the short. Unfortunately he doesn’t yet. Can this be changed in a new itf?

  11. aldtrading • 11/16/2016 #

    Merci pour ton travail ! J’ai de bons résultats en utilisant cet indicateur

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar

+9 more likes

Related users ' posts
P. Marlowe Muy bueno. ¿Podría hacerse para señalar extremos por el lado bajista? Lo mismo a la inversa....
Miro Esta es una versión del indicador, para ambos extremos. //-------------------------------...
P. Marlowe Muchas gracias ¡¡
Faisalx Hola Ivan. Thanks for your great job. I would appreciate if you have look at my request http...
roccafragius Thank you for all these useful information!! Very great job Ivan! THank you so much
geroniman Merci Ivan, super travail. On peut toujours compter sur toi pour apporter des innovations su...
Iván Allora crei un nuovo post. Lo aspetterò.
Stenozar Ciao Ivan, ho inserito il post con la richiesta di traduzione. Se puoi vedere, grazie!
Iván perfect!
larouedegann TIMEFRAME(15minutes) apparemment ne fonctionne pas
Iván Bonjour Je ne comprends pas bien le problème. L'indicateur fonctionne dans n'importe quelle...
larouedegann OUI je le sais, il fonctionne dans toutes les unités de temps. Mais je souhaite utiliser l'i...
Doddge Hola Iván, ¿sería posible crear un screener que indique cuándo las velas coloreadas del indi...
RTR Ivan thank you for the pro-screener. I a trying to understand how to write the signals from ...
Iván Hi, Lines 62 and 63. These lines define buy and sell conditions.
Iván
11 months ago
winnie37 Hi Ivan, if i want to use it, and call the oscillator value (in grey, green or red), how to...
Iván The oscillator is smoothtype. In inputs there is de lag to configure the output
mfejza also, for long trailing stop d2=low d1=lowest[3](d2)+1/3*AverageTrueRange[20](close) d3...
CederTrader Hi Denis, does this indicator add to the chart as panel, or on the candles. Thanks
Nicolas Add it on the price chart as described in this video: https://www.prorealcode.com/blog/video...
Denis Hello Nicolas and Ceder Trader, Sorry, I only just saw your replies. The indicator is alre...
Xenotrax A première vue, sa à l'air d'être un indicateur très puissant sur de petites temporalités, j...
merri Bonjour Nicolas, Comment transformer cet indicateur en bot sur PRT ?
Nicolas Cela a déjà été fait, voir ce sujet: https://www.prorealcode.com/topic/strategia-con-lindica...
zilliq Thanks @Nicolas. I tried to use it as Trend in a proorder system, but don't know why, it doe...
Suzu Yuk He is right. MT and mavgMT are not defined and causing errors.....
StephFor //ind1 = ZigZagPoint[2*averagetruerange[200]](close) avr = 3 //3% ind1 = ZigZag[avr](close...
Manu L. @Steph un grand merci pour ton aide mais :-( J'ai copier le code tel quel mais cependant j...
AlphaMauss Je n'ai pas réussi à faire fonctionner l'indicateur avec le code fourni en commentaire sur P...
Pensera Bonjour Nicolas, comment est-il possible de backtester cet indicateur? cela fait une erreu...
Nicolas Oui bien sûr, il doit y avoir pas mal de sujets dans le forum à ce propos.
simmerseb Bonjour, merci beaucoup pour cet indicateur je le trouve très clair et pertinent.
Nicolas Oui c'est possible. Merci de ne pas poster des demandes qui sont hors sujets. Pour les deman...
Igor Merci pour cet itf. Question : comment faire pour instruire un screener ?
Nicolas tester le croisement du Close avec la première valeur de l'indicateur : "TrailingStop", faci...
supertiti Bonjour Nicolas, Je ne comprend pas bien , le trend change de couleur quand les prix sont a...
Nicolas Oui ce serait possible, cependant l'indicateur est bien prévu pour conserver la couleur de l...
supertiti Quand tu pourras si tu peux nous coder la troisième couleur cela améliorerait les trades cou...
Nicolas remplacer les valeurs de coloured(0,255,0) par coloured(r,g,b) et ajouter ces noms de variab...
mohamed merci Nicolas!
sacram14 Merci Nicolas pour ce set-up que je ne connaissais pas ! J'ai tenté de reprendre le code pou...
Nicolas Just add it on the price series.
yomisadiku Hello Nicolas, Can I use high and low price at lines hh=max(hh,close) and ll=min(ll,close) ...
Nicolas Yes you can do that, the impact will be that the trailing stop line will be much close to th...

Top