//+------------------------------------------------------------------+
//|                         Custom ma-alert.mq4                      |
//|                      Copyright 2007, °µÐäÓ¯Ïã                    |
//|                 ÁìÓòÍâ»ãÂÛÌ³   http://www.fxxxt.cn               |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 3
#property indicator_width2 3

extern int       FastEMA = 5;
extern int       SlowEMA = 13;
extern int       SignalSMA = 1;
extern int       ARROWWIDTH = 3;

double buy[];
double sell[];
double m;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,EMPTY,3,Magenta);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,buy);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,3,Magenta);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,sell);
   SetIndexEmptyValue(1,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  double Macd0,Macd1;
  for (int i = Bars - 1; i >= 0; i --)
  {
    Macd0 = iMACD(NULL , 0 , FastEMA , SlowEMA ,SignalSMA , PRICE_CLOSE , MODE_MAIN , i);
    Macd1 = iMACD(NULL , 0 , FastEMA , SlowEMA ,SignalSMA , PRICE_CLOSE , MODE_MAIN , i+1);
    buy [i] = 0; sell [i] = 0;
    if (Macd0 > 0 && Macd1 < 0)
    {
      buy [i] = Low [i] - 5 * Point;
      if (Period () >= PERIOD_M30) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_H1) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_H4) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_D1) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_W1) buy [i] -= 12 * Point;
      if (Period () >= PERIOD_MN1) buy [i] -= 60 * Point;
    }
    if (Macd0 < 0 && Macd1 > 0)
    {
      sell [i] = High [i] + 5 * Point;
      if (Period () >= PERIOD_M30) sell [i] += 8 * Point;
      if (Period () >= PERIOD_H1) sell [i] += 8 * Point;
      if (Period () >= PERIOD_H4) sell [i] += 8 * Point;
      if (Period () >= PERIOD_D1) sell [i] += 8 * Point;
      if (Period () >= PERIOD_W1) sell [i] += 12 * Point;
      if (Period () >= PERIOD_MN1) sell [i] += 60 * Point;
    }     
  }
return(0);
}