# 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) :

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. • 11/16/2016 #

Hi,
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)

if EMA5 crosses over EMA200 then
stoploss = (close-ll)/pointsize
stoplevel = (close-ll)
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
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

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. • 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 ?

• • 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
ENDIF

3. • 11/16/2016 #

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

IF SHORTONMARKET and close > ATRts THEN
ENDIF

4. • 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. • 11/16/2016 #

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

6. • 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. • 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
ENDIF

8. • 11/16/2016 #

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

9. • 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. • 336 days ago #

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?

Register or

#### Likes

+5 more likes

Related users ' posts
carlvan
6 months ago
4
Indicators
Hi Denis, does this indicator add to the chart as panel, or on the candles. Thanks
Add it on the price chart as described in this video: https://www.prorealcode.com/blog/video...
Hello Nicolas and Ceder Trader, Sorry, I only just saw your replies. The indicator is alre...
Nicolas
1 year ago
v10.3
12
Indicators
Bonjour, j'ai essayé de faire afficher cet indic en temps 5 mn sur le 1 mn et c'est Hiroshim...
Il suffit d'ajouter l'instruction TIMEFRAME(5 minutes,updateonclose) en tête du code
cordial saludo Nicolas, una pregunta senciLla : Como coloco un STOPS en un maximo o un mini...
Nicolas
1 year ago
2
Indicators
Thanks @Nicolas. I tried to use it as Trend in a proorder system, but don't know why, it doe...
He is right. MT and mavgMT are not defined and causing errors.....
Seb
2 years ago
23
Screeners
//ind1 = ZigZagPoint[2*averagetruerange[200]](close) avr = 3 //3% ind1 = ZigZag[avr](close...
@Steph un grand merci pour ton aide mais :-( J'ai copier le code tel quel mais cependant j...
Je n'ai pas réussi à faire fonctionner l'indicateur avec le code fourni en commentaire sur P...
Nicolas
2 years ago
v10.3
57
Indicators
C'est dans ce sujet: https://www.prorealcode.com/topic/trendline-une-approche-du-trading/ M...
Bonjour Nicolas, comment est-il possible de backtester cet indicateur? cela fait une erreu...
Oui bien sûr, il doit y avoir pas mal de sujets dans le forum à ce propos.
Nicolas
2 years ago
v10.3
4
Indicators
Oui c'est possible. Merci de ne pas poster des demandes qui sont hors sujets. Pour les deman...
Merci pour cet itf. Question : comment faire pour instruire un screener ?
tester le croisement du Close avec la première valeur de l'indicateur : "TrailingStop", faci...
Zigo
2 years ago
v10.3
0
Indicators
Thomas
2 years ago
v10.3
0
Indicators
Nicolas
2 years ago
v10.3
7
Indicators
Poni qui la tua domanda se è correlata a questo indicatore, altrimenti apri un nuovo argomen...
Hi Nicolas, can i backtest this indicator? And if so, how do i do it? I have tried, but don´...
Sure, use the forums to create a new topic to ask for it Please respect the posting rules ...
Nicolas
2 years ago
v10.3
5
Indicators
bonjour nicolas! j'aimerais pouvoir changer les couleurs des chandelier directement depuis ...
remplacer les valeurs de coloured(0,255,0) par coloured(r,g,b) et ajouter ces noms de variab...
merci Nicolas!
Nicolas
3 years ago
v10.3
6
Indicators
You should open a new topic to discuss about the strategy and its coding.
Hello Nicolas, How could plot this indicator over the price series? Thanks Dave
Just add it on the price series.
Thomas
3 years ago
13
Indicators
Clean view, thanks for sharing
hi where i can found the window for candle configuration?
Ciao! . I have seen the pictures that explain this metod but i don't understand when is mome...
Thomas
3 years ago
v10.3
16
Indicators
Como? no intiendo. Can you write in english . It works! Download the itf file.
New Version comin soon...
OLA NAO SERVE PARA MT4?
Jan
3 years ago
9
Strategies
Please could someone explain how the following code is calculated:- iDI = TEMA[3](DI[DI2]...
Jan, I find sometimes that the priceexit variable is never set. It seems to happen when the ...
I do not understand the first time I launch the backtest I got the same result as you. but ...
juanj
3 years ago
v10.3
0
Indicators
juanj
3 years ago
v10.3
1
Indicators
I have actually completely redesigned this indicator with loads of improvements, so will res...
Oscar Gil Balaguer
4 years ago
v10.3
0
Indicators
Nicolas
4 years ago
v10.3
5
Indicators
Thank you Nicolas, great indicator, N. 1
Merci Nicolas! First Happy new Year 2020. Very good indicator BUT (yes the french "oui, m...
Whats prorealtime version? Did you try in version prior to v11? indicator's call and loop ca...
Nicolas
4 years ago
v10.3
3
Indicators
Hello Nicolas, is it possible to stablish a bullish screener for this indicator when the cen...
Please open a topic in the screener section to ask for this specific query.
Hello, the indicator doesn't show up anything on the screen, any suggestions please?
Nicolas
4 years ago
3
Indicators
Hi Nicolas, when i upload this indicator in my list and use it as indicator. I get a totally...
Apply it on the price chart. The indicator plot just one single line. There are two in the...
Hi Nicolas, do you happen to know if there is an indicator that can be applied to charts, to...

Top