Download MetaTrader 5

Can anyone tell me the math behind CFP indicator?

To add comments, please log in or register
squarepusher229
181
squarepusher229  

Hi,


Can anyone guide me in laymens terms what arithmetic is being done in the CFP indicator for mt4, for example for the AUDUSD pair's display.



eg.  FAST MA divided by SLOW MA, then minus 1.   Then multiplied by 5.... etc etc


Attached indicator from    https://www.mql5.com/en/articles/1472




THANK YOU

Practical Application of Cluster Indicators in FOREX
Practical Application of Cluster Indicators in FOREX
  • 2007.09.03
  • Simeon Semenych
  • www.mql5.com
Cluster indicators are sets of indicators that divide currency pairs into separate currencies. Indicators allow to trace the relative currency fluctuation, determine the potential of forming new currency trends, receive trade signals and follow medium-term and long-term positions.
Files:
CFP814.mq4 14 kb
Stanislav Korotky
21060
Stanislav Korotky  

I'm not sure where you see multiplication by 5, but the idea is to calculate for every major pair how it has been changing in past - this is done by ratio between two MAs - slow and fast. Then every major currency power is formed from the corresponding ratios for all pairs which contain specific currency. Minus 1 comes from the fact that we want to have a zero line for balance. In other words, if a pair is not changed, its ratio of fast and slow MAs will give 1. If it was rising it will give > 1, if it was falling < 1. We just transfer this > 1 and < 1 to > 0 and < 0 scale. This makes the sum of all changes (in different currencies) equal to 0!

Also you may see that if a pair contains usd as quoting currency (second), we calculate the ratio as fast/slow, and if usd is the base (first) - then the ratio is calculated as slow/fast.

Also the MAs are actually not a simple MAs but constructed from many MAs of different periods - this produces more weighted behaviour.

squarepusher229
181
squarepusher229  
Stanislav Korotky:

I'm not sure where you see multiplication by 5, but the idea is to calculate for every major pair how it has been changing in past - this is done by ratio between two MAs - slow and fast. Then every major currency power is formed from the corresponding ratios for all pairs which contain specific currency. Minus 1 comes from the fact that we want to have a zero line for balance. In other words, if a pair is not changed, its ratio of fast and slow MAs will give 1. If it was rising it will give > 1, if it was falling < 1. We just transfer this > 1 and < 1 to > 0 and < 0 scale. This makes the sum of all changes (in different currencies) equal to 0!

Also you may see that if a pair contains usd as quoting currency (second), we calculate the ratio as fast/slow, and if usd is the base (first) - then the ratio is calculated as slow/fast.

Also the MAs are actually not a simple MAs but constructed from many MAs of different periods - this produces more weighted behaviour.

Thanks for your response, I appreciate it very much.



I do agree in that I understand, for example in AUDUSD, the first math done is FAST moving avg (based on linear weight avg) divided by SLOW moving avg of AUDUSD. Then minus 1 or normalize it for a zero line balance. But what is done after, since that is not the end.  Is that value then balanced with every other AUDXXX calculation as well or ?? 


You said something about the sum of all changes equalling 0..this may be what I am not understanding in how that is calculated particularly.

Stanislav Korotky
21060
Stanislav Korotky  
squarepusher229:

I do agree in that I understand, for example in AUDUSD, the first math done is FAST moving avg (based on linear weight avg) divided by SLOW moving avg of AUDUSD. Then minus 1 or normalize it for a zero line balance. But what is done after, since that is not the end.  Is that value then balanced with every other AUDXXX calculation as well or ?? 

Please quote here exact lines of the code you don't understand. "After" is just combining 2 "powers" of 2 currencies which form current Symbol().
squarepusher229
181
squarepusher229  

For the example of 4hr AUDUSD, does the following sequence of code take place?


1.

