Australian (ASX) Stock Market Forum

AmiBroker Plugin for Trailing Stop Plots

Great work dude! What I want to know is, how did I not see this in december :banghead:Im currently doing up a swing trading system for forex. I'll keep you posted how it works with that.
 
I have been using the following code for years for ATR trailing stops. Drag and drop it onto any chart and adjust the parameters.

Code:
// ATR Trailing stop - stevo 2006
// When stop line drops exit is triggered.

multiplier = Param("ATR Multiplier", 2, 0, 10, 0.1);
myATR= multiplier*ATR(10); // calculate ATR
initial=C-myATR; // raw stop - not racheted

stop[ 0 ] = Close[ 0 ];
for( i = 1 ; i < BarCount; i++)
{
 if( Close[ i ] > stop[ i - 1])
{
 temp = Close[ i ] - myATR[ i ];
 if( temp > stop[ i - 1 ] ) stop[ i ] = temp;
 else stop[ i ] = stop[ i - 1 ];
}
 else
 stop[ i ] = initial[ i ];
}

Plot( stop, "ATR Stop", colorRed, styleLine);

To test for an exit signal use;

sell = c < ref( stop, -1);

If you want to plot arrows use;

PlotShapes( IIf( stop< Ref( stop,-1), shapeDownArrow, Null), colorOrange, 0, H);

regards

stevo
 
Milk Man,

If you're going to download it, get the latest version from message #5.

Cheers,
GP
 
Stevo, GP,

Thanks for posting your codes for these stops. Anyone who has played around with either AFL or metamumbojumbo will surely be in awe, as I am. Very elegant.

Cheers
 
Hi All

I'm kind of hoping someone has got a little time to help me out... before I throw my computer through the window :mad:

I have recently got Amibroker, and I'm wanting to put in the Guppy count back line - Great Pig, thanks for this post, it looks exactly like what I'm after, only I'm having a little (actually a large) challenge trying to get it onto amibroker as an indicator.

I have gone into the Charts/Custom area, and can open up the formulas Great Pig wrote, but thats where my capabilities have ended. When I try to use the formula, I just get a blank indicator section that says "ERROR:Formula File not Found or empty". When I go back into the Custom formula area, GP's formula has gone, even though I saved it.

I hope someone can help
Thanks

rubles
 
Rubles,

What are you doing when you say "try to use the formula"? If you can see it in the Charts/Custom list, you should just be able to double-click it and it should then appear as a chart.

GP
 
GP,

I went into the charts/custom list, then created a folder. Went to edit, went into the formula (at this stage blank) then opened up your formulas. Then, clicked on save, went out of the edit area. Tried to double click so it appeared as an indicator, then I get a blank indicator section that says "ERROR:Formula File not Found or empty". When I go back into the Custom formula area, click on the newly created file and then edit to have a look, the formula is no longer there.

thanks
rubles
 
Sorry, but I'm not familiar with adding AFL files that way.

All I do is use Windows Explorer to copy the file directly into the Formulas\Custom folder under where AmiBroker is installed. Can you try that?

GP
 
Thanks Great Pig, I appreciate your help.

It seems the way I was trying to do it is not the way it is done, evenutally I tried what you just mentioned and that worked - there are still errors, but I've been looking around just now on the 'net and it seems that perhaps the lines are "wrapped".

So, I'll fix that up tonight and see if the error goes away.

Thanks for your help
Cheers

rubles
 
Updated version of the stops DLL.

Cheers,
GP

PS: the attachment is a ZIP file that I've appended .XLS to so I can upload it. Could a moderator please change it back to a ZIP file by removing the .XLS extension.
 

Attachments

  • GP_Stops_v2.2.zip.xls
    55.2 KB · Views: 291
GP,
got this error when I tried to Apply the Indicator.
The GP_Stops.dll is in the C:\Program Files\AmiBroker\Plugins folder.

I checked the file permissions but they are ok. Did I miss something ?
 

Attachments

  • error.JPG
    error.JPG
    12.3 KB · Views: 570
Sorry, the AFL files are set to read-only, something that my revision control system does. For some reason AmiBroker always gives that error when trying to load a read-only AFL file (don't ask me why it needs to write to the file).

Anyway, select all the AFL files and then go into the Properties dialog and uncheck the Read-Only checkbox.

Despite that error though, the indicator should still load and work.

Cheers,
GP
 
Sorry, the AFL files are set to read-only, something that my revision control system does. For some reason AmiBroker always gives that error when trying to load a read-only AFL file (don't ask me why it needs to write to the file).

Anyway, select all the AFL files and then go into the Properties dialog and uncheck the Read-Only checkbox.

Despite that error though, the indicator should still load and work.

Cheers,
GP

that fixed it. thanx. How would I go about plumbing this into an existing system so that I can use it for exit ?
 
Here's some sample code for a very simple system using a 30/60 day EMA crossover to buy and a 20 step countback line trailing stop (intended as a longer-term system). It does the following:

- Creates an auto-resetting trailing stop from the countback line data.
- Creates the buy array from the EMA crossover.
- Creates the sell array using the trailing stop.
- Removes redundant buy & sell signals.
- Masks the stop line data so it will only plot between buys & sells.
- Plots the results.

Code:
cback = Param("Countback?", 20, 1, 100, 1);

GraphXSpace = 10;
Plot(Close, "Price", -1, styleCandle);

e30 = EMA(Close, 30);
e60 = EMA(Close, 60);

cblLine = GP_CountBack(cback, True);
Stop = GP_CreateStop(cblLine, Close, Null, Null, "", -1, -1, True);

Buy = Cross(e30, e60);
Sell = Stop < Ref(Stop, -1);

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Stop = IIf(Flip(Buy, Ref(Sell,-1)), Stop, Null);

Plot(e30, "EMA(30)", colorRed, styleLine);
Plot(e60, "EMA(60)", colorGreen, styleLine);
Plot(Stop, "Stop", colorBlue, styleLine | styleThick | styleDots);

PlotShapes(IIf(Buy, shapeUpTriangle, shapeNone), colorBlue, 0, Low, -30);
PlotShapes(IIf(Sell, shapeDownTriangle, shapeNone), colorBlue, 0, Low, 30);

If you want your own other sell conditions as well, OR them together:

Sell = <my sell conditions> || Stop < Ref(Stop, -1);

And if you want short versions, set the final function parameters to False instead of True.

For backtesting, add some position sizing, liquidity & other filters, etc. Just tried that myself using this simple system and did a few Monte Carlo runs. Results weren't too bad - better than the random system I played with.

Hope this helps.

Cheers,
GP
 
Some quick backtest results for this system using a 100-pass Monte Carlo run over (nearly) all current stocks. Other conditions were:

- Initial capital = $200K
- Position Size = fixed $20K, subject to volume limiting
- Volume < 10% of 100 day EMA
- Volume < 20% of buy day volume
- Unlimited open positions
- Minimum purchase = $5K
- Maximum purchase = $100K
- 100 day volume EMA times buy price >= $50K
- Buy on high, sell on low
- $30 commission
- Random position score
- 1/1/1997 to 31/12/2006

Max Profit: $2,278,361 (28.6% pa)
Min Profit: $211,096 (7.5% pa)
Average Profit: $1,132,707 (20.9% pa)
Median Profit: $855,123 (18.1% pa)
Profit StdDev: $610,485 (15% pa)

Average MaxDD: -28.9%
Median MaxDD: -27.6%

Results were somewhat better if changed to buy/sell on close (average profit 26.9% pa and median profit 27.8% pa). If nothing else, perhaps a good starting point as an introduction to developing a longer-term system.

Cheers,
GP
 
Just AmiBroker using random position score and randomly rejecting a certain percentage of buy signals.

Cheers,
GP
 
I can't seem to do anything with this file except opening it in Excel. Can anyone tell me how to access the dll file and AFL files.
 
Top