//+------------------------------------------------------------------+
//|                                                  HLine Alert.mq4 |
//+------------------------------------------------------------------+
#property copyright "raff1410@o2.pl"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  LimeGreen

extern int    MaPeriod       = 30;
extern int    MaMethod       = MODE_SMA;
extern int    MaPrice        = PRICE_CLOSE;
extern string LineName       = "MyLine1";
extern color  LineColor      = Gold; 
extern int    LineStyle      = STYLE_SOLID;
extern int    AlertPipRange  = 1;
extern string AlertWav       = "Sound Effect - Police Siren 02.wav";

double ma[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,ma);
   return(0);
}
int deinit() { return(0);}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   static datetime time = 0;
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //
   
   for(int i=limit; i>=0; i--) ma[i] = iMA(NULL,0,MaPeriod,0,MaMethod,MaPrice,i);
   if (LineName!="")
      ObjectCreate(LineName, OBJ_HLINE, 0, 0, Bid);
      ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
        
      double val =  ObjectGet( LineName, OBJPROP_PRICE1);
      double ma1 = ma[0]-val;
      double ma2 = ma[1]-val;
         Comment(ma1,"   ",ma2);
         if ((ma1*ma2)<0 && time !=Time[0])
         {
            time = Time[0];
            if (ma1>0)
                  Alert("Moving average crossed horizontal line up");
            else  Alert("Moving average crossed horizontal line down");
            PlaySound(AlertWav);
         }            
   return(0);
}

