Code Library / Entry Signals

Moving Average Cross EA

MQL5 EA that trades on EMA crossovers.

Language: MQL5 · Category: Entry Signals · Tags: MA crossover, EMA, MQL5

Source code

#include <Trade/Trade.mqh>
CTrade trade;
input int FastMA=10; input int SlowMA=50;
int fH,sH; double fB[],sB[];
int OnInit(){fH=iMA(_Symbol,0,FastMA,0,MODE_EMA,PRICE_CLOSE);sH=iMA(_Symbol,0,SlowMA,0,MODE_EMA,PRICE_CLOSE);return 0;}
void OnTick(){CopyBuffer(fH,0,0,3,fB);CopyBuffer(sH,0,0,3,sB);if(fB[1]>sB[1]&&fB[2]<=sB[2])trade.Buy(0.1);}

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own MQL5 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