Australian (ASX) Stock Market Forum

Trend Line Plots

GP, if you modified this code to produce a ABC wave (or similar) as described in Nick Radge's recent book (thanks Nick an interesting book), without having to use a zizzag function it would make a useful tool for part of a system. Needing only 3 trend lines it might be a bit simpler. Although I'm not sure if you can use ABC wave as a stand alone function without needing to confirm the 5 part Elliot Wave, can it? anyone?

Apparently zizzag functions skew backtesting results, I don't fully understand why as I've tended to avoid them.


regards
 
Poormantrading,

I haven't read Nick's book yet, so I don't know about this ABC wave thing.

Apparently the zig-zag indicator can look into the future, which will affect backtesting. The way I've done the trend line calculation though doesn't involve any looking into the future (that I'm aware of), so it shouldn't do that.

However, backtesting with the trendline calculation is very slow, as it effectively has to calculate a new trendline for every day in the price array. This is because an existing trendline can change positions if a new low or high point occurs. In fact, a line can even disappear and the previous line become extended to the new point.

Cheers,
GP
 
It can be done fairly efficiently so that it does not affect the processing time too much. It is a matter of calculating the lines at certain key points rather than for every point
 
Ok guys thanks for the replys.

The abc wave as I understand it basically a 3 point reversal patern, that can be represented by looking for the 2 most recent troughs & peaks. Ive attached a simple system that I think represents it or at least one form of it.

I think looking for key reversals or pivot points would do the same ... candlestick patterns perhaps.

Anyway the code also includes setting profit targets, stops etc to determine risk/reward & could form the basis of a system if anyone wants to play with it or comment on it.

At the moment it is best used as an exploration to find the most recent patterns.



Regards
 

Attachments

  • abc wave.txt
    4.3 KB · Views: 72
The problem with using Peak and Trough formula is that Zig Zag is used to define peak and trough.

The last leg of a peak or a trough are dynamic and cannot be seen as complete until the next trough or peak has been completed.

In realtime many peaks and troughs of today will not be tommorow.

In testing patterns can be confirmed complete due to hindsite.

Therefore false indications of a methods reliability will be formed when used.
 
Tech all you have to do is have any signals given at or after the bar that creates the new peak or trough. That is what I do with system using this. It ensures validity, also shows how much error comes in if you use the actual turning points that you see in the history
 
Kave

2 days later the stock can move in the opposite direction to confirmation and the trough or peak then is no longer valid.

Anyway I'm not here to convince people of the dynamics of the last leg.
If your happy with how you use it then thats fine.
 
Tech
Once the price has moved past the reversal value and defined a peak or trough that turning point is fixed. This is exactly the same principle that creates the P&F charts
somehow will se if I can post a chart
this is a zigzag with $1.00 reversal to define the turning points. The red star is located at the bar where the price crosses the reversal price. This then sets that turning point in stone, and only the next point is yet to be defined. Thus when backtesting you only need to define that any signal be after the create bar (star shown circled) and you will then be using the correct zig direction as if that bar was the end of the chart.
zigzag.gif
 
Graham

This chart is still dynamic.
If price fell by another 50% from where it is today then the trough now shown would disappear!!!!!!!
 
No way, you are so wrong. The turning points showing are fixed and will never move.
The star means that the last turning point has been determined because the price rose enough to pass above the reversal level. The only point that can now be determined is a new peak.
The last leg follows the price until a reversal level is reached, then that tp is fixed ad it waits for the next opposite tp be calculated.
zig2.gif


Here is he last leg of the chart. Any movement down past a closing price of $23.05 will create a new peak at the circled bar. Any movement up will just take the last zig leg higher and if the price close higher than $24.05 will just move the goal posts for a new peak level reversal definition. eg price goes to $25.00 then the revcersal to creat a new peak is a fall after that to $24.00

The only item in a zigzag that is not set in stone is the last leg, and this is just waiting for the price to move enough to either create a new turning point, or to define a new goal post for the new turning point.
 
Ah yes now I see where your coming from.

You are correct in that once the % change is in place then the peak or trough is set.

I apologise for falling fowl of not being thourough.
However most fall for the trick of setting the peak or trough before a % swing is achieved locking it in place.

Any move then would be that % lagging.
I've also had the feeling that at the time of an exploration for example the peak or trough shown is "true" at that time and as such will either prove to be true of be taken out.
Knowing this a stop can easily be set below or above the trough or peak and trade early.

Again my apologies .
 
kaveman said:
Thus when backtesting you only need to define that any signal be after the create bar (star shown circled)
Do you mean the very next bar after the create bar? Otherwise, it seems to me that prices are always after a create bar, since until the next create bar, there's no change in line direction.

I do my trendlines a little different, in that I start at the last day and work backwards, using an MA to decide the direction of the most-recent line. Because of that, the most-recent line can suddenly change from up to down or vice-versa if the MA slope changes. This can actually cause the most recent line to disappear completely and the one that was before it to be extended up to the current day (see attached images - the first one takes the select line as being the last day).

Also, the slow part is not calculating the pivot points, but rather fitting the lines to the top and bottom edges of the prices.

Cheers,
GP
 

Attachments

  • GP_Tline1.gif
    GP_Tline1.gif
    7 KB · Views: 233
  • GP_Tline2.gif
    GP_Tline2.gif
    6.7 KB · Views: 232
For an example
You want an entry when the zig is rising and exit when it is falling.
When backtesting you make sure that only the real bars for each leg are used.
I will call the bars where the price crosses the reversal level CreatePeak and CreateTrough. The are definite bars as can be seen on my previous screen shots as the abrs with the stars.
So
buy = CreateTrough;
Sell = CreatePeak;


If you have the trades requiring a rising or falling leg of the zigzag then you can use this in backtesting

ZigRise = barssince(createTrough) < barssince( createPeak );
ZigFall = barssince(createTrough) > barssince( createPeak );

buy = OtherBuyConditions and zigrise;
short = OtherShortconditions and zigfall;

This is the only way you can use the zigzag for backtesting and be certain you are not looking forward
 
kaveman said:
If you have the trades requiring a rising or falling leg of the zigzag then you can use this in backtesting

ZigRise = barssince(createTrough) < barssince( createPeak );
...
buy = OtherBuyConditions and zigrise;
The way I see it, this formula for ZigRise won't always give a point on a rising line. For example, on the day before the next createPeak day, ZigRise will still be true (since createPeak hasn't happened yet) but that bar will ultimately be on a falling line. In fact, for all bars between the actual peak and the createPeak bar, ZigRise will be true, as createTrough will still be the most recent bar of the two.

So with this formula, depending of course on what the OtherBuyConditions are, you could quite easily buy just after the actual peak at the start of the next down line. Perhaps if the OtherBuyConditions included buying on a new high for the preceding 'X' periods, or something like that.

Cheers,
GP
 
HI GP:

the trendline code you created, changes signals and adjusts with time and candles as that is dependent on percent changes and peak/trough.....have your worked on something that minimizes this misleading and autoadjustments?....some signals vanishes over time; is there any way to scape that?

Will be highly benefeited if you hint something....


thanks,

tarmi
 
I have tried with every parameter and possible changes but still many close_above signals vanishes/adjusted over time....i have also tried the kaveman suggestions but still no luck..is it not possible in Amibroker? Is there any possiblity with tradestation or metastock?...pls someone suggest...
 
Every time its mentioned I point out you CANT use ZIGZAG.
People keep telling me you can and Graham keeps popping up telling everyone you can.

BUT
Proof is in the in ability to plot what you want.
The last Peak or Trough will always be dynamic so your trend will alwys be a peak or trough behind and as such will alter from time to time.
Spend long enough stuffing around with it and you'll see exactly what I mean.

Ho hum.
 
Top