Nicolas

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
CDC ATR Trailing Stop v2.1

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: 805
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

Caribeengeek
9 years ago
#

Les devises unité

Caribeengeek
9 years ago
#

Bonjour j’avais vu que vous proposiez d’écrire des codes pour ceux qui s’y connaisse pas Maison je me rappel plus a quel e-mail vous envoyer svp c’est pour un screemer pour les devises time frame 1H merci d’avance

Nicolas
9 years ago
#

Merci d'utiliser le forum pour les demandes de programmation personnalisée

Matt B
9 years ago
#

c'est bon çà marche ! j'ai supprimé toutes les lignes vides du dessus

Matt B
9 years ago
#

Bonjour Nicolas, je débute et suis intéressé par cet indicateur mais quand je copie/colle le code dans le mode "création d'indicateur" j'ai un message d'erreur : "erreur de syntaxe dans l'assignation" et la dernière ligne est grisée. Merci pour votre aide.

Inertia
9 years ago
#

Thank you Nicolas. Nice one ;)

bezieh
9 years ago
#

Another question.. is it even needed to learn how to code, even if you seem to have found a good strategy with the wizard? Just because the wizard is simple, doesn't mean it's bad.. It's usually the simple strategies that last good in the long run, just like trading manually, doing over complex shit will not do any good

Nicolas
9 years ago
#

No, but if you are able to code, you can use any of the codes around here and improve them for your own needs like this is the case for this indicator.

bezieh
9 years ago
#

Oh okay, and how do i tell the wizard to buy and sell accoring to the arrows, because i only see the option to buy and sell when the indicator is under or over the price, thats the problem :p

Nicolas
9 years ago
#

You can also test values of indicator. Equal or not to 1 for example.

bezieh
9 years ago
#

Ok, i pressed modify in the indicator, and changed the last return line with that line you sent me. But it's still an indicator? When i press the wizard to create bot i still have to put in the buy and sell signals, so it still doesn't work mate

Nicolas
9 years ago
#

yes it is still an indicator obviously :) But now you can get the signals (ones with arrows) with the "wizard", mate. Learn to code and no need of wizard things anymore ;) Start with the first course: https://www.prorealcode.com/courses/training-program-introduction-programming-prorealtime/ the advanced one should come this month.

bezieh
9 years ago
#

I dont understand what you mean.. the code already has "ssell" and "sbuy"..?

Nicolas
9 years ago
#

change the RETURN instruction line with this one: return ts1 style(point,1) as "Fast Trail", ts2 coloured(rtrail,gtrail,0) style(line,2) as "Slow Trail", ssell,sbuy Then you'll be able to use these last variables in any trading strategies, by looking for their values, 1 means a new signal, 0 means no signal.

bezieh
9 years ago
#

Looking good nicolas, although, after i download it and have it as a indicator, what settings should i put in the wizard so it buys and sells as the indicator shows? Doesn't seem to figure out how to do that, thanks :)

Nicolas
9 years ago
#

Add sSell and sBuy in the RETURN instruction and you should be able to use the indicator in automatic trading.

Maik2404
9 years ago
#

Ich hab mal eine Frage zu deinem Indikator: Der Einstieg ist ja über die Pfeile geregelt.Ab wann steige ich aus? Bei Short am Ende der roten Linie?

zilliq
9 years ago
#

All works in High Volatility Market ;-) Thanks Nicolas and have a nice day

ProRealCode ProRealCode
Loading...