Download MetaTrader 5

Layman's Notes: ZigZag…

29 July 2008, 08:32
Alexei Kharchenko
4 145


Surely, a fey thought to trade closely to extremums has visited every apprentice trader when he/she saw "enigmatic" polyline for the first time. It's so simple, indeed. Here is the maximum. And there is the minimum. A beautiful picture on the history. And what is in practice? A ray is drawn. It should seem, that is it, the peak! It is time to sell. And now we go down. But hell no! The price is treacherously moving upwards. Haw! It's a trifle, not an indicator. And you throw it out!

Again and again, we come back to the ZigZag indicator after having read some intelligent books about Elliot's wave theory, Fibo levels, Gartley's patterns, etc. An endless circle. An infinite subject to discuss.

The ZigZag indicator is a polyline that consequently joins the peaks and troughs on a price chart. In such a manner, we display the path the price has "followed" with the course of time. This brings up a question now...What are these peaks and troughs?

The article contains the following:
- the description of ZigZag;
- the description of a method to find price models "Peak" and "Trough";
- the definition of potential reverse points;
- the revelation of the indicator's additional features.

What Is ZigZag?

I think, only few ones are surprised with the modern representation of the price chart as a bar. A time length is cut from the ticks history. The enter (Open) and exit (Close) prices, the maximal (High) and minimal (Low) values are fixed. But we can say nothing about the intrabar movement, about its direction at the exit... There is not enough information to make a trade decision. Additional tools are necessary for market analysis.

It is another pair of shoes, when the matter is the ZigZag polyline... We know the level and the approximate time of the last movement start, its direction. On the basis of statistical data processing (peaks and troughs), the possibility of forecasting the probable level and probable reverse time appears... There is enough information to make a "proper" trade decision.

It is important to understand that the current quotes are used for ZigZag drawing. It doesn't use any "quackery" and nor it adds anything to what already exists. The ZigZag is one of the methods of representing a price chart in a more compact form.

What quotes are usually used for ZigZag drawing? High and Low. That is the answer. But we can draw a polyline using only the open or only the close price of the bar (in my opinion, these are most preferable variants, because we know the event time for sure).

How Can We Identify Peaks and Troughs?

Let's remember the definition of a fractal, before we answer this question. Let me quote some phrases from New Trading Dimensions by Bill Williams:

"The fractal pattern is a simple one. The market makes a move in one direction or the other. After a period of time, all the willing buyer, have bought (on an up move) and the market falls back because of a lack of buyers. Then some new incoming information (Chaos) begins to affect the traders. There is an influx of new buying, and the market, finding that place of equal disagreement on value and agreement on price, moves up. If the momentum and the buyers' strength are strong enough to exceed the immediately preceding up fractal, we would place an order to buy one tick over the high of the fractal."

In practice, it is applicable to ZigZag. We search for the new models of Peaks and Troughs during its composing. How can we find them? And here comes a quote again:

“The technical definition of a fractal is: a series of a minimum of five consecutive bars where the highest high is preceded by two lower highs and is followed by two lower highs. (The opposite configuration would be applicable to a sell fractal.)”.

The technical definition of the Peak price model is: a series of N number of consecutive bars, the ExtDepth of bars and CheckBar bars with lower maximums after it are located before the highest maximum in it. (The opposite configuration corresponds the Trough price model). Obtained price model is compared with the last known model for the observance of the ZigZag's main rule: the consecutive alternation of models.

ExtDepth and CheckBar are the names of the parameters used in the ZigZagTF indicator.

The above mentioned algorithm is entirely implemented. Two buffers are used to write the extremums.

Reverse Points

The only parameter ExtDepth is used in the standard ZigZag implementation. CheckBar=0, i.e. the extremum is to be searched on the current bar. This is the reason for the permanent refreshing and redrawing of the last ray. “This ability to correct its values by the following price changes makes Zigzag a perfect tool for analyzing price changes that have already happened. Therefore, you should not try to create a trade system basing on the Zigzag. It is more suitable for analyzing historical data than for making prognoses." (The citation of standard ZigZag developers). It is hard to disagree.

Let's refer to the fractal again. The models of fractal alternate on the price chart, i.e. the fractal of Buying is changed with the Selling fractal and vice versa. But there are some regions on the chart, where fractals do not alternate and the same fractal model occurs again. Usually, it's repeated 2-3 times.

ExtDepth = 2, CheckBar = 2.

