# AB Trailing Stop Code



## The Estimator (19 December 2005)

Hi Guys,

I only just got Amibroker on saturday.  I've been looking for an indicator that plots a trailing stop loss a certain percent below.  I found this thread http://www.traderji.com/metastock/4399-trailing-stoploss-indicator.html but cant seem to get it to work in AB.  Is this possibly an old obsolete code or am I just importing it wrong?  I've obviously got a lot to learn.  Also can someone give me a link to a good site/forum/document so I cant get a better idea of using Amibroker itself and AFL.

Regards,

John


----------



## kaveman (19 December 2005)

As the link suggests it is for Metastock
You would have to re-write it for amibroker


----------



## markrmau (19 December 2005)

From memory, AB has a trailing stop built in, so you don't need specific code. Just look at the "ApplyStop" function.

Also, AFL link:

http://www.amibroker.com/guide/h_understandafl.html


----------



## captain black (19 December 2005)

The Amibroker support page is the best place to start.
Has links to the online library, mailing list(s),help documentation, AFL reference guide etc.

As with learning anything new it's better to "know less" and "understand more". Start with the basic concepts first. There is a downloadable mailing list history in the 3rd party area of Amibroker, it's probably the best resource, although searching it can be daunting.

And there's always the helpful crew here, we'll have a go at any questions you have. I don't speak "metastock" so can't help with the trailing stop loss, can anyone else convert it to AFL ?

Cheers,
           The Captain


----------



## The Estimator (20 December 2005)

Thanks Guys,

Now wonder the code didn't work.  I thought it looked a bit foreign compared to the others.  I found it through a search on google and all the pages I'd read before were for amibroker.  I guess I got myself in the mindset that that was what I was looking at.  I'll have to check out those links on the weekend.  Thanks for the responses.  I'm sure once I get a bit more versed in the program I'll have more questions.

John


----------



## captain black (20 December 2005)

Had another look at the MS code for the trailing stop and put together some AFL that looks like it will do the same job. Copy and paste into Formula Editor then click on "Apply Indicator". Will plot the trailing stop as a red line. Drag and drop a price chart on top. Can adjust lookback period and percentage stop by right clicking chart and selecting "parameters".

Code
--------------
lookback=param("lookback",20,1,20,1);
percent=param("percent",7,1,10,1);

stop=hhv(close,lookback);
sellstop=stop-(stop*(stop/100));

Plot(sellstop,"sellstop display",colorred,styleline);

---------------------

Cheers,
           The Captain


----------

