Download MetaTrader 5

Theoretical Basis of Building Cluster Indicators for FOREX

13 July 2007, 14:04
Simeon Semenych
12
12 264

Introduction

Any financial instrument that is traded on the market is a position of some active towards some currency. FOREX differs from other markets only in the fact, that another currency is used as an active. As a result in the FOREX market we always deal with the correlation of two currencies, called currency pairs.

The project that started more than a year ago, helped to develop a group of indicators under a joint name cluster indicators. Their task was to divide currency pairs into separate currencies. Since then indicators were changed several times. Moreover, the interest of users and active discussions in forums allowed to develop methods of working with indicators and create trade systems based on them.


Operation Features of Cluster Indicators

The first distinctive feature of cluster indicators is in the fact, that for the operation they simultaneously need quotes of a certain group of currency pairs. The indicators can work with a separate currency pair, but in the author's opinion it is useless in practice. The advantage of indicators is exactly in the ability to analyse a large amount of currency pairs, dividing them into separate currencies. The more pairs they analyse, the more precise is the provided information.

In order to view fluctuation of three currencies, for example EUR, USD, GPB, we need quotes of three currency pairs: EURUSD, GBPUSD and EURGBP. And if you want to add for example JPY, you need quotes of GBPGPY, USDJPY, EURJPY - totally 6 currency pairs, where each currency has three relations with other currencies. Graphically it can be presented as a square with currencies on its angles, the relations (sides and diagonals of the square) between the currencies denote currency pairs. From each angle of the square a line will be drawn to all other angles. This self-contained net was called a cluster. It explains the name - cluster indicators.

As a rule, in the trading terminal MetaTrader 4 indicators are shown in a separate subwindow under a price chart and their form depends on the currency pair examined. In their turn cluster indicators look like the same everywhere, no matter to what chart they are connected. This is the second distinguishing feature of the cluster indicators. Picture Fig 1 shows the indicator CCFp (Complex_Common_Frame percent). In spite of its binding to the chart EURUSD, it will have the same form on any other currency pair, even if this pair doesn't belong to the analysed cluster.


Basic Concepts of Working with Cluster Indicators

In the picture Fig 1 there are eight lines of different color. Each line corresponds to a definite currency. Cluster indicators reflect not the currency indexes, but their fluctuation relative to each other. Indicators represent a self-contained system; this makes the market model simpler, but such simplification does not hinder a successful trading on the indicators.

The currencies are measured in relative units, that is why in each unit time the sum of all currencies will be equal to zero. Thus one of the basic elements of cluster indicators is a zero line, or balance line. If a currency is below the balance line, it is said to be oversold as compared to other currencies. Accordingly, if a currency is above the zero line, it is said to be overbought. If a currency is overbought, sooner or later it will start to wind down against all other currencies, the currency line will go down and may reach the balance line or even enter the overselling zone.

The nearness of a currency to the balance line means that the currency is in the balance state towards other currencies. One more important element of cluster indicators is the point of intersection of lines, pointing to the trend change or giving a signal. Besides, based on indicators one can extract divergency and convergency, but we will discuss these elements in details in the next article "Practical application of cluster indicators in the FOREX market".

I would like to draw your attention to a fact, which is not evident during analysing cluster indicators. Usually indicators are build on the basis of the price of a definite currency pair. But cluster indicators are build on the basis of all currency pairs of the complex. Watching the indicator you must understand that we observe the prices of all the twenty four currency pairs simultaneously, and not only the derivative from the price of a current currency pair, to which the indicator is attached.

If the indicator is displayed under the pair EURUSD, beside this currency pair it calculates pairs EURGBP, USDGBP, USDCHF, EURJPY and so on, i.e. all other pairs, which include USD and EUR. And when a trade signal comes, you must remember, that not a definite pair is traded, but the whole market, or a market cluster to be more precise. This fact is an advantage, but at the same time a disadvantage. Signals on this indicators are more secure, because they are build on the basis of all currency pairs. But at the same time there is always a risk, that the chosen currency pair will stand out among the whole complex of currencies. For example, in the market it may happen so, that large amounts of pounds are sold for USD. The influence of one currency on the whole cluster is a little more than 4% (onу pair out of twenty four). In this case the indicators are most valuable as informational, not trading. Though trading systems are created based on the indicators.


