Code Library / MACD
MQL4 MACD Multi-TF
Multi-timeframe MACD confluence across M15, H1, H4.
Language: MQL4 · Category: MACD · Tags: MACD, multi-timeframe, MQL4, confluence, MTF
Source code
int MACDDir(int tf) {
double m=iMACD(Symbol(),tf,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
double s=iMACD(Symbol(),tf,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
return (m-s)>0?1:-1;
}
int MTFConfluence() {
int m15=MACDDir(PERIOD_M15),h1=MACDDir(PERIOD_H1),h4=MACDDir(PERIOD_H4);
if(m15==1&&h1==1&&h4==1) return 2;
if(m15==-1&&h1==-1&&h4==-1) return -2;
return 0;
}How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL4 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.