I spent a bit of time over the weekend playing around with AmiBroker's formula language and have created some stop/loss plots. I've done one using ATR (Average True Range) and another using Guppy's count back.
These are not just basic plots as they have to start from a particular purchase date and only ever go up from there. Consequently, the actual purchase date has to be available somewhere. AmiBroker's portfolio manager doesn't link to the formula language (that I've seen), so I had to create a folder of files to enter the purchase dates into. Currently these would have to be manually entered at each purchase. The files also include the parameters for the ATR and count back plots, so can be customised separately for each stock, plus there's a dynamic parameter feature where they can then be adjusted on the fly.
Here are a few charts showing plots from selected dates (picked simply for display purposes). The default options I've used are 2 times 14 period ATR or 3 times 21 period ATR (as recommended by Leon Wilson), and a count back of two steps (the standard Guppy method).
This first plot is GUD weekly with a purchase date of 5/10/2001. The blue triangles on the date line indicate the purchase date and the blue down-arrows indicate prices crossing below the stop line, giving a sell signal. The stop line is only relevant after the purchase date, so ignore the fact it sometimes goes down before that. Given that the GUD trend continued up for the whole period, I think this would imply that the stops are too close to the price action for a long term hold.
Cheers,
GP
GreatPig
6th-September-2004, 10:42 PM
Here are the same plots but this time using a count back of 3 steps and 3 times 21 period ATR. No sell signals have been indicated here.
GP
GreatPig
6th-September-2004, 10:46 PM
And a shorter term daily plot for BSL over the last couple of months. The count back method gave two sell signals during this period, while the ATR method only gave one (although was border-line on the other one).
GP
badr2015
7th-June-2006, 04:15 AM
hi
Just looking for some tips on setting contingent buy orders once you get a buy signal so as not to chase prices too high.
raven4ns
4th-December-2008, 01:04 PM
Hi GP,
I know this thread is old but I thought this might help some people. The enclosed url will take you to a page about Volatility Stops. He tested them on about 100 of his trades against 2 other methods and the conclusion is interesting. Here is the url
http://thepatternsite.com/stops.html#WIU
Regards,
Tim
pavilion103
18th-February-2011, 07:14 PM
Does anyone have a code for this?
I want to use an ATR trailing stop (of multiple of ATR) that only goes up, as with the first post in this thread.
I have no idea how to create this code. Any help would be appreciated
Wysiwyg
18th-February-2011, 08:52 PM
Great Pig created these AFL's so all credit to him. The ATR trailer works fine if you do mean plot. Search function keywords are an option too.
How do I create this now? Is just a matter of creating my own indicator?
Thanks,
Matt
pavilion103
18th-February-2011, 10:14 PM
I tried it under the Formula heading and then tried to apply it as an indicator and this came up. Do you know what I'm doing wrong?
41467
Wysiwyg
18th-February-2011, 10:42 PM
I tried it under the Formula heading and then tried to apply it as an indicator and this came up. Do you know what I'm doing wrong?
41467
No mate. It is a plot which means you plot it on a chart. Exempli gratia 3*ATR(14)... (thanks Yoe)
pavilion103
19th-February-2011, 10:30 AM
No mate. It is a plot which means you plot it on a chart. Exempli gratia 3*ATR(14)... (thanks Yoe)
OK. I am a little confused. I apologise for my ignorance but I am not sure how to code this. I have gone through the help on Amibroker and am new to it. I've managed to get some codes working but am not sure how to implement this one.
Now I'm not sure how to implement this. Am I supposed to create the stop first? Why is the buy and sell there (is that only for backtesting)?
All I want to do it plot the 2.5*ATR on the chart but am not sure how to.
Are you (or someone else who knows) able to give me a step by step proceedure for this? It would be much appreciated.
Thanks,
Matt:)
pavilion103
19th-February-2011, 11:58 AM
It also mentions 'array not initialised' which I don't understand. I've been going through the help section most of this morning but am completely stuck!
Wysiwyg
19th-February-2011, 01:45 PM
This is the code I got from the other thread:
That is not the complete formula. When you click on the .zip for GP_ATRStop.afl the whole formula is there. For the ATRStop to work you need to load the .dll into plug-ins. I don't know if the trial version will allow plug-ins.
Alternatively go to Wise Stock Trader (http://www.wisestocktrader.com/indicators/578-atr-stop-loss-system) and search for ATR formulas to get another version.
pavilion103
24th-February-2011, 09:07 PM
I would also like the know the code to create an indicator that is on the same chart as the price and the price + the ATR or the price - the ATR.
What is the code for each of these?
pavilion103
25th-February-2011, 09:14 PM
That is not the complete formula. When you click on the .zip for GP_ATRStop.afl the whole formula is there. For the ATRStop to work you need to load the .dll into plug-ins. I don't know if the trial version will allow plug-ins.
Alternatively go to Wise Stock Trader (http://www.wisestocktrader.com/indicators/578-atr-stop-loss-system) and search for ATR formulas to get another version.
Where in Amibroker do I enter this code? I am completely new to it and don't understand what screens to load up to enter this code and what file type to save it as?
Any help would be greatly appreciated.
Thanks,
Matt :)
pavilion103
25th-February-2011, 09:33 PM
OK I created an indicator with that code and got the following result:
41581
I have a couple of questions.
1. Why doesn't the ATR trail move up every day that the price moves up? (for example above where I drew the purple line)
2. How do I change the buy and sell signals? (e.g. where I drew the green circle)
3. It is possible for me to simply enter a buy date manually that it can start the trailing stop from?
Thanks,
Matt :)
Wysiwyg
25th-February-2011, 09:55 PM
I have a couple of questions.
1. Why doesn't the ATR trail move up every day that the price moves up? (for example above where I drew the purple line)
This the formula how an ATR is created using a true range (TR). (thanks to chart school (http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:aver age_true_range_a) definition)
Current ATR = [(Prior ATR x 9) + Current TR] / 10
- Multiply the previous 10-day ATR by 9.
- Add the most recent day's TR value.
- Divide the total by 10
2. How do I change the buy and sell signals? (e.g. where I drew the green circle) Change the ATR period or ATR multiple in "Parameters" by clicking on the slider beside them.
3. It is possible for me to simply enter a buy date manually that it can start the trailing stop from? The ATR plot will be whatever you set it at no matter when you buy your shares.
pavilion103
25th-February-2011, 10:36 PM
Thank you for your help. I am trying to work my way through this but my understanding is still limited.
41586
I tried to change the "buy" as you can see by the code boxed in red. I wanted to enter on the highest bar of the previous 10 bars.
1. Why are there no entry signals coming up? How do I create entry signals to for the highest bar of the previous 10 bars
2. Why is trailing line the same as the one I previously posted but without the buy and sell signals?
Thanks,
Matt
Wysiwyg
25th-February-2011, 11:44 PM
Thank you for your help. I am trying to work my way through this but my understanding is still limited.
41586
I tried to change the "buy" as you can see by the code boxed in red. I wanted to enter on the highest bar of the previous 10 bars.
1. Why are there no entry signals coming up? How do I create entry signals to for the highest bar of the previous 10 bars
Thanks,
Matt
Click on edit and copy/paste this code at the bottom of the formula. Cick X in top right hand corner to exit and when prompted to save changes to Amibroker formula click yes. Double click on same formula in it's holding folder and the chart will appear with the 10 day high shapes. The "Exploration" in Automatic Analysis helps to find the most recent stocks by setting the "Range" to 24-Feb-2011 to 25-Feb-2011 and then click "Explore".
Note thinly traded and penny stocks do this often so you can add another filter such as MA(C*V, 50) > 50000.
Breakout = C >= HHV(H,10);
PlotShapes(shapeHollowUpTriangle*Breakout,colorBlu e, 0, L, Offset = -20);
1. Why doesn't the ATR trail move up every day that the price moves up? (for example above where I drew the purple line)
Thanks,
Matt :)
Okay I see what you mean now. It is hhv/llv based and not ATR.
This one adjusts every bar.
pavilion103
26th-February-2011, 09:48 AM
Ok this is starting to become a bit clearer. Thanks for the help.
I have some more questions in relation to the chart below:
41601
1. Why is there no signal for the bars which I have circled in green? These would represent the highest high of the previous 10 days. It doens't appear that there is any AND in the formula so shouldn't they be showing up?
2. I have saved this code into Formula Editor and saved it as an indicator. How do I create an AFL file where I can run a scan of all stocks to get entry signals for the highest high of the last 10 days? I haven't created any AFL files before so am not sure how to do this.
Thanks
pavilion103
26th-February-2011, 10:05 AM
One minor thing that I noticed in that code which you gave me is that the ATR dips back down at times. I circled part of the chart below where this occurs. In the previous ones I posted that line went up in a step type shape (where it never goes back down, only rises). Is it possible to change it to that step type shape?
41602
Thanks
pavilion103
27th-February-2011, 10:06 PM
I've had a play around with the AFL codes and a bit of the explorations which is making some more sense.
I still can't get the trailing ATR to change to a "step" pattern. Does anyone know how to do this? I've searched through the formula without any luck!!
I can change the line from "thick" to "staircase" but it still comes down slightly when I want it to always be going up and never coming down.
Wysiwyg
27th-February-2011, 10:25 PM
In the previous ones I posted that line went up in a step type shape (where it never goes back down, only rises). Is it possible to change it to that step type shape?
Well we can go back to GP's Trailing Stop Plot. The first pic. is of the 14 period * 6 ATR adjusting per bar. The second pic. is after double clicking on a great hindsight entry place. This bar could be any bar including present time that a trade is entered and will not retreat from your buy in price.
pavilion103
28th-February-2011, 07:46 PM
I guess I'm not really understanding what each of those trails are exactly.
1. I'm not sure why the one that doesn't stay flat retraces slightly, but never by much. Do you know why it does this even on up days?
2. Maybe I am misunderstanding you, but do you have a code for one that moves up everyday but never goes down? I only have ones that move up and then retrace slightly and ones that don't move up every day but remain flat (like the one at the start of this thread)
Wysiwyg
28th-February-2011, 08:11 PM
I guess I'm not really understanding what each of those trails are exactly.
1. I'm not sure why the one that doesn't stay flat retraces slightly, but never by much. Do you know why it does this even on up days?
That one from WiseStock uses HHV and LLV to plot the line and will change as these values change.
2. Maybe I am misunderstanding you, but do you have a code for one that moves up everyday but never goes down? I only have ones that move up and then retrace slightly and ones that don't move up every day but remain flat (like the one at the start of this thread)
The idea of a trailing stop is to only move in the direction of the trade. So as the GPStop Plot does (when your chosen price is clicked) only moves up when the price moves up and will remain horizontal until previous highs (for long) or lows (for shorts) are exceeded.
I do not have any other trailing stop plot that works as perfectly as the GP Trailing Stop Plot.
pavilion103
1st-March-2011, 11:44 AM
Thanks mate, really appreciate the help. You're a gun.
pavilion103
1st-March-2011, 07:13 PM
Another question, a bit off topic.
How do I create a "filter" for an exploration for the highest close value of the previous 20 days?
Is it simply, C== HHV (C,20)
or does this include the Highest High in 20 days rather than highest close ?
Thanks,
Matt
AlterEgo
2nd-March-2011, 01:08 AM
Another question, a bit off topic.
How do I create a "filter" for an exploration for the highest close value of the previous 20 days?
Is it simply, C== HHV (C,20)
or does this include the Highest High in 20 days rather than highest close ?
Thanks,
Matt
No, only uses the highest value of the close, not the high.
pavilion103
9th-March-2011, 08:05 PM
I have a trailing stop loss plotted on my chart. I also have one on a chart below and I click on a certain point and it trails it from the point I clicked it on. Is it possible to lock it on set date for one company and another date for another company
For example if my current trailing ATR stop is at the red point in this chart for this company. Can I keep it so that this remains the same, but for another company I had a stop trailing from the purple point? So I don't have to go back and keep clicking on the day that it trailed from?