Doctrading

ATR Trailing Stop

Category: Indicators By: Doctrading Created: November 16, 2016, 9:54 AM
November 16, 2016, 9:54 AM
Indicators
12 Comments
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) :

// Période
p = 14

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


// ATRts = ATR Trailing Stop

// 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
     ATRts = ATRnew
    ENDIF
ENDIF


return ATRts as "ATR Trailing Stop"

 

Download
Filename: ATR-_-stop.itf
Downloads: 890
Doctrading
Doctrading Master
Hello, I'm Marc. Nice to meet you.
Author’s Profile

Comments

aldtrading
3 years ago
#

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

Tradingrob
5 years 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?

Guibourse
5 years ago
#

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 !!

dvlukic
6 years ago
#

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

s00071609
7 years ago
#

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

s00071609
7 years ago
#

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,

Doctrading
7 years ago
#

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

Doctrading
7 years ago
#

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,

Degardin Arnaud
9 years ago
#

pardon... IF LONGONMARKET and close < ATRts THEN SELL AT MARKET ENDIF IF SHORTONMARKET and close > ATRts THEN BUY AT MARKET ENDIF

Laurent7533
9 years ago
#

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
9 years ago
#

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

mbaker15
10 years ago
#

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

 

ProRealCode ProRealCode
Loading...