Can someone help with MACD please?

Hello folks,

I have been learning the MQL4 programming lingo but came stuck at the MACD. The iMACD function, I know gets some stick, but its main problem for me is the values it returns. It will round everything up or down making values flatline when really the histogram is moving up… 0.00037 becomes 0.0004 and 0.00042 becomes 0.0004… Two very different values. Can anyone help with a solution?

I have tried using custom indicators but can’t seem to get them to work. If anyone can lend a hand here, I would much appreciate it. Any help welcome :slight_smile:

Thanks for reading.

Cappa

The problem isn’t with MT4, its your code. All double values have 16 digits of precision, but of course you only want to look at no more than 5. I don’t know how you displaying the values, but try something lkieDoubleToStr(MACDval, Digits) and that should work unless you are trying something else.

Thanks CodeMeister for your response…

My code is very basic…

double MACD3 = iMACD(currency, timeframe, fast_ema_period, slow_ema_period, signal_period, PRICE_CLOSE, 0, 2);
Alert("MACD3 Value is: ", MACD3);

This only displays 0.0003

Thanks for your piece of code… what should the Digits variable be?

C

Digits is a predefined MQL4 variable which will 2, 3, 4 or 5 depending on your broker (4/5 digit) and currency pair.