Nicolas

Another ATR Trailing Stop

Category: Indicators By: Nicolas Created: September 24, 2019, 1:14 PM
September 24, 2019, 1:14 PM
Indicators
10 Comments
Another ATR Trailing Stop

Closely following the price with the Another trailing stop ATR (Average True Range), a based trend following indicator. The idea of this indicator is to closely following the price to get out quickly if the price tends to not move enough to ensure the trend is profitable.

This version uses declining ATR to closely adapt its level to the price. The trailing stop line is following the highest Close (green when it is bullish) or Lowest Close (red when it is bearish) by adding or subtracting the ATR value multiplied with the “mult” setting.

If the ATR (aka price volatility) is ascending, then the trailing stop keep its previous level. When it is declining, the trailing stop level adapt its value according to the current trend:

  • Long trend: if the new calculated level is higher than the previous one
  • Short trend: if the new calculated level is lower than the previous one

The ATR trailing stop has 2 modes: (“mode” setting)

  • mode=0 ; the trend line will keep the same level each time a cross over occur
  • mode>0 ; the trend line will take the highest or lowest Close level each time a cross over occur

The chosen mode of the trailing stop line behavior depends of your own trading style, traded instrument and timeframe.

Idea come from this topic in the indicator’s forum: ATR TRAILING STOP

If you have other ideas, nevermind opening a new topic in the forum describing what you have in mind. The community will try to help you achieving your goal!

//PRC_Another ATR trailing stop | indicator
//24.09.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

// --- settings 
p=14 //ATR period
mult=2 //multiplier 
mode=1 //trailing stop mode (0=straight line
// --- end of settings 

atr = AverageTrueRange[p](close) * mult

once trend=1

if trend=1 then 
 hh=max(hh,close)
 ll=hh
 if atr<atr[1] then 
  hhlevel=hh-atr
   if hhlevel>ts then 
    ts=hhlevel
   endif
 endif
 r=0
 g=168
else
 ll=min(ll,close)
 hh=ll
 if atr<atr[1] then
  lllevel=ll+atr
  if lllevel<ts then
   ts=lllevel
  endif
 endif
 r=255
 g=0
endif 


if close crosses over ts then
 trend=1
 if mode>0 then 
  ts=ll
 endif
elsif close crosses under ts then
 trend=-1
 if mode>0 then
  ts=hh
 endif
endif


return ts coloured(r,g,0) style(line,3)

 

Download
Filename: PRC_Another-ATR-trailing-stop-1.itf
Downloads: 772
Download
Filename: atr-trailing-stop-1.png
Downloads: 306
Nicolas
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Loloshang
4 months ago
#

Bonjour à partir de ce code j'essaie de créer un trailing short only mais j en'y arrive pas // PRC ATR trailing stop SHORT only

p=14

mult=2

 

atr = AverageTrueRange[p](close) * mult

 

once ll = close

once ts = close + atr

 

ll = min(ll, close)

 

if atr < atr[1] then

lllevel = ll + atr

if lllevel < ts then

 ts = lllevel

endif

endif

 

return ts coloured(255,0,0) style(line,3)

Nicolas
4 months ago
#

Pourquoi pas, mais le mieux serait d'ouvrir un sujet sur le forum de trading automatique, et de nous indiquer dans quelle stratégie il faut l'implanter, etc.. ce sera bien plus simple de traiter ta demande dans cette partie du site, merci ! Ouvre un sujet ici: https://www.prorealcode.com/forum/prorealtime-forum-francais/support-proorder/

yomisadiku
3 years ago
#

Hello Nicolas, Can I use high and low price at lines hh=max(hh,close) and ll=min(ll,close) instead of close ? What impact would that make to my tracking? Thank you. Ahmed

Nicolas
3 years ago
#

Yes you can do that, the impact will be that the trailing stop line will be much close to the price.

dvlukic
6 years ago
#

Hello Nicolas, How could plot this indicator over the price series? Thanks Dave

Nicolas
6 years ago
#

Just add it on the price series.

s00071609
7 years ago
#

Where can i find the syntax to test the colour of the line, I am calling the indicator values at the moment, this is my current code, ts= Call "ATR STOP2" IF SHORTONMARKET AND close > TS THEN BUY AT MARKET ENDIF I tried few syntax but it gives error. Could you please help?

Nicolas
7 years ago
#

You should open a new topic to discuss about the strategy and its coding.

s00071609
7 years ago
#

I tried this indicator to trail stop. Problem i am facing is that, when there is a trend change, say from bullish to bearish. For example, In a short entry - I get stopped out when price moves back and touches the support line of Bullish Trend. While the purpose of stop is to sell when the BEARISH upper line is crossed (when short in market), positions get stopped out at start of the trend. I think this is unintended consequence. I tried similar another indicator, same thing happens. How would be possible to BUY only when RED line above is crossed in Short Entry and Bottom Green line when Long?

Nicolas
7 years ago
#

Use the color variables R and G to test if the trend is bullish (R=0) or bearish (R>0).

ProRealCode ProRealCode
Loading...