CDC ATR Trailing Stop v2.1

Category: Indicators By: Nicolas Created: April 10, 2018, 2:22 PM
April 10, 2018, 2:22 PM
Indicators
18 Comments

Contains two ATR trailing stop lines, fast and slow.
The slow ATR SL line is the same as the one in a normal ATR trailing stop loss indicator.
The fast one is created to generate buy/sell signals (plot arrows on the chart).

The system works well in high volatility market.

(translated from tradingview code, following a request in the Spanish forum).

//PRC_ATR Trailng Stop v2.1 | indicator
//10.04.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from Tradingview code

// --- settings 
// Fast Trail //
AP1 = 5 //"fast ATR period",integer) // ATR Period
AF1 = 0.5 //"fast ATR multiplier",float) // ATR Factor
// Slow Trail //
AP2 = 10 //"slow ATR perod",integer) // ATR Period
AF2 = 2 // "slow ATR multiplier",float) // ATR Factor
// --- end of settings 

SC = customclose
SL1 = AF1*AverageTrueRange[AP1] // Stop Loss
once trail1=sc-sl1

if sc>trail1[1] and sc[1]>trail1[1] then 
 trail1 = max(trail1[1],sc-sl1)
else
 if sc<trail1[1] and sc[1]<trail1[1] then 
  trail1=min(trail1[1],sc+sl1)
 else
  if sc>trail1[1] then
   trail1=sc-sl1
  else
   trail1=sc+sl1
  endif
 endif
endif

SL2 = AF2*AverageTrueRange[AP2] // Stop Loss

if sc>trail2[1] and sc[1]>trail2[1] then
 trail2 = max(trail2[1],sc-sl2)
else
 if sc<trail2[1] and sc[1]<trail2[1] then
  trail2=min(trail2[1],sc+sl2)
 else
  if sc>trail2[1] then
   trail2=sc-sl2
  else
   trail2=sc+sl2
  endif
 endif
endif


ts1 = trail1
ts2 = trail2

if sc>trail2 then 
 rtrail=0
 gtrail=255
else
 rtrail=255
 gtrail=0
endif

drawcandle(trail1,trail2,trail1,trail2) coloured(rtrail,gtrail,0,50)bordercolor(0,0,0,0)

Hst = Trail1-Trail2
Sig = average[9,1](Hst)

// Bar color for trade signal //
Green = Hst>0 and Hst>Sig
Red = Hst<0 and Hst<Sig

sBuy = green and not green[1]
sSell = red and not red[1]

if sBuy then 
 drawarrowup(barindex,ts2)coloured(rtrail,gtrail,0)
endif
if sSell then 
 drawarrowdown(barindex,ts2)coloured(rtrail,gtrail,0)
endif

return ts1 style(point,1) as "Fast Trail", ts2 coloured(rtrail,gtrail,0) style(line,2) as "Slow Trail"

 

Download
Filename: PRC_ATR-Trailing-Stop-v2.1.itf
Downloads: 791
Nicolas Master
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

Logo Logo
Loading...