Requirements for Cluster Indicators Operation

Terminal MetaTrader 4 makes some restrictions, which do not allow to use cluster indicators for all financial instruments. The maximal number of lines on the indicator is eight. That is why the largest cluster can contain only eight currencies. This set includes: USD, EUR, GBP, CHF, JPY, CAD, AUD, NZD. And for their operation the indicators need quotes of twenty four currency pairs: EURUSD, EURGBP, EURCHF, EURJPY, EURCAD, EURAUD, EURNZD, GBPUSD, GBPCHF, GBPJPY, GBPCAD, GBPAUD, GBPNZD, USDCHF, USDJPY, USDCAD, AUDUSD, AUDJPY, AUDCAD, AUDNZD, NZDUSD, NZDCHF, NZDCAD, NZDJPY. The necessity of the quotes on the indicated pairs until recently was limiting the number of brokerage companies, on whose platforms the indicators could operate.

Nowadays in the last indicator modifications the requirements became lower, now you need to have all crosses that include USD. So , to have indicators operate, the following currency pairs are enough: EURUSD, GBPUSD, USDCHF, USDJPY, USDCAD, AUDUSD, NZDUSD. As the author knows, all brokerage companies working on MetaTrader 4 platform provide quotes for the mentioned currency pairs. But it must be remembered that old versions of indicators, which still can be met in the Internet, request the complete set, i.e. twenty four currency pairs.

It should be noted, that cluster indicators, especially those of earlier versions, were very demanding to the computer capacity and the capacity of the Internet Channel. Now the requirements are lower, however cluster indicators remain more resource-intensive than the majority of other indicators and oscillators. Besides, experience shows that primary installation of the indicators generally reveals the deficiency of quotes on some currency pairs, which suggests their forced downloading.


Types of Cluster Indicators

During the development of the complex of cluster indicators, a large number of ideas was realized in separate indicators. However now the author suggests dwelling on three main types.

The first one is indicator CCFp, it is shown at the picture Fig 1.


CCFp (Complex_Common_Frames percent) – is a trend following indicator. Its predecessor CCF estimated the divergency of currencies in points, while CCFp works with specific values, which allows to avoid distortions, resulting from the "heaviness" of separate currencies. "Heaviness" here means that, for example, pound is almost twice more expensive than USD (Febr. , 2007 - time of article writing). As a result - points for each currency have different value. So the decision was made to count the percentage.


The second indicator is CC (Complex_Common).

It is an impulse, or signal indicator. It is very sensitive and quickly reacts on the price movements. The indicator is shown at the picture Fig 2.




The picture shows the currency pair EURUSD. Two windows below contain the same indicator. The upper window shows all the currencies, lines of USD and euro are semi-bold. The lower window contains the same indicator, but all other currencies are concealed; it shows currencies only of the corresponding pair.

The third indicator Complex_Pair1

is a derivative from the indicator CC. At the picture Fig 2 the lower window displays only two lines: EUR and USD. The sum of these indicators is the indicator Complex_Pair1, which reflects only one impulse (signal) line. You can see this indicator at the picture Fig 3.




It should be noted, that the indicator Complex_Pair was developed first. But it was too resource-intensive. Later development found another way of building the same indicator, but using a fast algorithm, which allowed to extract the same information, but now from the price chart of one currency only. Inspite of the fact, that Complex_Pair and Complex_Pair1 receive the information in different ways, their visual identity on the higher timeframes was absolute. On the lower timeframes there was some difference, but Complex_Pair 1 can work on any financial instrument - stocks, futures or raw material.

The author of the cluster indicators specifies, that the algorithm of the indicator Complex_Pair1 was developed by another person. (Forum of the site Onix, developer - arzuma, link to a message).


A Short Description of Algorithms of Cluster Indicators Operation

The idea of dividing a complete cluster of currency pairs into separate pairs is simple. Suppose, a small cluster is used for currency pairs EURUSD, GBPUSD, EURUSD and the task is to separate the currencies: EUR, USD, GBP. If within a certain period of time a pair EURUSD grew, the difference will be added to EUR and subtracted from USD. If at the same time the pair GBPUSD raised, the changes in price are added to GBP and subtracted from USD. And, finally, it is necessary to consider the price changes of the pair EURGBP. Suppose the pair sank, then the difference will be added to GBP and subtracted from EUR.


As in Forex it is impossible to determine a common denominator, which could be a model stable in time, when separating currencies, they are not normalized and all the changes are counted in relative units. Until recently a point was accepted as such unit. But as the point value is changeable in time and is different for different currencies, in last modifications of cluster indicators the price change was calculated in percentage. Besides, experience showed that contemporary quote servers do now allow a significant difference of currency crosses. That is why to reduce the traffic of pumping quotes and to increase the operation speed of the indicators, calculations of all currency pairs are conducted on the basis of dollar crosses only. So the general algorithm of the indicators looks like this:

  1. Determination of currencies, that will enter a cluster. Is set by user's settings;
  2. Mathematical calculation of non-dollar crosses based on dollar ones, even if USD is excluded from the cluster;
  3. Noise filtering by moving average. The parameters are set by the user;
  4. Analysing all currency pairs of the cluster on the price change and fulfilling the matrix of currencies, included into the cluster;
  5. Next is the logical realization of a certain type of indicator, i.e. for a trend following indicator several timeframes are processed (not only the current one), simple transformations are used for an impulse indicator.

The source files of the indicators CCFp, CC, CFP, Complex_pairs1 are attached to the article.


Parameters of Cluster Indicators

The following inputs available for setup are determined in the last version of the indicators. The inputs are divided into several groups.

The first group of inputs determines the method of filtration
MA_Method - method of determining a moving average, can be one of the following variants:

  • 0 - Simple moving average;
  • 1 - Exponential moving average;
  • 2 - Smoothed moving average;
  • 3 - Linearly-weighted average.

The parameter 3 is set on default

Price - used price, can accept one of the following values:

  • 0 - Close price;
  • 1 - Open price;
  • 2 - Maximal price, (High);
  • 3 - Minimal price, (Low);
  • 4 - Average price, (High+Low)/2;
  • 5 - Typical price, (High+Low+Close)/3;
  • 6 - Weighted closing price, (High+Low+Close+Close)/4.

The parameter 6 is set on default.

Fast - a period of fast average, on default - 3.

Slow - a period of slow average, on default - 5.

The second group of inputs enables to form different types of clusters

This group encloses eight logical parameters, which can assume a value true/false (1/0). Each parameter includes this or that currency into a cluster or disables it:

  • USD - includes into the cluster or excludes from the cluster US dollar (on default - true);
  • EUR - includes into the cluster or excludes from the cluster Euro (on default - true);
  • GBP - includes into the cluster or excludes from the cluster British pound (on default - true);
  • CHF - includes into the cluster or excludes from the cluster Swiss frank (on default - true);
  • JPY - includes into the cluster or excludes from the cluster Japanese yen (on default - true);
  • CAD - includes into the cluster or excludes from the cluster Canadian dollar (on default - true);
  • AUD - includes into the cluster or excludes from the cluster Australian dollar (on default - true);
  • NZD - includes into the cluster or excludes from the cluster New Zealand dollar (on default - true).


The third group of inputs manages the external view of the indicators

It should be noted, that line thickness and color should be better set through this inputs, and not through a common tab, present in any indicator. When a line is set up in an invisible color (background color), the lines will not be displayed on the indicator, but currencies will be calculated. A currency can be excluded from the cluster only through the second group of inputs, described earlier.

  • Color_USD – color of a line for US dollar;
  • Color_EUD – color of a line for Euro;
  • Color_GBP – color of a line for British pound;
  • Color_CHF – color of a line for Swiss frank;
  • Color_JPY – color of a line for Japanese yen;
  • Color_CAD – color of a line for Canadian dollar;
  • Color_AUD – color of a line for Australian dollar;
  • Color_NZD – color of a line for New Zealand dollar;
  • Line_Thickness – presets the line thickness of a displayed currency pair. Sometimes it is convenient. For example, if we analyse the chart EURUSD, it is more convenient when EUR and USD differ from others not only in color, but also in the line thickness.


At the same time the indicators can be set up so, that other currencies will not be visible at all; only necessary currencies will be viewed. The example of such setting is at the picture Fig 3.

The fourth group of inputs includes only one parameter, but now there is an idea to include additional parameters into this group.

All_Bars determines the number of the calculated history bars. If this parameter is equal to 0 (it is so on default), all available history is calculated. But, as mentioned earlier, the indicators are resource intensive, that is why its use on low-performance computers is problematic. This parameter allows to unburden the machine by limiting the analysed history of quotes. It is noted, that at values 1000 and 500 the operation speed of indicators is significantly higher.


Conclusion

The advantage of cluster indicators is in their ability to show in one window dynamics of relative currency fluctuation, which allows to discover promising currency pairs, which are likely to experience trend movements. Cluster indicators allow to track trends inception and can give signals to open or close positions. You can find more information about the operation of indicators from the article "Practical use of cluster indicators in FOREX market". You can read about the history of development of indicators on the site Onix, section "Cluster indicators".

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/1464

Attached files |
CC.mq4 (16.97 KB)
CCFp.mq4 (17.15 KB)
CFP.mq4 (13.82 KB)
Complex_pairs1.mq4 (3.67 KB)
Last comments | Go to discussion (12)
MQL4 Comments
MQL4 Comments | 10 Jul 2012 at 07:10
thaankssss...
MQL4 Comments
MQL4 Comments | 23 Oct 2013 at 08:50

Dear all.

The Complex_pairs1.mq4 indicator looks clever.

How to use the Complex_pairs1 indicator to input/close positions ?

laz
laz | 9 Jan 2016 at 16:42

sry for posting in an old thread but i got a question...

i think the calculation in CCFP is wrong, can one check this pls?

double ma(string sym, int per, int Mode, int Price, int i)
  {
   double res = 0;
   int k = 1;
   int ma_shift = 0;
   int tf = 0;
   switch(Period())
     {
       case 1:     res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 5;
       case 5:     res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 3;
       case 15:    res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 2;
       case 30:    res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 2;
       case 60:    res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 4;
       case 240:   res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 6;
       case 1440:  res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k += 4;
       case 10080: res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
                   k +=4;
       case 43200: res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); 
     } 
   return(res);
  }  
he forgot the "break;" after each "case" - the result is that he adds values of higher timeframes to the real/correct output value "res" ...

the correct result for H4 is 117,93, because of the missing breaks all higher timeframe results are added with wrong k values...?


why wrong k values?

 case 240:   res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); k += 6;

in my picture you'll see k = 7 @ H4 but the IMA call is before we increased k(intial value 1) to 7, the IMA calculation is done with k = 1! this makes no sense, why increase k after we used it? we don't need it anymore?


example code for that H4 line should be like this or did i understand something wrong?

 case 240:   k += 6; res += iMA(sym, tf, per*k, ma_shift, Mode, Price, i); break;
jauhar
jauhar | 7 Feb 2016 at 06:50

I think the missing break is not an error. It is done intentionally to add the values for higher timeframes as well by continuing down to the following cases.

 

But I think there is another error. After each call to iMA(), k is updated using '+=' operator. I think it should be '*='. As the higher timeframe should be calculated by multiplying the current time frame by a number. So if the current timeframe is H4, k should change as k *= 6 to calculate D1 from it. Also for case 1440: the multiplier should be 5 (not 4) as there are 5 daily bars in a week.  

luis
luis | 24 Aug 2016 at 19:46

In my opinion, the algorithm of the indicator is right, nothing to be changed. The smaller the timeframe, the more bars that are used on the calculation, what makes sense to me.

I would have done it other way, using "break" on the switch statements, and modifying the period depending on the current timeframe the number of bars, to avoid calling so many times iMA() when using small timeframes for each bar. But anyway, it works the way it is.

I have modified the code to cope with the new MQL4. But indicator values are exactly the same as on the original CCFp.mq4.

List of changes:

  1. Adapted original CCFp.mq4 to new MQL4
  2. Minor changes to improve speed and clarity (renaming)
  3. Added zero line level to the indicator
  4. Once indicator is loaded, as a default, each time a tick arrives, only the last 2 candles are recalculated.

I have left the copyright values to the original author, and change the link to this article on mql5.com.

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.

False trigger protection for Trading Robot False trigger protection for Trading Robot

Profitability of trading systems is defined not only by logic and precision of analyzing the financial instrument dynamics, but also by the quality of the performance algorithm of this logic. False trigger is typical for low quality performance of the main logic of a trading robot. Ways of solving the specified problem are considered in this article.

Using text files for storing input parameters of Expert Advisors, indicators and scripts Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.