Code Library / MACD

MQL4 MACD Histogram EA

Trade MACD histogram reversals for momentum entries.

Language: MQL4 · Category: MACD · Tags: MACD, histogram, MQL4, EA, momentum

Source code

input double Lots=0.1;
void OnTick() {
   double m0=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   double s0=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   double m1=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   double s1=iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   if((m1-s1)<=0&&(m0-s0)>0&&OrdersTotal()==0)
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"MACD");
   if((m1-s1)>=0&&(m0-s0)<0&&OrdersTotal()==0)
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"MACD");
}

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.

Related snippets