How to show MACD to another currency pair ?

 

Hi all, i would like to show MACD on another Currency pair,but i meet some problem when i try to do it.

For example,please see the below pic,the current pair is EURUSD,and the MACD is belong to EURGBP,apparently the MACD is wrong.

But if i change the currency pair to EURGBP, the MACD looks good.

Anybody can help me on it ?what's wrong when i attach MACD to different pair ?

macdtest.mq4

Files:
t2.jpg  108 kb
t1.jpg  118 kb
macdtest.mq4  3 kb
 

...

You have a problem that few are thinking of

In case when you are calculating values for symbol different than the current chart symbol you have to check the number of changed bars for 2 symbols not one : the current chart and the target symbol. The bigger of the 2 should be used. Probably the biggest problem is how to "ask" the other symbol how many bars have been changed. You can either write a separate indicator which will be used only for that (to return the number of changed bars for a target symbol and time frame) or you can do something like it is done in this indicator. That way all the bars that need to be recalculated will be recalculated (for example on the current bar you might have just one bar changed and in the target symbol, due to not being downloaded for a long time, all the bars are changed)

Hope this was not a complicated explanation. The code itself is rather simple and I hope that it will speak for itself

yuzs2000:
Hi all, i would like to show MACD on another Currency pair,but i meet some problem when i try to do it.

For example,please see the below pic,the current pair is EURUSD,and the MACD is belong to EURGBP,apparently the MACD is wrong.

But if i change the currency pair to EURGBP, the MACD looks good.

Anybody can help me on it ?what's wrong when i attach MACD to different pair ?

macdtest.mq4
Files:
macdtest.mq4  3 kb
 

I changed a bit and I tested it and works fine to me:

I've used a EURUSD chart and I've choosed USDCHF for the indicator.

To be sure, then I've opened a USDCHF chart and attached a standard MACD indicator and the figures match perfectly

Check it :-)

Best regards and happy trading!!!

 

Hi acushnir,the attachment is unavailable ,can you upload it again ?

acushnir:
I changed a bit and I tested it and works fine to me:

I've used a EURUSD chart and I've choosed USDCHF for the indicator.

To be sure, then I've opened a USDCHF chart and attached a standard MACD indicator and the figures match perfectly

Check it :-)

Best regards and happy trading!!!

 

Hi mladen,i download your file ,but i still got the wrong MACD chart ,i was wondering if it works well in your machine ?

mladen:
You have a problem that few are thinking of

In case when you are calculating values for symbol different than the current chart symbol you have to check the number of changed bars for 2 symbols not one : the current chart and the target symbol. The bigger of the 2 should be used. Probably the biggest problem is how to "ask" the other symbol how many bars have been changed. You can either write a separate indicator which will be used only for that (to return the number of changed bars for a target symbol and time frame) or you can do something like it is done in this indicator. That way all the bars that need to be recalculated will be recalculated (for example on the current bar you might have just one bar changed and in the target symbol, due to not being downloaded for a long time, all the bars are changed)

Hope this was not a complicated explanation. The code itself is rather simple and I hope that it will speak for itself
 

It does

Here is how it looks on EURUSD chart

and here is how it looks on EURGBP chart

as you can see it shows the same MACD values on both charts (as it should). Also, if I change to any other symbol it stays the same (as it should, since it is supposed to show MACD for EURGBP with default settings)

And the last, it is EURGBP chart with that indicator (upper) and the built in MACD (lower). As you can see the values of the MACDTest and the built in MACD are the same

yuzs2000:
Hi mladen,i download your file ,but i still got the wrong MACD chart ,i was wondering if it works well in your machine ?
Files:
 

Hi mladen,thanks for your help!

one question please, what's mean of the below statement ? the indicatorFileName is MACDTest ,right ?

iCustom(symbol,0,indicatorFileName,"returnBars",0,0)

mladen:
It does

Here is how it looks on EURUSD chart

and here is how it looks on EURGBP chart

as you can see it shows the same MACD values on both charts (as it should). Also, if I change to any other symbol it stays the same (as it should, since it is supposed to show MACD for EURGBP with default settings)

And the last, it is EURGBP chart with that indicator (upper) and the built in MACD (lower). As you can see the values of the MACDTest and the built in MACD are the same

 

...

:):)

That is the "trick" It calls itself to find out how many bars of the target symbol has been changed (you will find a line in the init section that is saying :

indicatorFileName = WindowExpertName();

That line gets the name of the indicator regardless what is the name you have given it (so you do not have to remember it or to hard code it), and then calls itself to do what I explained above (and that way it avoid writing one external indicator)

yuzs2000:
Hi mladen,thanks for your help!

one question please, what's mean of the below statement ? the indicatorFileName is MACDTest ,right ?

iCustom(symbol,0,indicatorFileName,"returnBars",0,0)
 

...

yuzs2000

It is not a parameter name but a value. It is passing that value to the first parameter (symbol) of the target symbol and, when tha symbol parameter has the value of "returnBars" it does just one thing : writes the limit (number of bars that should be recalculated for the target symbol) to the first buffer. That value is then used in th MACDTest indicator to see how many bars actually has to be calculated.

The whole problem is that you have to know how many bars of a current symbol and how many bars of the target symbol have changed. If you do not calculate the greater number of the 2 then you get result what you were having. This is a "2 symbols talking to each other" sort of speaking, and it has to be done when you are calculating symbol other than the current chart symbol

yuzs2000:
Hi Mladen,sorry me again

Please , for the below indidator,why there is a parameter named "returnBars" ?what's the mean of it ? it is not a parameter of MACDTest,right ?

iCustom(symbol,0,indicatorFileName,"returnBars",0,0)
 

Hi Mladen,sorry me again

Please , for the below indidator,why there is a parameter named "returnBars" ?what's the mean of it ? it is not a parameter of MACDTest,right ?

iCustom(symbol,0,indicatorFileName,"returnBars",0,0)

Btw,i still got wrong chart,is there any other specify settings ?

mladen;:

That is the "trick" It calls itself to find out how many bars of the target symbol has been changed (you will find a line in the init section that is saying :

indicatorFileName = WindowExpertName();
That line gets the name of the indicator regardless what is the name you have given it (so you do not have to remember it or to hard code it), and then calls itself to do what I explained above (and that way it avoid writing one external indicator)
 

Dear Mladen,

please ,what's mean of this line code ? why does it try to compare symbol with "returnBars" ? should i attach another MACDTest with symbol="returnBars" on the current symbol?

returnBars = (symbol=="returnBars"); if (returnBars) return(0);

mladen:
yuzs2000

It is not a parameter name but a value. It is passing that value to the first parameter (symbol) of the target symbol and, when tha symbol parameter has the value of "returnBars" it does just one thing : writes the limit (number of bars that should be recalculated for the target symbol) to the first buffer. That value is then used in th MACDTest indicator to see how many bars actually has to be calculated.

The whole problem is that you have to know how many bars of a current symbol and how many bars of the target symbol have changed. If you do not calculate the greater number of the 2 then you get result what you were having. This is a "2 symbols talking to each other" sort of speaking, and it has to be done when you are calculating symbol other than the current chart symbol
Reason: