stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

ZigZag is NOT ZigZag!
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1313
Page 1 of 8
Author:  Big Be [ Mon Dec 17, 2012 3:14 am ]
Post subject:  ZigZag is NOT ZigZag!

Researching ZigZag outside of the Empty4 world, you will see that before Empty4, ZigZag was designed in a very different way than the ZigZag in Empty4. Empty4's ZigZag is looking for the high and low of the last n bars, with a couple extra rules, as will be explained later. Originally ZigZag looked at price movements up and down. It looks at highs and lows, but with a price move percentage filter. I quote well-written selections from the Stockcharts.com website:

"ZigZag
"Introduction
"The ZigZag feature on SharpCharts is not an indicator per se, but rather a means to filter out smaller price movements. A ZigZag set at 10% would ignore all price movements less than 10%. Only price movements greater than 10% would be shown. Filtering out smaller movements gives chartists the ability to see the forest instead of just trees. It is important to remember that the ZigZag feature has no predictive power because it draws lines base on hindsight. Any predictive power will come from applications such as Elliott Wave, price pattern analysis or indicators. Chartists can also use the ZigZag with retracements feature to identify Fibonacci retracements and projections."

"Calculation
"The parameters box allows chartists to set the sensitivity of the ZigZag feature. A ZigZag with 5 in the parameter box will filter out all movements less than 5%. A ZigZag(10) will filter out movements less than 10%. If a stock traded from a reaction low of 100 to a high of 109 (+9%), there would not be a line because the move was less than 10%. If the stock advanced from a low of 100 to a high of 110 (+10%), there would be a line from 100 to 110. If the stock continued on to 112, this line would extend to 112 (100 to 112). The ZigZag would not reverse until the stock declined 10% or more from its high. From a high of 112, a stock would have to decline 11.2 points (or to a low of 100.8) to warrant another line."
QQQ ZigZag.png
The webpage has more info and example charts:
http://stockcharts.com/school/doku.php? ... ors:zigzag

Sometimes the above principle is called a retracement indicator, and sometimes Fibonacci is mentioned. The original concept is a retracement indicator with a settable percent threshold. The Fibo levels are not a core requirement. And yes it repaints. Empty4's ZigZag repaints mostly “forwards”, that is it resets as price moves higher and higher or lower and lower. Not certain if the original ZigZag behaves similarly, but I suspect it does.

In Empty4's ZigZag, percentage is NOT looked at.
Instead it looks back for the highest Highs and lowest Lows of the past n bars, called 'ExtDepth' in ZigZag.

There is one technical requirement in Empty4 ZigZag's code. This is what distinguishes ZigZag from just a Highs and Lows indicator: To have a lower High, there must be an intervening Low. That is, High – Low – lower High. And to have a higher Low, there must be an intervening High: Low – High -- higher Low. And each High [Low] must “qualify”, it must be the highest [lowest] of the past 'ExtDepth' number of bars. You can see all this if you study it on a chart.

This image shows two examples of lower Highs with intervening Lows (ExtDepth = 12):
zz%20.gif
In Empty4, most ZigZag derived indicators rely on the ZigZag built into Empty4, so incorporate this different concept called "ZigZag".
These include such indicators as “GP Lauer”, “3_Level_ZZ_Semafor_TRO_MODIFIED_VERSION”, a useful version MrPip and I modified called “3_Level_ZZ_Corrected_V2.1”, various "Semaphore" versions we have put out, and others.

Big Be
Author:  Big Be [ Mon Dec 17, 2012 3:19 am ]
Post subject:  The Bugs Built into ZigZag, and ZigZag_Corrected

ZigZag's code is one of the most incomprehensible piles of Empty4 I have ever studied.

However I can tell you with full certainty that ZigZag has two bugs built in:

1. ExtDeviation does nothing
You can test ExtDeviation by putting in any number: Try 0. Try 10,000. No change in the chart.

2. When ExtDeviation is fixed, it does not adjust for 5 Digits brokers (Digits = decimal places).
So the exact same data on a 4 Digits broker will give a different ZigZag plot than on a 5 Digits broker. ZigZag was coded before 5 digit brokers existed.

What ExtDeviation is supposed to do:
Imagine a “double top” chart. Now imagine the second top is ONE pip less that the first top. As a trader, you would call that a second top. ZigZag with this bug may IGNORE the second high (chart middle).
zz 2.gif
In this image the second High is one pip below the first. ZigZag ignores it even though it is the actual turning point of the trend.

ExtDeviation is supposed to allow for “Close is good enough” in this type of situation. It should allow you to adjust the number of pips of tolerance. So if set to 5, it should recognize a high that is within 5 pips of the last high. The optimum number of Pips varies with time frame. It also probably varies, to a much lesser extent, with the average volatility range of the pair.

I give you ZigZag_Corrected (light blue line):
zz 3.gif
With the above two bugs corrected, it now picks up the second slightly lower High, which is where the new trend starts.

For ExtDeviation (Pips tolerance) here are a couple time frame settings that work pretty well:

M5: 2.0
H1: 5.0 (used for blue line in chart above)
D1: 30.0

These may be modified a little for the volatility of the currency pair being used.

