Hi all
I'm new to MQL. I apologise in advance if I'm asking a question that has probably been answered lots of times already, I have looked around on the forum trying to find what I need.
Simply, I'd like a snippet of code the calculates MACD and the Signal properly using EMA not the function built in to MQL that uses SMA and gives slightly different output. Is there a way to quickly do this within my own EA script without referencing out to someone elses MACD indicator?
or is it possible to do it slightly differently, and code a MACD indicator in my own script so something is displayed, and I can use the MACD variables from that, and use the rest of my EA script to do the other stuff such as order placement etc.
hi guys
thanks for replies. I was trying to avoid iMACD as I had read around various places saying that it wasn't right (which surprised me!) and plenty of people saying they use different calculation, its disappointing as I'd like to use the built in functions as much as possible
I have this code: MACD = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
this gives me a MACD of -4.1935 on a 15 minute chart
if I look in another charting package, exact same price and based on 15 minute chart I get -23.1266 as the macd!
so something isn't quite right there.
Id like to pull out:
MACD
MACD Signal
MACD histogram (e.g. positive or negative number above or below zero line)
I tried the code snippet found in https://www.metatrader5.com/en/terminal/help/indicators/oscillators/macd but the compiler complained that CLOSE was an undeclared variable, do I need to do an include on Momentum.mq4 somehow, to make use of the code?
thanks,
Ian
(UK)
hi guys
I tried the code snippet found in https://www.metatrader5.com/en/terminal/help/indicators/oscillators/macd but the compiler complained that CLOSE was an undeclared variable, do I need to do an include on Momentum.mq4 somehow, to make use of the code?
I'm still having some trouble with this, could someone paste some code I could use please? I know you pointed out that link, but Im unsure how to use it as it's an indicator, and Im not too troubled about displaying anything (but would look better I suppose), but how can I access the MACD calculation function from my own code?
I wish metaquotes iMACD gave the same output as other MACD charting does, would make this a lot easier. Cant see why the numbers are slightly out on their implementation.
I'm still having some trouble with this, could someone paste some code I could use please? I know you pointed out that link, but Im unsure how to use it as it's an indicator, and Im not too troubled about displaying anything (but would look better I suppose), but how can I access the MACD calculation function from my own code?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all
I'm new to MQL. I apologise in advance if I'm asking a question that has probably been answered lots of times already, I have looked around on the forum trying to find what I need.
Simply, I'd like a snippet of code the calculates MACD and the Signal properly using EMA not the function built in to MQL that uses SMA and gives slightly different output. Is there a way to quickly do this within my own EA script without referencing out to someone elses MACD indicator?
or is it possible to do it slightly differently, and code a MACD indicator in my own script so something is displayed, and I can use the MACD variables from that, and use the rest of my EA script to do the other stuff such as order placement etc.
thanks