ATR Trailing Stop

Category: Indicators By: Doctrading Created: November 16, 2016, 9:54 AM
November 16, 2016, 9:54 AM
Indicators
12 Comments

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: 876
Doctrading Master
Hello, I'm Marc. Nice to meet you.
Author’s Profile

Comments

Logo Logo
Loading...