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
jebus89 Big thanks for sharing this :) Seems to work as expected, good stuff.
xpe74 Top visually, and very efficient. I would like to integrate it as a value in a small algo i...
GraHal Please forgive the daft question, but why is 3-bars-trailing-stop-williams-3.itf included a...
Kris75 Hi, Seems great but what would be the code for a stock ? Thanks, Chirs
oakenstream Paul, what is the best way in your opinion to know if I have over optimized?
WarningTrading Comment peut on la comparer ? comme ceci ? cela ne me donne plus le message d'erreur manque...
sally31120 Bonjour, je n'arrive pas à créer ce screener close > supertrend extended2[1] la réponse...
Nicolas voir ce sujet pour un screener basé sur Supertrend Extended: https://www.prorealcode.com/top...
JanWd Tried the code, nice concept, seems to work quit well for US/EUR 2hrs, Other markets seems n...
JR1976 Simple and nice code , congrats !!! Seems work well with TIme frame 1 h
phanz Hi all, Sorry revisiting an old post. This algo is simple, and simplicity is the ultimate ...
Mr_Balagan Bonjour, j'ai quelques questions concernant cette combinaison d'indicateurs qui à l'air inté...
larouedegann STE : Fonction statistique "erreur standard" de séries temporelles de N périodes pour le pri...
Mr_Balagan Merci pour ces informations précieuses larouedegann. J'y vois plus clair. Encore joli boulot
Kris75 Hi Gabri I launched a very simple strategy based on the 3 bars trailing stop that you cre...
TimDeCat Hi. Has anyone coded a version that you could alter it to say 5 bar trailing stop? ie make ...
Nicolas Please open a new topic in forums so we can code it there, thanks.
poonsl2828 Hi! Francesco I have test it on GBP/USD but it only have a trade on 9 Jun which i backtes...
ullle73 why not use 1h chart? has 95% hitrate
ullle73 i see most of positions are only 1 pip before exit?
Jean-Pierre Poulain When I buy and when I sell ?
Nicolas The featured image of the post do not deserve the indicator you are right, I attached other ...
Nicolas It is described in the post already :) The BUY/SELL signals are quite similar of what you ca...
fabio407 Thanks, Nicolas. Very useful. Would you tell me where to find what result conveys the functi...
Nicolas This is not an instruction of the programming language but a variable from this indicator (l...
fabio407 OK. I didn't notice it. Many thanks, Nicolas!
albertocampagna Sei grande Nicolas :-)
SAcht Dear Nicolas, Great work, thank you very much!I would love to use the indicator in ProScree...
SAcht btw: The above-posted ProScreener is supposed to show stocks for which the center line has i...
victormork Hi, I would just like to share my own take on this strategy. I'm using 30 min on EURUSD but ...
mckubik Thanks. I will run a Test. 
poonsl2828 Hi! bjoern May i know what timing should i change for time zone (Singapore (GMT +8:00) ...
Nicolas Rien, il faut l'appliquer sur la charte. Soit le mettre sur le graphique du prix, à l'aide d...
signorini Merci pour votre réponse. Je l'applique sur la charte, j'utilise la petite clé pour effacer ...
signorini Je vous remercie, Nicolas. C'est fixé. Très bon week-end.
julien1978 The ADR value that is plotted intraday does not match the value of the regular ATR indicator...
Fab666 I've tried to get a fix for this also but no luck, it doesn't print the correct data as far ...
Seabiscuit Hi! With the new PRT update, this indicator does not work anymore
Nicolas Use the wrench of the price chart! Upper left of the window
Dymjohn The wrench shows options for the components of the indicator not how to show in the main cha...
Nicolas http://www.prorealcode.com/topic/overlapping-indicators/  
David Thanks for the explanation Nicolas.
freecat1899 Hello, I wanted to create a percent ADR based on this indicator, so I wrote this code that I...
revstrat At first glance, I see this mistake. You shouldn't average the highs and the lows. You shoul...
denmar Hi Could somebody please enlighten me how this code operates. I wish to use the code (is...
denmar Testing email notification to Denmar
David Black #gm74 Did you ever get this figured out? gm74
Investment Account Wow great thanks ... looks good! Do I set the colour shades up from within the indicator 's...
avatar
Anonymous Thanks for your comments and yes, that is exactly how I set up the colour levels.
Vish Thanks I have added this in my watch list. Has anyone tried it yet ? Does it work on currenc...
sr021 Hi I tried to copy and paste the code, but recieve the message  : Syntax error:The followi...
Nicolas Hello, of course. You have 3 options : 1/ you download the file and import it into your plat...

Top