When using the MACD indicator on the chart it shows 2 values - a Histogram and a Signal line.
If you use the iMACD() function to calculaute the MACD values you have 2 options - MODE_MAIN and MODE_SIGNAL.
I have always assumed thet MODE_MAIN represents the Histogram values.
Now to my dismay I discover that this is a fallacy! It represents the MACD values - of how it is calculated I have no idea! (But I can find out if I am interested)
My trading decisions are based on the MACD Histogram values (among others) and now I find out that if I use MODE_MAIN I get incorrect values.
It seems there is a way to use iCustom() with "iMACD" as the indicator name to get these values - or I have to write code to calculate these values.
Which is the best way? or can it be done with iMACD also?
If code is required is the following code correct?
simply:
double signal=iMACD(_Symbol, PERIOD_CURRENT, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, index); double main=iMACD(_Symbol, PERIOD_CURRENT, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, index); double histogram=signal-main;
Is histogram an Array here? I'd like to be able to iterate back over the histogram values similar to how we use CopyBuffer, is there a way to do this? Thanks.
CopyBuffer is for MQL5. This thread is MQL4.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When using the MACD indicator on the chart it shows 2 values - a Histogram and a Signal line.
If you use the iMACD() function to calculaute the MACD values you have 2 options - MODE_MAIN and MODE_SIGNAL.
I have always assumed thet MODE_MAIN represents the Histogram values.
Now to my dismay I discover that this is a fallacy! It represents the MACD values - of how it is calculated I have no idea! (But I can find out if I am interested)
My trading decisions are based on the MACD Histogram values (among others) and now I find out that if I use MODE_MAIN I get incorrect values.
It seems there is a way to use iCustom() with "iMACD" as the indicator name to get these values - or I have to write code to calculate these values.
Which is the best way? or can it be done with iMACD also?
If code is required is the following code correct?