if(AUD)
         {
           double AUDUSD_Fast = ma("AUDUSD", Fast, MA_Method, Price, i);
           double AUDUSD_Slow = ma("AUDUSD", Slow, MA_Method, Price, i);
           if(!AUDUSD_Fast || !AUDUSD_Slow)
               break;
2.
if(AUD)
         {
           arrAUD = 0;
           if(USD) 
               arrAUD += AUDUSD_Fast / AUDUSD_Slow - 1;
3. 
//+------------------------------------------------------------------+
//|  Subroutine                                                      |
//+------------------------------------------------------------------+
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 240:   res += iMA(sym, tf, per*k, ma_shift, Mode, Price,i); 
                   k += 6;



I hope that helps narrow down what I'm trying to understand.  As in step 3, what is happening?

If you could break down the arithmetic/logic of this 4hr AUDUSD , I would greatly appreciate it.

Stanislav Korotky
21060
Stanislav Korotky  

This is very simple.

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);
  }   

The author made this synthetic MA as combination of standard MAs from different periods from different timeframes. Whatever timeframe you use, the algorithm starts to calculate MA for that timeframe and then adds other parts from higher timeframes. This is done to make the synthetic MA behave more stable. Normally, when you use a single MA, it will have afteraffects, so to speak, that is every noticable increase will be followed by equally noticable fall (when old bars from MA period offset go out of the scope). The synthetic MA makes such falls less noticable.

When you use H4, the MA is calculated starting from the case 240 with given 'per', then another MA from "D1" (1440) case and period *7 is added and so on. Please note that the switch does not have breaks after each clause.

squarepusher229
181
squarepusher229  
Stanislav Korotky:

This is very simple.

The author made this synthetic MA as combination of standard MAs from different periods from different timeframes. Whatever timeframe you use, the algorithm starts to calculate MA for that timeframe and then adds other parts from higher timeframes. This is done to make the synthetic MA behave more stable. Normally, when you use a single MA, it will have afteraffects, so to speak, that is every noticable increase will be followed by equally noticable fall (when old bars from MA period offset go out of the scope). The synthetic MA makes such falls less noticable.

When you use H4, the MA is calculated starting from the case 240 with given 'per', then another MA from "D1" (1440) case and period *7 is added and so on. Please note that the switch does not have breaks after each clause.

Thank you ! I will apply what you explained so eloquently.  Thanks again
squarepusher229
181
squarepusher229  
Stanislav Korotky:

This is very simple.

The author made this synthetic MA as combination of standard MAs from different periods from different timeframes. Whatever timeframe you use, the algorithm starts to calculate MA for that timeframe and then adds other parts from higher timeframes. This is done to make the synthetic MA behave more stable. Normally, when you use a single MA, it will have afteraffects, so to speak, that is every noticable increase will be followed by equally noticable fall (when old bars from MA period offset go out of the scope). The synthetic MA makes such falls less noticable.

When you use H4, the MA is calculated starting from the case 240 with given 'per', then another MA from "D1" (1440) case and period *7 is added and so on. Please note that the switch does not have breaks after each clause.

Hi again, Im having an issue still getting to what you mean at this part "  Whatever timeframe you use, the algorithm starts to calculate MA for that timeframe and then adds other parts from higher timeframes." 



Can you if possible show me the math of what exactly is going on for example the 4hr AUDUSD when calculating CFP?  I would be greatly appreciative

Stanislav Korotky
21060
Stanislav Korotky  
squarepusher229:

Hi again, Im having an issue still getting to what you mean at this part "  Whatever timeframe you use, the algorithm starts to calculate MA for that timeframe and then adds other parts from higher timeframes." 

Can you if possible show me the math of what exactly is going on for example the 4hr AUDUSD when calculating CFP?  I would be greatly appreciative

Could you probably debug the code step by step and see in action all the math? The math is actually the algorithm shown in the source codes. I tried to describe it in natural language, but it seems not so definitive as MQL itself.
To add comments, please log in or register