//EU Session-Day H_Line + Alerts 
#property copyright "Copyright © 2014, File45"
#property link      "http: //codebase.mql4.com/en/author/file45"
#property indicator_chart_window
#property strict

extern string Start_Time = "8:00";
extern string End_Time = "23:58";
extern color  Base_Line_Color = DodgerBlue;
extern bool   Extend_Lines = false;
extern bool   Show_Target_Lines = true;
extern color  Long_Target_Color = Green;
extern color  Short_Target_Color = Red;
extern int    Long_Target = 420;
extern int    Short_Target = 420;
extern int    Line_Width = 2;
extern int    Line_Style = 1;

extern string ALERTS = "* * * ALERTS * * * ";
extern bool   Push_Notifications = false;
extern bool   Base_Line_cross = false;
extern int    Base_cross_max_count = 5;
extern bool   Long_Target_cross = false;
extern int    Long_Target_cross_max_count = 5;
extern bool   Short_Target_cross = false;
extern int    Short_Target_cross_max_count = 5;

int Base_Line_OBJ, Long_Target_OBJ, Short_Target_OBJ, i;

string TM;

int Count=0;

int init()
{
   switch(Extend_Lines)
   {
      case 0: Base_Line_OBJ = OBJ_TREND;
              Long_Target_OBJ = OBJ_TREND;
              Short_Target_OBJ = OBJ_TREND; break;
      case 1: Base_Line_OBJ = OBJ_HLINE;
              Long_Target_OBJ = OBJ_HLINE; 
              Short_Target_OBJ = OBJ_HLINE; break;
   }   
   
   switch(Period())
   {    
      case 1:     TM = "M1";  break;
      case 5:     TM = "M5";  break;
      case 15:    TM = "M15"; break;
      case 30:    TM = "M30"; break;
      case 60:    TM = "H1";  break;
      case 240:   TM = "H4";  break;
      case 1440:  TM = "D1";  break;
      case 10080: TM = "W1";  break;
      case 43200: TM = "MN";  break;
   }     
    
   return(0);
}

int deinit()
{
   ObjectDelete("BLEZ");
   ObjectDelete("LTEZ");
   ObjectDelete("STEZ");
   
   return(0);
}

