Pearson correlation - page 5

 
mladen:
Nice work

But be careful with it. The way you done it it is shortening the calculation period in cases when there are missing bars in some of the correlated symbols (that is why you get bigger differences in the past than you can see in the present - as the missing bars number grows, the difference will grow, so, in the end, it depends on your broker data) Here is one that will not shorten the calculation period artificially but will always calculate the required correlation period (bars)

Here is a comparison of the 3 for the present : upper is your version, middle is the one from the 1st post and the lower is this version - as you can see, you will have to go way back in past (to have enough missing bars on the chart) to start to see differences in the 3 versions values (as I said, it all depends on broker data and missing bars)

You are right that for an ideal broker there should be no difference between the original and the mods. Life is never ideal, though.

As to the shortening the length of the vector in case of missing bars, this is a matter of choice you have to make. In your last version, you know the length of the vectors you are calculating the correlation for, but not the exact time period. In my version, I am likely to know the time period but not the exact length. I would stick to my version but this is a matter of preferences.

 

That can lead to some positions on chart having no calculation lengths at all (easy to imagine when a "block" of data misees and calculation length is short) and still does not guarantee a "time chunk" is the expected one (again depends on broker and Monday start and Friday end times, and both symbols must have same start data). Anyway, a matter of preference. In any case, on a normal broker and in normal usage, the version from the first post does quite OK too, soo it is purely a matter of choice now

arcella:
You are right that for an ideal broker there should be no difference between the original and the mods. Life is never ideal, though. As to the shortening the length of the vector in case of missing bars, this is a matter of choice you have to make. In your last version, you know the length of the vectors you are calculating the correlation for, but not the exact time period. In my version, I am likely to know the time period but not the exact length. I would stick to my version but this is a matter of preferences.
 

mladen, I've just noticed an interesting trick in your code, the one with gettingBars. Nice! I am surprised with this part, however:

if (_=="gettingBars")

{

gettingBars = true;

return(0);

}

This implies that underscore (_) has a special meaning in this case. Where did you get this from?

 

arcella

In this case underscore is a name of an external variable (metatrader loows that kind of names). I use that parameter to pass special values (like the "gettingBars" case) when the indicator calls itself.

As of where did I get it from : actually that was my idea when I was fooling with some multi time framing some years back, once when I noticed that WindowExpertName() returns correct indicator name even when it is renamed to whatever : it allowed to have 3-indicators-in-1 for each multi time frame indicator and allowed the correct solution for the number of bars that need to be recalculated in multi time frame mode

arcella:
mladen, I've just noticed an interesting trick in your code, the one with gettingBars. Nice! I am surprised with this part, however:

if (_=="gettingBars")

{

gettingBars = true;

return(0);

}

This implies that underscore (_) has a special meaning in this case. Where did you get this from?
 

Right, I should have been more attentive about the underscore. Thank you for an interesting lesson! The subject of multi pair indicators seems to be plagued with subtle points.

I would like to ask you for an advice. May be you came across similar problems in your studies. I had a problem with using a multi timeframe and multi pair indicator that the indicator attached to a chart and the same indcator called from an EA were producing different results (well, not entirely different but different enough to become a problem). I am quite sure that there were no obvious solution to this (technical mistake, different parameters etc). Did you happen to come accross such a situation?

 

...

arcella

Whenever I had some problem similar to that, almost always it was a problem with parameters (some parameter was omitted, or a wrong type, or in wrong order ...) If the parameters are OK, there should be no difference in values

arcella:
Right, I should have been more attentive about the underscore. Thank you for an interesting lesson! The subject of multi pair indicators seems to be plagued with subtle points. I would like to ask you for an advice. May be you came across similar problems in your studies. I had a problem with using a multi timeframe and multi pair indicator that the indicator attached to a chart and the same indcator called from an EA were producing different results (well, not entirely different but different enough to become a problem). I am quite sure that there were no obvious solution to this (technical mistake, different parameters etc). Did you happen to come accross such a situation?
 

thanks, mladen

 

if it is possible ,please add an alert to this correlation indicator which is created by mladen.

when the line crosses over certain level, the alert is triggerd.

eg:

alert for:"currency pair"(EURUSD)

alert level: "number"(0.5)

alert current:"true or false"

alert message:"same as above"

alert sound:"same as above"

thanks a lot.

Pearson_mod 1.mq4

 

Hi mladen,

if you have time , could you help me with this alert function?it is a wonderful indicator when trade crosses pairs, i think it will aslo do big help to other traders when they are trading cross pairs.

Thanks.

leo

leowang:
if it is possible ,please add an alert to this correlation indicator which is created by mladen.

when the line crosses over certain level, the alert is triggerd.

eg:

alert for:"currency pair"(EURUSD)

alert level: "number"(0.5)

alert current:"true or false"

alert message:"same as above"

alert sound:"same as above"

thanks a lot.

Pearson_mod 1.mq4
 

if it is possible ,please add an alert. pls!!

Reason: