Articles on MQL4
Some Ways to Build Channels

Some Ways to Build Channels


for example, forex

A lot of traders use extremums within some definite period of time to create a trading strategy. The most famous ones are Turtles trading system and Price channel. We will consider now how such channels may be created with the help of function iHighest() and iLowest() . Usually such a channel is called PriceChannel, let it be the name of our indicator. Our indicator will show current levels of highs and lows within N period of bars in the shape of lines. Let's call the «Advisors creation wizard» and complete the required fields.

Pic. 1
Pic. 1

In this case I have chosen value 20. This period was used in the Turtles system to trade on breakouts.

Pic. 2
Pic. 2

As we should see the channel levels the indicator will be drawn on the price chart. One line will show the high and the second one – the low.

Pic. 3
Pic. 3

I have completed the code a bit for better understanding and usage. The only thing left is to write the code of buffers filling out with values.

Pic. 4
Pic. 4

Functions iHighest() and iLowest() have replaced the out-dated functions Highest() and Lowest(). The code is very simple, let's compile it and attach it to the chart.

Pic. 5
Pic. 5

In the DataWindow we can see values of any buffer of the indicator for the required date. The only drawback of this indicator (from my point of view) is that there is no visual confirmation of breakout of 20-day range. To correct this drawback we should change the code of the indicator a bit and name it PriceChannel-2.mq4.

Pic. 6
Pic. 6

The new version of the indicator is more vivid.

Pic. 7
Pic. 7

The difference between the two versions is obvious when we compare them.

Pic. 8
Pic. 8

There are a lot of strategies based on breakout of some range.

Pic. 9
Pic. 9

Moreover, trend and counter-trend, based on false breakouts. The drawback of this indicator is the fixed period within which extremums are looked for. There are different ways to adapt indicators of this type for the current market situation. It would be interesting if in the flat period (consolidation) the period of our indicator increased and decreased with the trend developing. Thus, we would be a bit guaranteed against flat false breakout and early exit from the position.

Indicator ADX() usage is one of such methods. 14-day value is popular for this period. You can notice that in flat its values are small and during a trend they may overcome 40.

Pic. 10
Pic. 10

- Value 150/ADX(14) is used as a variable period for indicator PriceChannel. Let's change the code of our indicator and name it as ADXChannell.mq4.

Pic. 11
Pic. 11

The nature of the price channel has changed.

Pic. 12
Pic. 12

We can make some rules of positions opening by the trend when price touches the opposite side of the channel.
We have considered only indicators drawing two lines, the channel edges. Sometimes traders add the third line, which is in the mid between the upper and lower edges of the channel. Let's name it the waterline or zero line (or balance line). Let's make the third version of the indicator, PriceChannel3.mq4. We should only add the third buffer and a code to calculate its values.

Pic. 13
Pic. 13

Let's drop the indicator to the chart.

Pic. 14
Pic. 14

In this case we have calculated the middle line of the channel on the basis of its edges. There are indicators built differently: some line is taken (e.g. some moving average) and the edges of the channel are built on its basis following some rules.

Besides usual averages some difficult algorithms may be used as the mid line, e.g. Kaufman's Adaptive Moving Average, AMA. This indicator is quite familiar to traders. That's why I have decided to take another indicator, FRAMA, as an example. This is not a classical variant of the code, it may be written differently.

The mid line PriceChannel and FRAMA may be compared.

Pic. 15
Pic. 15

The only advantage is that FRAMA movement is more smooth compared to the mid line PriceChannel. Let's try to build a channel from FRAMA. For this we need a rule following which we will specify the edges of the channel on FRAMA. I think Close price deviation from FRAMA should be used. That is, standard deviation of this distribution.

So, we have the following: 1. FRAMA indicator value, which we will show 2. Close price deviation from FRAMA, which we will not show 3. the upper edge of the channel, which will be shown 4. the lower edge of the channel, which will be shown.
It means that our indicator should depict (draw) three buffers and have one hidden (assisting) buffer for calculation. It is possible in MT4, though you should remember that invisible buffers should be the last ones (have the maximum index).

Pic. 16
Pic. 16

To build the edges of the channel at first we should count FRAMA values and deviations, only then in a separate cycle we can calculate the channel edges.

Pic. 17
Pic. 17

As an example I used one of the functions, calculated on the array of values, iStdDevOnArray(). This indicator with values by default looks the following way.

Pic. 18
Pic. 18

The indicators are here .

+7 (495) 710-76-76
© 1998—2008 «Alpari»

close

Your Personal Area

For alpari.classic enter your account number (a letter and 4 figures) and the code word for the Personal Area.

For alpari.micro account: enter your login (6 figures) and the password for MT.

Open an account!Forgotten your password?