//+------------------------------------------------------------------+
//| MA 交叉报警.mq4 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
//---- buffers
double buy[],sell[];
extern int fast=20; extern int slow=50;
double LastAlertTime=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(0,buy);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
 SetIndexBuffer(1,sell);
SetIndexEmptyValue(1,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
for (int i=Bars-1;i>=0;i--)
{
if
(
(
iMA(NULL,0,fast,0,MODE_EMA,PRICE_CLOSE,i)<iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i)
&&
iMA(NULL,0,fast,0,MODE_EMA,PRICE_CLOSE,i+1)>iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i+1)
)
)
{
sell[i]=High[i]+2*Point;
if (i==1 && LastAlertTime!=Time[0])
{
Alert("Negative Cross");
LastAlertTime=Time[0];
}

}
if
(
(
iMA(NULL,0,fast,0,MODE_EMA,PRICE_CLOSE,i)>iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i)
&&
iMA(NULL,0,fast,0,MODE_EMA,PRICE_CLOSE,i+1)<iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i+1)
)
)
{
buy[i]=Low[i]-2*Point;
if (i==1 && LastAlertTime!=Time[0])
{
Alert("Positive Cross");
LastAlertTime=Time[0];
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+ |