Let's try to imitate the working of Fractals indicator (a modification of the standard indicator without redrawing of the last fractal) using our ZigZagTF indicator. The ExtDepth and CheckBar parameters are equal to 2. For a new ray of ZigZag to arise the confirmation of the extremum by two bars is necessary. As soon as the ray appeared on the third bar, we will obtain the potential reverse point. The renewing of the ray is possible but not so often as in the standard ZigZag indicator.

Now the ZigZag indicator became more usable for the creation of a trade strategy.

The Indicator Features

The implementation of possibility of using different price properties for ZigZag composition was already mentioned above.
Price Parameters:
0 – High and Low;
1 – bar's open price (Open);
2 – bar's minimum (Low);
3 – bar's maximum (High);
4 – bar's close price (Close).

ZigZag is drawn by the close prices. ExtDepth = 2, CheckBar = 2.

The situation, when the more accurate information is necessary for drawing the ZigZag, may happen. For example, when both extremums are found on a bar, it is so called external bar. How should we correctly draw the polyline, in this case? The possibility of using smaller timeframes is implemented.
The TimeFrame parameter: 0 – the current timeframe.

The Zzcolor and Zzwidth parameters change the color and the width of the ZigZag line, respectively.

It is useful to know the information about the level of extremum possible appearance, especially when a new ray has not been drawn yet, when there is no confirmation signal (CheckBar parameter), and the level of extremum appearance is broken through.
The Levels parameter – enables disables the drawing of levels.
The Lcolor and Hcolor parameters change the color of the lower and the higher level, respectively.

The levels of new extremum appearance

There is a possibility of writing all points of the ZigZag's polyline after it's drawn into a file. The file is at the: client_terminal_root_directory\experts\files folder. The writing of found points: bar number, type of the point, price.
The Record parameter – enables writing of the reverse points into the file.

And the last function that is frequently used in trading is the connection of Fibo levels. The Fibo1 and Fibo2 parameters allow to enable/disable the Fibo levels on the last and the next to the last ray, respectively. We choose the necessary color by the FiboColor1 and FiboColor2 parameters.


In this article, I have compared the Fractal and the ZigZag indicators. It appeared that the Fractal model was a particular case. We can also remember the Gann's indicators: the small trend, the intermediate trend, and the main trend. They are the particular cases of the ZigZag, as well.

Maybe it is the first time when the ZigZag is defined as the consecutive alternation of the Peak-and-Trough price models, the technical method of finding them on the price chart.

Now the work is over. Worthful community obtained a convenient tool for trading and market analysis. Luck and profits to everyone!

Translated from Russian by MetaQuotes Software Corp.
Original article:

Translated from Russian by MetaQuotes Software Corp.
Original article:

Attached files |
ZigZagTF.mq4 (19.41 KB)
Last comments | Go to discussion (8)
MQL4 Comments
MQL4 Comments | 19 Feb 2009 at 07:05

Great indicator, thanks! ps for those using this the first time, it took a minute or so for the fib1 and fib2

to show up during which time the zig zag line disappeared. Be patient!

MQL4 Comments
MQL4 Comments | 12 Oct 2009 at 23:28

Very Interesting, I'm trying to build an ea based on zigzag indicator and I show you the result of backtesting from may 2008 till now.

No bad isn't it?

blueeagle | 17 Nov 2009 at 10:09

Very Interesting, I'm trying to build an ea based on zigzag indicator and I show you the result of backtesting from may 2008 till now.

No bad isn't it?

Can you share your EA?

Ankit Jain
Ankit Jain | 1 Nov 2012 at 09:01

does it repaints like the normal zig zag??

Ankit Jain
Ankit Jain | 1 Nov 2012 at 09:13
unable to use it..not adding or showing on graph..
Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

Working with currency baskets in the Forex market Working with currency baskets in the Forex market

The article describes how currency pairs can be divided into groups (baskets), as well as how to obtain data about their status (for example, overbought and oversold) using certain indicators and how to apply this data in trading.

Portfolio trading in MetaTrader 4 Portfolio trading in MetaTrader 4

The article reveals the portfolio trading principles and their application to Forex market. A few simple mathematical portfolio arrangement models are considered. The article contains examples of practical implementation of the portfolio trading in MetaTrader 4: portfolio indicator and Expert Advisor for semi-automated trading. The elements of trading strategies, as well as their advantages and pitfalls are described.