ATR Trailing Stop (Volatility Stop) Study  [SOLVED]

Questions about MultiCharts and user contributed studies.
Kamisyed
Posts: 8
Joined: 25 Feb 2014
Has thanked: 1 time
Been thanked: 3 times

ATR Trailing Stop (Volatility Stop) Study

Postby Kamisyed » 30 Jun 2014

New to programming and to multicharts.

Can someone please help me code a study for atr trailing stops on a chart (ATR Length 10 / ATR Factor 3). This is a standard indicator in most charting packages and is also called a volatility stop in some packages.

I want the indicator on my charts like PSAR dots and showing me stops either above price or below (i.e. not bands). I also want them to ratchet (i.e. only follow the trend - If a long position is triggered, the stop can only move up and will not move down but instead maintain its position).

Could not find code for this on the forum although i did come across a thread on how atr in mc is calculated based on sma rather than ema. MC does have built-in ATR Trailing Stop Signals for Long/Short entry & exits, but no study.

Would really really appreciate help on this!

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: ATR Trailing Stop (Volatility Stop) Study

Postby evdl » 01 Jul 2014

You can have a look at this topic http://www.multicharts.com/discussion/v ... &hilit=ATR to have a whole set of exits. Or to get an idea how to incorporate your own exit. Credits to the original poster for this ofcourse.

Kamisyed
Posts: 8
Joined: 25 Feb 2014
Has thanked: 1 time
Been thanked: 3 times

Re: ATR Trailing Stop (Volatility Stop) Study

Postby Kamisyed » 04 Jul 2014

Thanks evld! I really appreciate your input!

However, this is saved as a signal and I am looking for an indicator. Its a standard ATR Trailing Stop/Volatility Stop that plots the stop values on the chart and starts the plot assuming the 1st position is long (like how the PSAR indicator plots in multicharts).

I've been relentlessly searching online and on the forums and have been unable to find anything.

Help from anyone will be highly appreciated!!!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: ATR Trailing Stop (Volatility Stop) Study

Postby Henry MultiСharts » 10 Jul 2014

Kamisyed, you should be able to find this study online (example) or convert a signal into an indicator.

Kamisyed
Posts: 8
Joined: 25 Feb 2014
Has thanked: 1 time
Been thanked: 3 times

Re: ATR Trailing Stop (Volatility Stop) Study

Postby Kamisyed » 10 Jul 2014

Thanks Henry,

Just purchased the lifetime license and will try wrapping my head around this.

New to programming so all of this is a little overwhelming!

Kamisyed
Posts: 8
Joined: 25 Feb 2014
Has thanked: 1 time
Been thanked: 3 times

Re: ATR Trailing Stop (Volatility Stop) Study  [SOLVED]

Postby Kamisyed » 12 Jul 2014

I thought I'd post the code for anyone ever interested in the ATR Trailing Stop. This is a modified version created by Sylvain Vervoort with certain minor differences from the tradition ATR Stop.

Code: Select all

Inputs:
Period(14),
ATRMultiplication(2);

Variables:
HiLo(0), Href(0), Lref(0), diff1(0), diff2(0), atrMod(0), loss(0), trail(0);

value1 = 1.5 * Average(High - Low, Period);
value2 = High - Low;

HiLo = IFF(value2 < value1, value2, value1);

Href = IFF(Low <= High[1], High - Close[1], ( (High - Close[1]) - (Low - High[1]) ) / 2);
Lref = IFF(High >= Low[1], Close[1] - Low, ( (Close[1] - Low) - (Low[1] - High) ) / 2);

diff1 = MaxList(HiLo, Href);
diff2 = MaxList(diff1, Lref);

atrMod = XAverage(diff2, Period);
loss = ATRMultiplication * atrMod;

trail = IFF(Close > trail[1] and Close[1] > trail[1], MaxList(trail[1], (Close - loss)),
IFF(Close < trail[1] and Close[1] < trail[1], MinList(trail[1], (Close + loss)),
IFF(Close > trail[1], Close - loss, Close + loss)));

Plot1(trail, "ATR Trailing Stop", Default);

if Close > trail then
SetPlotColor(1, green)
else
SetPlotColor(1, red);


Return to “MultiCharts”