int start()
{ 
   datetime start_time = StrToTime(Start_Time);
   datetime end_time = StrToTime(End_Time);
   
   int shift_start_time = iBarShift(Symbol(),0,start_time);
   
   double base_open = iOpen(Symbol(), 0, shift_start_time);
   double base_open_long_target = iOpen(Symbol(), 0, shift_start_time) + Long_Target*Point;
   double base_open_short_target = iOpen(Symbol(), 0, shift_start_time) - Short_Target*Point;
   
 
   ObjectCreate(0,"BLEZ", Base_Line_OBJ, 0, 0, 0, 0, 0); 
   ObjectSet("BLEZ", OBJPROP_COLOR, Base_Line_Color);
   ObjectSet("BLEZ", OBJPROP_WIDTH, Line_Width);
   ObjectSet("BLEZ", OBJPROP_STYLE, Line_Style);
   ObjectSet("BLEZ", OBJPROP_TIME1, start_time);
   ObjectSet("BLEZ", OBJPROP_TIME2, end_time);
   ObjectSet("BLEZ", OBJPROP_PRICE1, Open[shift_start_time]);
   ObjectSet("BLEZ", OBJPROP_PRICE2, Open[shift_start_time]);
   ObjectSet("BLEZ", OBJPROP_RAY, false);
      
   if(Show_Target_Lines == true)
   {
      ObjectCreate(0, "LTEZ", Long_Target_OBJ, 0, 0, 0, 0, 0); 
      ObjectSet("LTEZ", OBJPROP_COLOR, Long_Target_Color);
      ObjectSet("LTEZ", OBJPROP_WIDTH, Line_Width);
      ObjectSet("LTEZ", OBJPROP_STYLE, Line_Style);
      ObjectSet("LTEZ", OBJPROP_TIME1, start_time);
      ObjectSet("LTEZ", OBJPROP_TIME2, end_time);
      ObjectSet("LTEZ", OBJPROP_PRICE1, base_open_long_target );
      ObjectSet("LTEZ", OBJPROP_PRICE2, base_open_long_target );
      ObjectSet("LTEZ", OBJPROP_RAY, false);
      
      ObjectCreate(0, "STEZ", Short_Target_OBJ, 0, 0, 0, 0, 0); 
      ObjectSet("STEZ", OBJPROP_COLOR, Short_Target_Color);
      ObjectSet("STEZ", OBJPROP_WIDTH, Line_Width);
      ObjectSet("STEZ", OBJPROP_STYLE, Line_Style);
      ObjectSet("STEZ", OBJPROP_TIME1, start_time);
      ObjectSet("STEZ", OBJPROP_TIME2, end_time);
      ObjectSet("STEZ", OBJPROP_PRICE1, base_open_short_target );
      ObjectSet("STEZ", OBJPROP_PRICE2, base_open_short_target );
      ObjectSet("STEZ", OBJPROP_RAY, false);   
   }
   
   // Alerts 
      
   double Price = Bid;
   Count++; 
   
   double b_blag = (Bid < base_open && Ask > base_open);
   double b_blal = (Bid < base_open && Ask < base_open);
   double b_bgag = (Bid > base_open && Ask > base_open);
   
   double tl_blag = (Bid < base_open_long_target && Ask > base_open_long_target);
   double tl_blal = (Bid < base_open_long_target && Ask < base_open_long_target);
   double tl_bgag = (Bid > base_open_long_target && Ask > base_open_long_target);
   
   double ts_blag = (Bid < base_open_short_target && Ask > base_open_short_target);
   double ts_blal = (Bid < base_open_short_target && Ask < base_open_short_target);
   double ts_bgag = (Bid > base_open_short_target && Ask > base_open_short_target);
   
   double bt = TimeCurrent() > start_time && TimeCurrent() < end_time;
   
   if(((b_blal || b_bgag) && (!tl_blag || !ts_blag)) && ((tl_blal || tl_bgag) && (!b_blag || !ts_blag)) && ((ts_blal || ts_bgag) && (!b_blag || !tl_blag)) )
   {
      Count = 0;
   }     
   
   if(Base_Line_cross == true && Extend_Lines == false && b_blag && bt ) 
   {
      if(Count <= Base_cross_max_count)
      {
         Alert("Base cross - #",Count,"  ",Symbol(),"  ", TM,"  ",Price, "  ",AccountCompany());
         if (Push_Notifications == true)
         {
         SendNotification(Symbol() + " " + TM + "\n" +
         "Base cross: " + TimeToStr(TimeCurrent(), TIME_SECONDS)+ "  " + TimeToStr(TimeCurrent(), TIME_DATE) + "  " + AccountCompany()); 
         }
      }
      
   }    
   else if(Base_Line_cross == true && Extend_Lines == true && b_blag) 
   {
      if(Count <= Base_cross_max_count)
      {
         Alert("Base cross - #",Count,"  ",Symbol(),"  ", TM,"  ",Price, "  ",AccountCompany());
         if (Push_Notifications == true)
         {
         SendNotification(Symbol() + " " + TM + "\n" +
         "Base cross: " + TimeToStr(TimeCurrent(), TIME_SECONDS)+ "  " + TimeToStr(TimeCurrent(), TIME_DATE) + "  " + AccountCompany()); 
         }
      }
   }  
   
   if(Show_Target_Lines == true)
   {
      if(Long_Target_cross == true && Extend_Lines == false && tl_blag && bt) 
      {
         if(Count <= Long_Target_cross_max_count)
         {
            Alert("Long Target cross - #",Count,"  ",Symbol(),"  ", TM,"  ",Price, "  ",AccountCompany());
            if (Push_Notifications == true)
            {
               SendNotification(Symbol() + " " + TM + "\n" +
               "LT cross: " + TimeToStr(TimeCurrent(), TIME_SECONDS)+ "  " + TimeToStr(TimeCurrent(), TIME_DATE) + "  " + AccountCompany()); 
            }
         }
      }
      else if(Long_Target_cross == true && Extend_Lines == true && tl_blag) 
      {
         if(Count <= Long_Target_cross_max_count)
         {
            Alert("Long Target cross - #",Count,"  ",Symbol(),"  ", TM,"  ",Price, "  ",AccountCompany());
            if (Push_Notifications == true)
            {
               SendNotification(Symbol() + " " + TM + "\n" +
               "LT cross: " + TimeToStr(TimeCurrent(), TIME_SECONDS)+ "  " + TimeToStr(TimeCurrent(), TIME_DATE) + "  " + AccountCompany()); 
            }
         }
      }    
   
      if(Short_Target_cross == true && Extend_Lines == false && ts_blag && bt) 
      {
         if(Count <= Short_Target_cross_max_count)
         {
            Alert("Short Target cross - #",Count,"  ",Symbol(),"  ", TM,"  ",Price, "  ",AccountCompany());
            if (Push_Notifications == true)
            {
               SendNotification(Symbol() + " " + TM + "\n" +
               "ST cross: " + TimeToStr(TimeCurrent(), TIME_SECONDS)+ "  " + TimeToStr(TimeCurrent(), TIME_DATE) + "  " + AccountCompany()); 
            }
         }
      }  
      else if(Short_Target_cross == true && Extend_Lines == true && ts_blag) 
      {
         if(Count <= Short_Target_cross_max_count)
         {
            Alert("Short Target cross - #",Count,"  ",Symbol(),"  ", TM,"  ",Price, "  ",AccountCompany());
            if (Push_Notifications == true)
            {
               SendNotification(Symbol() + " " + TM + "\n" +
               "ST cross: " + TimeToStr(TimeCurrent(), TIME_SECONDS)+ "  " + TimeToStr(TimeCurrent(), TIME_DATE) + "  " + AccountCompany()); 
            }
         }
      }  
   }         
   
   
  /* if(TimeToStr(TimeCurrent(),TIME_MINUTES) == Start_Time)
   {
      
      Alert("Current time is ", TimeToStr(TimeCurrent()));
      return(0);
   }*/
 
  
  
  return(0);
}
 