ZigZag_Corrected is set to match the original ZigZag defaults in Empty4. These are not really very useful settings. To match the indicators exactly set ExtDeviation to 0, in ZigZag_Corrected.

This gives a starting point for ZigZag use without bugs. Any indicator or EA that calls ZigZag would need the name changed in iCustom() from “ZigZag” to “ZigZag_Corrected_v3.2”. Of course the ExtDeviation setting will need to be set appropriately.


Big Be
Author:  Big Be [ Mon Dec 17, 2012 3:20 am ]
Post subject:  ZigZag_Corrected Settings

The default settings match the plot of the original Empty4 ZigZag, except for ExtDeviation, which would have to be set to '0' to match exactly. However we have not found much use for those settings.

At the nonprofit trader's club, http://www.4XLA.org, we have found certain settings for ZigZag derived indicators, especially Semaphores, to be useful.

I.
Lengths or ExtDepths of 34 and 69.

II.
ExtBackstep is apparently the number of previous Highs and Lows that it looks at, searched for up to 100 bars back.

Besides giving somewhat better results, setting ExtBackstep to 1 increases the speed some.

III.
For ExtDeviation (Pips tolerance) here are a couple time frame settings that work pretty well.
This will occasionally give you an extra valid signal. If set too high it will give too many added signals that are not useful.

M5: 2.0
H1: 5.0 (used for blue line in chart above)
D1: 30.0

These may be modified a little for the volatility of the pair being used.


Note: Because it is constantly looking back, ZigZag and ZigZag based indicators run somewhat slowly. They are somewhat CPU intensive.

Big Be
Author:  Big Be [ Mon Dec 17, 2012 3:23 am ]
Post subject:  Better ZigZags?

Is there a true Percent-based ZigZag for Empty4?
I have not written one.

I have found only two candidates:
“ZUP”, on mql4.com, of which I have not been able to understand the percentage aspect. I suspect the code is buggy or incomplete.

And “Percent ZigZag”, which I do not possess, in the Forex-TSD Elite section.
Update March 2014: I have bought and examined “Percent ZigZag”, and it is NOT a true percent-based ZigZag. Sigh.

Notes on coding a true Percent-based ZigZag

In stocks you can use a “percent of stock price”. But “percentage of exchange rate” is not I believe very significant in Forex so a clever substitute should be used.

Here are ideas based on other work I have done:

Perhaps this could look at the high and low of the last six months for Daily charts, the last 10 or 20 days for hourly charts, etc.

Or better, consider multi-period ranges. Maybe the single highest high of the last five days minus the five days' single lowest low. If needed, average with (20 or 40 days' high minus 20 or 40 days' low). This gives you a range to take a percentage of. It would need some tuning but once final should be self-adjusting.

Other time frames would probably need different numbers of periods.


Is there a fast, bug free, superior version of Semaphore available?

Well I have written one but it is not available yet. I hope to offer it through the commercial section soon. Assuming that I get Steve's approval.

Big Be
Author:  jcl [ Mon Dec 17, 2012 12:01 pm ]
Post subject:  Re: ZigZag is NOT ZigZag!

It is known that many Empty4 functions are not what they are supposed to be. For instance, iATR is NOT ATR. Empty4 has many such little surprises to make programmer's life more interesting :).
Author:  Big Be [ Mon Dec 17, 2012 6:28 pm ]
Post subject:  Re: ZigZag is NOT ZigZag!

jcl,
Can you give us a link about ATR vs. iATR?
Author:  SteveHopwood [ Mon Dec 17, 2012 10:12 pm ]
Post subject:  Re: ZigZag is NOT ZigZag!

Great contribution Big Be. Thanks.

:D
Author:  jcl [ Tue Dec 18, 2012 7:42 am ]
Post subject:  Re: ZigZag is NOT ZigZag!

Big Be wrote:jcl,
Can you give us a link about ATR vs. iATR?
I have no link, but you can easily check yourself. The ATR is defined recursively:

ATR(length) = (previousATR * (length-1) + True Range) / length;

this puts more weight on the recent ranges and gives the ATR a smooth appearance, like an EMA. Empty4 however calculates its ATR by just adding all ranges and dividing by the length, like a simple MA:

iATR(length) = sum(True Range) / length;

This returns a very different, more 'shaky' ATR value which is normally, dependent on what you do with it, less suited than the 'real' ATR.
Author:  garyfritz [ Tue Dec 18, 2012 1:46 pm ]
Post subject:  Re: ZigZag is NOT ZigZag!

FWIW, Empty4 isn't the only one to define it as SMA(TrueRange). Tradestation's AvgTrueRange() function uses a simple average too, not an EMA.

But I suspect you're right -- the (PreviousATR*(length-1)+TrueRange)/length is the type of formula Wilder and others used, because it was easy to calculate in those calculate-by-hand days.
Author:  swordfish [ Fri Dec 21, 2012 11:05 pm ]
Post subject:  Re: ZigZag is NOT ZigZag!

Thank you , Big BE.
With this improved Zig Zag, is it possible to code double top/double bottom and head-and-shoulder patterns?
All times are UTC Page 1 of 8