What is the math inside this indicator???

 

Greetings all, So I have in active use the indicator (called CFP). I am trying to read the mq4 file and understand how it works, but dont get it once it gets to "subroutine". Can anyone who understands mq4 programming decipher this for me? What I have so far is this: For example, GBPCHF will do this first: (GBPUSD_somemovingaverage * USDCHF_somemovingaverage) / (GBPUSD_mvgaverage * USDCHF_mvgaverage) - 1 then..... what? (this is where I get tripped up on the subroutine Let me know if you need more info... I can just post the subroutine here actually, instead of attach the file but let me know if you want the whole mq4. Thanks. -------------------------- *here is the first equation of movingaverages divided by other moving averages I stated earlier in this post* then.... //+------------------------------------------------------------------+ //| 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 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);

 

Wow, there are no spacing in making posts .... sorry for the jumbled looking post !!!!!

 
no0cool:
Wow, there are no spacing in making posts .... sorry for the jumbled looking post !!!!!

When you post code in as a text, use the php control for that (the one pointed to at the picture). Then it will loo OK

Files:
php.gif  33 kb
 
no0cool:
Greetings all, So I have in active use the indicator (called CFP). I am trying to read the mq4 file and understand how it works, but dont get it once it gets to "subroutine". Can anyone who understands mq4 programming decipher this for me? What I have so far is this: For example, GBPCHF will do this first: (GBPUSD_somemovingaverage * USDCHF_somemovingaverage) / (GBPUSD_mvgaverage * USDCHF_mvgaverage) - 1 then..... what? (this is where I get tripped up on the subroutine Let me know if you need more info... I can just post the subroutine here actually, instead of attach the file but let me know if you want the whole mq4. Thanks. -------------------------- *here is the first equation of movingaverages divided by other moving averages I stated earlier in this post* then.... //+------------------------------------------------------------------+ //| 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 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);

That function is returning a moving average using period avetage multiplied with time adjusting factor depending on the target time frame. It is a part of CCFp indicator (and it looks like this when formated properly) :

//+------------------------------------------------------------------+

//| Subroutines |

//+------------------------------------------------------------------+

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

}

 

mladen, you have exactly narrowed down on the part where I am getting lost. Thank you for your precision on focusing on that subroutine!

OK, I am trying to understand it now. So work with me here as I build my example from the previous post.

Eg. GBPCHF

I want to make a CFP for this on the 4hour TF.

First, part 1, I do the 5th math equation here (for GBP+CHF):

if(GBP)

{

arrGBP = 0;

if(USD)

arrGBP += GBPUSD_Fast/GBPUSD_Slow-1;

if(EUR)

arrGBP += (EURUSD_Slow / GBPUSD_Slow) /

(EURUSD_Fast / GBPUSD_Fast) - 1;

if(AUD)

arrGBP += (GBPUSD_Fast / AUDUSD_Fast) /

(GBPUSD_Slow / AUDUSD_Slow) - 1;

if(NZD)

arrGBP += (GBPUSD_Fast / NZDUSD_Fast) /

(GBPUSD_Slow / NZDUSD_Slow) - 1;

if(CHF)

arrGBP += (GBPUSD_Fast*USDCHF_Fast) /

(GBPUSD_Slow*USDCHF_Slow) - 1;[/PHP]

Then part 2 (here comes the subroutine part I am still not getting):

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

k += 6;

Is this saying multiply my answer from part 1 by 6 ?, or multiply the period of each MA, by 6? Wow mega confused.

Thanks for recognizing this is from CCfp. Maybe there is more arithmetic involved in the indicator than Im seeing but , these were the 2 salient math parts I saw. I am doing all this because I am trying to rebuild the indicator value just for a specific time frame use only and my data is not appearing correctly as I use my indicator builder side-by-side the actual Metatrader window showing the values.

 

PS.

Fast = LWMA with period of 5 bars

Slow= LWMA with period of 3 bars

 
no0cool:
mladen, you have exactly narrowed down on the part where I am getting lost. Thank you for your precision on focusing on that subroutine!

OK, I am trying to understand it now. So work with me here as I build my example from the previous post.

Eg. GBPCHF

I want to make a CFP for this on the 4hour TF.

First, part 1, I do the 5th math equation here (for GBP+CHF):

if(GBP)

{

arrGBP = 0;

if(USD)

arrGBP += GBPUSD_Fast/GBPUSD_Slow-1;

if(EUR)

arrGBP += (EURUSD_Slow / GBPUSD_Slow) /

(EURUSD_Fast / GBPUSD_Fast) - 1;

if(AUD)

arrGBP += (GBPUSD_Fast / AUDUSD_Fast) /

(GBPUSD_Slow / AUDUSD_Slow) - 1;

if(NZD)

arrGBP += (GBPUSD_Fast / NZDUSD_Fast) /

(GBPUSD_Slow / NZDUSD_Slow) - 1;

if(CHF)

arrGBP += (GBPUSD_Fast*USDCHF_Fast) /

(GBPUSD_Slow*USDCHF_Slow) - 1;[/PHP]

Then part 2 (here comes the subroutine part I am still not getting):

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

k += 6;

Is this saying multiply my answer from part 1 by 6 ?, or multiply the period of each MA, by 6? Wow mega confused.

Thanks for recognizing this is from CCfp. Maybe there is more arithmetic involved in the indicator than Im seeing but , these were the 2 salient math parts I saw. I am doing all this because I am trying to rebuild the indicator value just for a specific time frame use only and my data is not appearing correctly as I use my indicator builder side-by-side the actual Metatrader window showing the values.

Looking at that code (I copied it from CFP from metaquotes site - from here : Theoretical Basis of Building Cluster Indicators for FOREX - MQL4 Articles) and only now noticed that the code is all wrong. The error is simple : instead of "k +=nnn" should be "k*=nnn"

What that code should do is the following : if your time frame is 1 minute then it should :
calculate 1 minute average

calculate 5 minute average (by multiplying the 1 minute calculation period by 5)

calculate 15 minute average (by multiplying the 5 minute calculation period by 3)

...

and so on

By adding those numbers instead of multiplying the k factor by those factors, it is using completely wrong periods for all but the first moving average. So, in order to have a proper CFp, all those "k+=nnn" should be replaced by "k*=nnn". The way it is written now, does not conform to any logical point of view (but then, with correct periods, results are meaningless for lower time frames )

_____________________

Surprise, surprise : it works correcly with build 509 for lower time frames, it does not work correctly with new builds when the "+" is changed to "*"

 
mladen:
Looking at that code (I copied it from CFP from metaquotes site - from here : Theoretical Basis of Building Cluster Indicators for FOREX - MQL4 Articles) and only now noticed that the code is all wrong. The error is simple : instead of "k +=nnn" should be "k*=nnn" What that code should do is the following : if your time frame is 1 minute then it should :
calculate 1 minute average

calculate 5 minute average (by multiplying the 1 minute calculation period by 5)

calculate 15 minute average (by multiplying the 5 minute calculation period by 3)

...

and so on

By adding those numbers instead of multiplying the k factor by those factors, it is using completely wrong periods for all but the first moving average. So, in order to have a proper CFp, all those "k+=nnn" should be replaced by "k*=nnn". The way it is written now, does not conform to any logical point of view (but then, with correct periods, results are meaningless for lower time frames )

_____________________

Surprise, surprise : it works correcly with build 509 for lower time frames, it does not work correctly with new builds when the "+" is changed to "*"

mladen, I really appreciate you continuing trying to tackle this with me.

I am still stumped though. I've been inputting these settings as best as I can but the data is not matching what my Metatrader data is outputting as far as CFP gives to me.

Can you clarify when you say "calculate 1 minute average, then mult that by 5 to give the next "5 minute average", etc etc." ... are you creating a 1m average using the 1minute of (GBPUSDfast*USDCHFslow/GBPUSDslow*USDCHFfast) -1 ? Or what?? As I create this indicator, it appears more and more like the Complex_pair, which is another very similar indicator of the same style.

This CFP is giving me tremendous problems...

 

All that is changing as I multiply each subsequent moving average results by 5, 3, 2, 2 etc... is the scale changes larger. The line looks exactly the same...

 

Also, basically what I think would be a workaround to all this is if I could get this mq4 into a DLL file that would be able to run in my (paid) Neuroshell. Thats what Ive been trying to accomplish but cant (talked to many a programmers and support staff, still nothing). It would save me having to decipher the mq4 indicator and create the arithmetic in neuroshell because it seems Im missing something besides seeing the mult and division of these moving averages.

https://www.mql5.com/en/forum/174921/page8

 
no0cool:
mladen, I really appreciate you continuing trying to tackle this with me.

I am still stumped though. I've been inputting these settings as best as I can but the data is not matching what my Metatrader data is outputting as far as CFP gives to me.

Can you clarify when you say "calculate 1 minute average, then mult that by 5 to give the next "5 minute average", etc etc." ... are you creating a 1m average using the 1minute of (GBPUSDfast*USDCHFslow/GBPUSDslow*USDCHFfast) -1 ? Or what?? As I create this indicator, it appears more and more like the Complex_pair, which is another very similar indicator of the same style.

This CFP is giving me tremendous problems...

no0cool

As of multiplication :

Imagine this. I minute average period 10. Now, in the old days when the computers were not so common, if they wanted 5 minute average they calculated period 50 on 1 minute data. And so on for any higher time frame. You simply have to multiply the period with the desired "ratio" (in this case it was 5 since 5 minute time frame is 5 times "longer" than 1 minute period) and you will get an approximate multi time frame result