#property copyright "Copyright 2010, Learn Forex Live"
#property link      "http://www.LearnForexLive.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue

double buf1[];
double buf2[];
double buf3[];
double buf_sell_signal[];
double buf_buyl_signal[];
extern int TimeFrame=0;
extern int ma_method = MODE_EMA;
extern int period= 6;
extern int shift = 0;
extern int applied_price= PRICE_CLOSE;
extern bool   alertsOn          = false;
extern bool   alertsOnCurrent   = false;
extern bool   alertsMessage     = true;
extern bool   alertsPushNotif   = false;
extern bool   alertsSound       = false;
extern bool   alertsEmail       = false;

double var_112;

string fileName;
int init() {
   IndicatorBuffers(5);
   SetIndexBuffer(0, buf1);
   SetIndexBuffer(1, buf2);
   SetIndexBuffer(2, buf_sell_signal);
   SetIndexBuffer(3, buf_buyl_signal);
   SetIndexArrow(2, 159);
   SetIndexArrow(3, 159);
   SetIndexStyle(0, DRAW_NONE, STYLE_SOLID, 4);
   SetIndexStyle(1, DRAW_NONE, STYLE_SOLID, 4);
   SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexBuffer(4, buf3);
   fileName = WindowExpertName();
   if (TimeFrame<Period()) TimeFrame=Period();
   var_112 = Point;
   if (Digits == 3 || Digits == 5) var_112 = 10.0 * Point;
   return (0);
}

int start() {

   if (TimeFrame!=Period())
   {
      for (int i = Bars - 10; i >= 0; i--)
      {
         int y = iBarShift(NULL,TimeFrame,Time[i]);
         int x = iBarShift(NULL,TimeFrame,Time[i+1]);
            if (x!=y)
            {
               buf_sell_signal[i] = iCustom(NULL,TimeFrame,fileName,0,ma_method,period,shift,applied_price,alertsOn,alertsOnCurrent,alertsMessage,alertsPushNotif,alertsSound,alertsEmail,2,y);
               buf_buyl_signal[i] = iCustom(NULL,TimeFrame,fileName,0,ma_method,period,shift,applied_price,alertsOn,alertsOnCurrent,alertsMessage,alertsPushNotif,alertsSound,alertsEmail,3,y);
            }
            else
            {
               buf_sell_signal[i] = EMPTY_VALUE;
               buf_buyl_signal[i] = EMPTY_VALUE;
            }
      }
      return(0);
   }
   for (i = Bars - 10; i >= 0; i--) buf3[i] = iMA(NULL, 0, period, shift, ma_method, applied_price, i);
   if (buf3[0] > buf3[1]) {
      buf1[0] = EMPTY_VALUE;
      buf2[0] = buf3[0];
   } else {
      if (buf3[0] < buf3[1]) {
         buf2[0] = EMPTY_VALUE;
         buf1[0] = buf3[0];
      }
   }
   for (int j = Bars - 10; j >= 0; j--) {
      buf1[j] = buf3[j];
      buf2[j] = buf3[j];
      if (buf3[j] > buf3[j + 1] && buf3[j + 1] > buf3[j + 2]) {
         buf1[j] = EMPTY_VALUE;
         buf1[j + 1] = EMPTY_VALUE;
         buf2[j + 1] = buf3[j + 1];
      } else {
         if (buf3[j] < buf3[j + 1] && buf3[j + 1] < buf3[j + 2]) {
            buf2[j] = EMPTY_VALUE;
            buf2[j + 1] = EMPTY_VALUE;
            buf1[j + 1] = buf3[j + 1];
         }
      }
   }
   for (j = Bars - 10; j > 0; j--) {
      if (buf1[j + 1] == EMPTY_VALUE && buf1[j] != EMPTY_VALUE && buf2[j + 1] != EMPTY_VALUE && buf2[j] == EMPTY_VALUE) {
         buf_sell_signal[j] = High[j] + 5.0 * var_112;
         buf_buyl_signal[j] = EMPTY_VALUE;
      } else {
         if (buf2[j + 1] == EMPTY_VALUE && buf2[j] != EMPTY_VALUE && buf1[j + 1] != EMPTY_VALUE && buf1[j] == EMPTY_VALUE) {
            buf_sell_signal[j] = EMPTY_VALUE;
            buf_buyl_signal[j] = Low[j] - 5.0 * var_112;
         }
      }
   }
   manageAlerts();
   return (0);
}

//-------------------------------------------------------------------
//                                                                  
//-------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;
      
      //
      //
      //
      //
      //
      
      static string   alertType1 = "";
      static datetime alertTime1 = 0;
      if (buf_buyl_signal[whichBar] != EMPTY_VALUE || buf_sell_signal[whichBar] != EMPTY_VALUE)
      {
         if (buf_sell_signal[whichBar] !=  EMPTY_VALUE)      doAlert(alertType1,alertTime1,"signal for sell");
         if (buf_buyl_signal[whichBar] !=  EMPTY_VALUE)      doAlert(alertType1,alertTime1,"signal for buy");
      }
   }
}

//
//
//
//
//

void doAlert(string& previousAlert, datetime& previousTime, string doWhat)
{
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[0]) {
       previousAlert  = doWhat;
       previousTime   = Time[0];

       //
       //
       //
       //
       //

       message =  StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," magic dots ",doWhat);
          if (alertsMessage)   Alert(message);
          if (alertsEmail)     SendMail(StringConcatenate(Symbol(),"magic dots"),message);
          if (alertsPushNotif) SendNotification(StringConcatenate(Symbol(),"magic dots - "+message));
          if (alertsSound)     PlaySound("alert2.wav");
   }
}
questo indicatore mt4 si basa su moving average?