Below is a link and the code to create a simple SMA moving average crossover in Metatrader.
//+——————————————————————+
//| Moving Average Cross Alert.mq4 |
//| Copyright © 2010, Jeremy Whittaker |
//| http://www.JeremyWhittaker.com |
//+——————————————————————+
#property copyright “Copyright © 2010, Jeremy Whittaker”
#property link “http://www.JeremyWhittaker.com”
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Aqua
#property indicator_color3 Red
#property indicator_color4 Aqua
//—- External Variables
extern int Period1 = 20;
extern int Period2 = 100;
extern bool Email = True;
//—- Indicators
int nShift, digit, digits;
int i,j,limit,counted_bars;
//—- Buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+——————————————————————+
//| Custom indicator initialization function |
//+——————————————————————+
int init()
{
//—- Draw Lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//—- Draw Arrows
SetIndexStyle(2, DRAW_ARROW, 0, 1); // Fleche vers le haut
SetIndexArrow(2, 233);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3, DRAW_ARROW, 0, 1); // Fleche vers le bas
SetIndexArrow(3, 234);
SetIndexBuffer(3, ExtMapBuffer4);
//—-
watermark();
//—-
return(0);
}
//+——————————————————————+
//| Custom indicator deinitialization function |
//+——————————————————————+
int deinit()
{
//—-
//—-
return(0);
}
//+——————————————————————+
//| Custom indicator iteration function |
//+——————————————————————+
int start()
{
double Ma1,Ma2, Ma1Previous, Ma2Previous;
counted_bars=IndicatorCounted();
//—-
if(counted_bars<0)
return(-1);
if(counted_bars>0)
counted_bars–;
limit=Bars-counted_bars;
for(i=0; i
Ma1=iMA(NULL,0,Period1,0,MODE_SMA,PRICE_CLOSE,i);
Ma1Previous=iMA(NULL,0,Period1,0,MODE_SMA,PRICE_CLOSE,i+1);
ExtMapBuffer1[i]=Ma1;
Ma2=iMA(NULL,0,Period2,0,MODE_SMA,PRICE_CLOSE,i);
Ma2Previous=iMA(NULL,0,Period2,0,MODE_SMA,PRICE_CLOSE,i+1);
ExtMapBuffer2[i]=Ma2;
}
if(Ma1>Ma2 && Ma1Previous
if(NewBar()==true)
{
ExtMapBuffer3[0] = Low[0] - iATR(Symbol(),0,10,0)*0.25;
Alert("Long Trade setup coming ",Period1, " has just crossed above ",Period2,". The current Price ",Close[1]," for ", Symbol(),"-",Period());
PlaySound("alert.wav");
if (Email)
{
SendMail("Long Trade setup confirmed", "Trade setup confirmed "+DoubleToStr(Ma1, digits)+" has just crossed above "+DoubleToStr(Ma2, digits)+" for "+Symbol()+"-"+Period());
}
}
}
if(Ma1
{
if(NewBar()==true)
{
ExtMapBuffer4[0] = High[0] + iATR(Symbol(),0,10,0)*0.25;
if(NewBar()==true)
{
Alert(“Short Trade setup coming “,Period1, ” has just crossed below “,Period2,”. The current Price “,Close[1],” for “, Symbol(),”-”,Period());
PlaySound(“alert.wav”);
if (Email)
{
SendMail(“Short Trade setup confirmed”, “Trade setup confirmed “+DoubleToStr(Ma1, digits)+” has just crossed below “+DoubleToStr(Ma2, digits)+” for “+Symbol()+”-”+Period());
}
}
}
}
//—-
return(0);
}
//+——————————————————————+
void watermark()
{
ObjectCreate(“JeremyWhittaker”, OBJ_LABEL, 0, 0, 0);
ObjectSetText(“JeremyWhittaker”, “JeremyWhittaker.com”, 8, “Arial”, RoyalBlue);
ObjectSet(“JeremyWhittaker”, OBJPROP_CORNER, 2);
ObjectSet(“JeremyWhittaker”, OBJPROP_XDISTANCE, 5);
ObjectSet(“JeremyWhittaker”, OBJPROP_YDISTANCE, 10);
return(0);
}
bool NewBar()
{
static datetime lastbar;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return(false);
}
}

It gives error while compiling. counted_bars- and Ma1Ma2Previous undefined. Hope you will correct them soon.
You must be doing something wrong I just downloaded from the MQ4 link and compiled perfectly fine. This is MT4 code fyi.