//+------------------------------------------------------------------+
//|                                                 Hourly Lines.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


enum LW
{
   One = 1,
   Two = 2,
   Three = 3,
   Four = 4,
   Five = 5,
};   

// DEFAULT INPUTS : START
//-----------------------------------------------------
input int Historical_Days = 50;               // Historical days
  
input color  Line_01_Color = DodgerBlue;       // Line 1 Color 
input bool   Line_01_Visible = true;           // Line 1 Visible
input string Line_01_Time = "00:00";           // Line 1 Time
input LW     Line_01_Width = 2;                // Line 1 Width
input ENUM_LINE_STYLE Line_01_Style = 1;       // Line 1 Style

input color  Line_02_Color = DodgerBlue;       // Line 2 Color
input bool   Line_02_Visible = true;           // Line 2 Visible
input string Line_02_Time = "01:00";           // Line 2 Time 
input LW     Line_02_Width = 1;                // Line 2 Width
input ENUM_LINE_STYLE Line_02_Style = 2;       // Line 2 Style

input color  Line_03_Color = DodgerBlue;       // Line 3 Color
input bool   Line_03_Visible = true;           // Line 3 Visible
input string Line_03_Time = "02:00";           // Line 3 Time
input LW     Line_03_Width = 1;                // Line 3 Width
input ENUM_LINE_STYLE Line_03_Style = 2;       // Line 3 Style

input color  Line_04_Color = MediumOrchid;     // Line 4  Color
input bool   Line_04_Visible = true;           // Line 4 Visible
input string Line_04_Time = "03:00";           // Line 4 Time
input LW     Line_04_Width = 2;                // Line 4 Width
input ENUM_LINE_STYLE Line_04_Style = 1;       // Line 4 Style

input color  Line_05_Color = MediumOrchid;     // Line 5 Color
input bool   Line_05_Visible = true;           // Line 5 Visible
input string Line_05_Time = "04:00";           // Line 5 Time
input LW     Line_05_Width = 1;                // Line 5 Width
input ENUM_LINE_STYLE Line_05_Style = 2;       // Line 5 Style

input color  Line_06_Color = MediumOrchid;     // Line 6 Color
input bool   Line_06_Visible = true;           // Line 6 Visible 
input string Line_06_Time = "05:00";           // Line 6 Time
input LW     Line_06_Width = 1;                // Line 6 Width
input ENUM_LINE_STYLE Line_06_Style = 2;       // Line 6 Style 

input color  Line_07_Color = MediumOrchid;     // Line 7 Color
input bool   Line_07_Visible = true;           // Line 7 Visible 
input string Line_07_Time = "06:00";           // Line 7 Time
input LW     Line_07_Width = 1;                // Line 7 Width
input ENUM_LINE_STYLE Line_07_Style = 2;       // Line 7 Style 

input color  Line_08_Color = MediumOrchid;     // Line 8 Color
input bool   Line_08_Visible = true;           // Line 8 Visible 
input string Line_08_Time = "07:00";           // Line 8 Time
input LW     Line_08_Width = 1;                // Line 8 Width
input ENUM_LINE_STYLE Line_08_Style = 2;       // Line 8 Style 

input color  Line_09_Color = MediumOrchid;     // Line 9 Color
input bool   Line_09_Visible = true;           // Line 9 Visible 
input string Line_09_Time = "08:00";           // Line 9 Time
input LW     Line_09_Width = 1;                // Line 9 Width
input ENUM_LINE_STYLE Line_09_Style = 2;       // Line 9 Style 

input color  Line_10_Color = FireBrick;        // Line 10 Color
input bool   Line_10_Visible = true;           // Line 10 Visible 
input string Line_10_Time = "09:00";           // Line 10 Time
input LW     Line_10_Width = 2;                // Line 10 Width
input ENUM_LINE_STYLE Line_10_Style = 1;       // Line 10 Style 

input color  Line_11_Color = Blue;             // Line 11 Color
input bool   Line_11_Visible = true;           // Line 11 Visible 
input string Line_11_Time = "10:00";           // Line 11 Time
input LW     Line_11_Width = 2;                // Line 11 Width
input ENUM_LINE_STYLE Line_11_Style = 1;       // Line 11 Style 

input color  Line_12_Color = RosyBrown;        // Line 12 Color
input bool   Line_12_Visible = true;           // Line 12 Visible 
input string Line_12_Time = "11:00";           // Line 12 Time
input LW     Line_12_Width = 1;                // Line 12 Width
input ENUM_LINE_STYLE Line_12_Style = 2;       // Line 12 Style 

input color  Line_13_Color = RosyBrown;        // Line 13 Color
input bool   Line_13_Visible = true;           // Line 13 Visible 
input string Line_13_Time = "12:00";           // Line 13 Time
input LW     Line_13_Width = 1;                // Line 13 Width
input ENUM_LINE_STYLE Line_13_Style = 2;       // Line 13 Style 

input color  Line_14_Color = RosyBrown;        // Line 14 Color
input bool   Line_14_Visible = true;           // Line 14 Visible 
input string Line_14_Time = "13:00";           // Line 14 Time
input LW     Line_14_Width = 1;                // Line 14 Width
input ENUM_LINE_STYLE Line_14_Style = 2;       // Line 14 Style 

input color  Line_15_Color = RosyBrown;        // Line 15 Color
input bool   Line_15_Visible = true;           // Line 15 Visible 
input string Line_15_Time = "14:00";           // Line 15 Time
input LW     Line_15_Width = 1;                // Line 15 Width
input ENUM_LINE_STYLE Line_15_Style = 2;       // Line 15 Style 

input color  Line_16_Color = LightSteelBlue;   // Line 16 Color
input bool   Line_16_Visible = true;           // Line 16 Visible 
input string Line_16_Time = "15:00";           // Line 16 Time
input LW     Line_16_Width = 2;                // Line 16 idth
input ENUM_LINE_STYLE Line_16_Style = 1;       // Line 16 Style 

input color  Line_17_Color = LightSteelBlue;   // Line 17 Color
input bool   Line_17_Visible = true;           // Line 17 Visible 
input string Line_17_Time = "16:00";           // Line 17 Time
input LW     Line_17_Width = 1;                // Line 17 Width
input ENUM_LINE_STYLE Line_17_Style = 2;       // Line 17 Style 

input color  Line_18_Color = LightSteelBlue;   // Line 18 Color
input bool   Line_18_Visible = true;           // Line 18 Visible 
input string Line_18_Time = "17:00";           // Line 18 Time
input LW     Line_18_Width = 1;                // Line 18 Width
input ENUM_LINE_STYLE Line_18_Style = 2;       // Line 18 Style 

input color  Line_19_Color = LightSteelBlue;   // Line 19 Color
input bool   Line_19_Visible = true;           // Line 19 Visible 
input string Line_19_Time = "18:00";           // Line 19 Time
input LW     Line_19_Width = 1;                // Line 19 Width
input ENUM_LINE_STYLE Line_19_Style = 2;       // Line 19 Style 

input color  Line_20_Color = MediumSeaGreen;   // Line 20 Color
input bool   Line_20_Visible = true;           // Line 20 Visible 
input string Line_20_Time = "19:00";           // Line 20 Time
input LW     Line_20_Width = 2;                // Line 20 Width
input ENUM_LINE_STYLE Line_20_Style = 1;       // Line 20 Style 

input color  Line_21_Color = MediumSeaGreen;   // Line 21 Color
input bool   Line_21_Visible = true;           // Line 21 Visible 
input string Line_21_Time = "20:00";           // Line 21 Time
input LW     Line_21_Width = 1;                // Line 21 Width
input ENUM_LINE_STYLE Line_21_Style = 2;       // Line 21 Style 

input color  Line_22_Color = MediumSeaGreen;   // Line 22 Color
input bool   Line_22_Visible = true;           // Line 22 Visible 
input string Line_22_Time = "21:00";           // Line 22 Time
input LW     Line_22_Width = 1;                // Line 22 Width
input ENUM_LINE_STYLE Line_22_Style = 2;       // Line 22 Style 

input color  Line_23_Color = MediumSeaGreen;   // Line 23 Color
input bool   Line_23_Visible = true;           // Line 23 Visible 
input string Line_23_Time = "22:00";           // Line 23 Time
input LW     Line_23_Width = 1;                // Line 23 Width
input ENUM_LINE_STYLE Line_23_Style = 2;       // Line 23 Style 

input color  Line_24_Color = MediumSeaGreen;   // Line 24 Color
input bool   Line_24_Visible = true;           // Line 24 Visible 
input string Line_24_Time = "23:00";           // Line 24 Time
input LW     Line_24_Width = 1;                // Line 24 Width
input ENUM_LINE_STYLE Line_24_Style = 2;       // Line 24 Style 


//----------------------------------------------------- 
// DEFAULT INPUTS : END 

string T01_End = "Time_Line_01"; 
string T02_End = "Time_Line_02"; 
string T03_End = "Time_Line_03";  
string T04_End = "Time_Line_04"; 
string T05_End = "Time_Line_05";  
string T06_End = "Time_Line_06";    
string T07_End = "Time_Line_07";    
string T08_End = "Time_Line_08";    
string T09_End = "Time_Line_09";    
string T10_End = "Time_Line_10";    
string T11_End = "Time_Line_11";    
string T12_End = "Time_Line_12";    
string T13_End = "Time_Line_13";    
string T14_End = "Time_Line_14";    
string T15_End = "Time_Line_15";    
string T16_End = "Time_Line_16";    
string T17_End = "Time_Line_17";    
string T18_End = "Time_Line_18";    
string T19_End = "Time_Line_19";    
string T20_End = "Time_Line_20";    
string T21_End = "Time_Line_21";    
string T22_End = "Time_Line_22";    
string T23_End = "Time_Line_23";    
string T24_End = "Time_Line_24";  

int OnInit()
{
   DeleteObjects();
  for (int i=0; i<Historical_Days; i++) 
  {
     CreateObjects("T01"+ IntegerToString(i), Line_01_Color);
     ObjectSet("T01"+IntegerToString(i), OBJPROP_WIDTH, Line_01_Width);
     ObjectSet("T01"+IntegerToString(i), OBJPROP_STYLE, Line_01_Style);
     
     CreateObjects("T02"+IntegerToString(i), Line_02_Color);
     ObjectSet("T02"+IntegerToString(i), OBJPROP_WIDTH, Line_02_Width);
     ObjectSet("T02"+IntegerToString(i), OBJPROP_STYLE, Line_02_Style);
     
     CreateObjects("T03"+IntegerToString(i), Line_03_Color);
     ObjectSet("T03"+IntegerToString(i), OBJPROP_WIDTH, Line_03_Width);
     ObjectSet("T03"+IntegerToString(i), OBJPROP_STYLE, Line_03_Style);
     
     CreateObjects("T04"+IntegerToString(i), Line_04_Color);
     ObjectSet("T04"+IntegerToString(i), OBJPROP_WIDTH, Line_04_Width);
     ObjectSet("T04"+IntegerToString(i), OBJPROP_STYLE, Line_04_Style);
     
     CreateObjects("T05"+IntegerToString(i), Line_05_Color);
     ObjectSet("T05"+IntegerToString(i), OBJPROP_WIDTH, Line_05_Width);
     ObjectSet("T05"+IntegerToString(i), OBJPROP_STYLE, Line_05_Style);
     
     CreateObjects("T06"+IntegerToString(i), Line_06_Color);
     ObjectSet("T06"+IntegerToString(i), OBJPROP_WIDTH, Line_06_Width);
     ObjectSet("T06"+IntegerToString(i), OBJPROP_STYLE, Line_06_Style);
     
     CreateObjects("T07"+ IntegerToString(i), Line_07_Color);
     ObjectSet("T07"+IntegerToString(i), OBJPROP_WIDTH, Line_07_Width);
     ObjectSet("T07"+IntegerToString(i), OBJPROP_STYLE, Line_07_Style);

     CreateObjects("T08"+ IntegerToString(i), Line_08_Color);
     ObjectSet("T08"+IntegerToString(i), OBJPROP_WIDTH, Line_08_Width);
     ObjectSet("T08"+IntegerToString(i), OBJPROP_STYLE, Line_08_Style);
     
     CreateObjects("T09"+ IntegerToString(i), Line_09_Color);
     ObjectSet("T09"+IntegerToString(i), OBJPROP_WIDTH, Line_09_Width);
     ObjectSet("T09"+IntegerToString(i), OBJPROP_STYLE, Line_09_Style);
     
     CreateObjects("T10"+ IntegerToString(i), Line_10_Color);
     ObjectSet("T10"+IntegerToString(i), OBJPROP_WIDTH, Line_10_Width);
     ObjectSet("T10"+IntegerToString(i), OBJPROP_STYLE, Line_10_Style);
     
     CreateObjects("T11"+ IntegerToString(i), Line_11_Color);
     ObjectSet("T11"+IntegerToString(i), OBJPROP_WIDTH, Line_11_Width);
     ObjectSet("T11"+IntegerToString(i), OBJPROP_STYLE, Line_11_Style);
     
     CreateObjects("T12"+ IntegerToString(i), Line_12_Color);
     ObjectSet("T12"+IntegerToString(i), OBJPROP_WIDTH, Line_12_Width);
     ObjectSet("T12"+IntegerToString(i), OBJPROP_STYLE, Line_12_Style);
     
     CreateObjects("T13"+ IntegerToString(i), Line_13_Color);
     ObjectSet("T13"+IntegerToString(i), OBJPROP_WIDTH, Line_13_Width);
     ObjectSet("T13"+IntegerToString(i), OBJPROP_STYLE, Line_13_Style);
     
     CreateObjects("T14"+ IntegerToString(i), Line_14_Color);
     ObjectSet("T14"+IntegerToString(i), OBJPROP_WIDTH, Line_14_Width);
     ObjectSet("T14"+IntegerToString(i), OBJPROP_STYLE, Line_14_Style);
     
     CreateObjects("T15"+ IntegerToString(i), Line_15_Color);
     ObjectSet("T15"+IntegerToString(i), OBJPROP_WIDTH, Line_15_Width);
     ObjectSet("T15"+IntegerToString(i), OBJPROP_STYLE, Line_15_Style);
     
     CreateObjects("T16"+ IntegerToString(i), Line_16_Color);
     ObjectSet("T16"+IntegerToString(i), OBJPROP_WIDTH, Line_16_Width);
     ObjectSet("T16"+IntegerToString(i), OBJPROP_STYLE, Line_16_Style);
     
     CreateObjects("T17"+ IntegerToString(i), Line_17_Color);
     ObjectSet("T17"+IntegerToString(i), OBJPROP_WIDTH, Line_17_Width);
     ObjectSet("T17"+IntegerToString(i), OBJPROP_STYLE, Line_17_Style);
     
     CreateObjects("T18"+ IntegerToString(i), Line_18_Color);
     ObjectSet("T18"+IntegerToString(i), OBJPROP_WIDTH, Line_18_Width);
     ObjectSet("T18"+IntegerToString(i), OBJPROP_STYLE, Line_18_Style);
     
     CreateObjects("T19"+ IntegerToString(i), Line_19_Color);
     ObjectSet("T19"+IntegerToString(i), OBJPROP_WIDTH, Line_19_Width);
     ObjectSet("T19"+IntegerToString(i), OBJPROP_STYLE, Line_19_Style);
     
     CreateObjects("T20"+ IntegerToString(i), Line_20_Color);
     ObjectSet("T20"+IntegerToString(i), OBJPROP_WIDTH, Line_20_Width);
     ObjectSet("T20"+IntegerToString(i), OBJPROP_STYLE, Line_20_Style);
     
     CreateObjects("T21"+ IntegerToString(i), Line_21_Color);
     ObjectSet("T21"+IntegerToString(i), OBJPROP_WIDTH, Line_21_Width);
     ObjectSet("T21"+IntegerToString(i), OBJPROP_STYLE, Line_21_Style);
     
     CreateObjects("T22"+ IntegerToString(i), Line_22_Color);
     ObjectSet("T22"+IntegerToString(i), OBJPROP_WIDTH, Line_22_Width);
     ObjectSet("T22"+IntegerToString(i), OBJPROP_STYLE, Line_22_Style);
     
     CreateObjects("T23"+ IntegerToString(i), Line_23_Color);
     ObjectSet("T23"+IntegerToString(i), OBJPROP_WIDTH, Line_23_Width);
     ObjectSet("T23"+IntegerToString(i), OBJPROP_STYLE, Line_23_Style);
     
     CreateObjects("T24"+ IntegerToString(i), Line_24_Color);
     ObjectSet("T24"+IntegerToString(i), OBJPROP_WIDTH, Line_24_Width);
     ObjectSet("T24"+IntegerToString(i), OBJPROP_STYLE, Line_24_Style);
     
  }

   return(INIT_SUCCEEDED);
}

void deinit() 
{
  DeleteObjects();
}

void CreateObjects(string no, color cl)
{
  ObjectCreate(no, OBJ_VLINE, 0, 0,0, 0,0);
 // ObjectSet(no, OBJPROP_WIDTH, Line_Width_1_2_3_4_or_5);
 // ObjectSet(no, OBJPROP_STYLE, Line_Style);
  ObjectSet(no, OBJPROP_COLOR, cl);
  ObjectSet(no, OBJPROP_BACK, false);
}

void DeleteObjects() 
{
  for (int i=0; i<Historical_Days; i++) 
  {
    ObjectDelete("T01"+IntegerToString(i));
    ObjectDelete("T02"+IntegerToString(i));
    ObjectDelete("T03"+IntegerToString(i));
    ObjectDelete("T04"+IntegerToString(i));
    ObjectDelete("T05"+IntegerToString(i));
    ObjectDelete("T06"+IntegerToString(i));
    ObjectDelete("T07"+IntegerToString(i));
    ObjectDelete("T08"+IntegerToString(i));
    ObjectDelete("T09"+IntegerToString(i));
    ObjectDelete("T10"+IntegerToString(i));
    ObjectDelete("T11"+IntegerToString(i));
    ObjectDelete("T12"+IntegerToString(i));
    ObjectDelete("T13"+IntegerToString(i));
    ObjectDelete("T14"+IntegerToString(i));
    ObjectDelete("T15"+IntegerToString(i));
    ObjectDelete("T16"+IntegerToString(i));
    ObjectDelete("T17"+IntegerToString(i));
    ObjectDelete("T18"+IntegerToString(i));
    ObjectDelete("T19"+IntegerToString(i));
    ObjectDelete("T20"+IntegerToString(i));
    ObjectDelete("T21"+IntegerToString(i));
    ObjectDelete("T22"+IntegerToString(i));
    ObjectDelete("T23"+IntegerToString(i));
    ObjectDelete("T24"+IntegerToString(i));
  }
}

void DrawObjects(datetime dt, string no, string tb, string te) 
{
  datetime t1, t2;
  double   p1, p2;
  int      b1, b2;

  t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
  t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
  b1=iBarShift(NULL, 0, t1);
  b2=iBarShift(NULL, 0, t2);
  p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
  p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
  ObjectSet(no, OBJPROP_TIME1 , t1);
  ObjectSet(no, OBJPROP_PRICE1, p1);
  ObjectSet(no, OBJPROP_TIME2 , t2);
  ObjectSet(no, OBJPROP_PRICE2, p2);
}

datetime decDateTradeDay (datetime dt) 
{
  int ty=TimeYear(dt);
  int tm=TimeMonth(dt);
  int td=TimeDay(dt);
  int th=TimeHour(dt);
  int ti=TimeMinute(dt);

  td--;
  if (td==0) 
  {
    tm--;
    if (tm==0) 
    {
      ty--;
      tm=12;
    }
    if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
    if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;
    if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
  }
  return(StrToTime(IntegerToString(ty)+"."+IntegerToString(tm)+"."+IntegerToString(td)+" "+IntegerToString(th)+":"+IntegerToString(ti)));
}




int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
 {

   datetime dt=CurTime();

   for (int i=0; i<Historical_Days; i++) 
   {
      if(Line_01_Visible == true)
      {
         DrawObjects(dt, "T01"+IntegerToString(i), Line_01_Time, T01_End);
      }
      if(Line_02_Visible == true)
      {
         DrawObjects(dt, "T02"+IntegerToString(i), Line_02_Time, T02_End);
      }
      if(Line_03_Visible == true)
      {
         DrawObjects(dt, "T03"+IntegerToString(i), Line_03_Time, T03_End);
      }
      if(Line_04_Visible == true)
      {
         DrawObjects(dt, "T04"+IntegerToString(i), Line_04_Time, T04_End);
      }
      if(Line_05_Visible == true)
      {
         DrawObjects(dt, "T05"+IntegerToString(i), Line_05_Time, T05_End);
      }
      if(Line_06_Visible == true)
      {
         DrawObjects(dt, "T06"+IntegerToString(i), Line_06_Time, T06_End);
      }
      if(Line_07_Visible == true)
      {
         DrawObjects(dt, "T07"+IntegerToString(i), Line_07_Time, T07_End);
      }
      if(Line_08_Visible == true)
      {
         DrawObjects(dt, "T08"+IntegerToString(i), Line_08_Time, T08_End);
      }
      if(Line_09_Visible == true)
      {
         DrawObjects(dt, "T09"+IntegerToString(i), Line_09_Time, T09_End);
      }
      if(Line_10_Visible == true)
      {
         DrawObjects(dt, "T10"+IntegerToString(i), Line_10_Time, T10_End);
      }
      if(Line_11_Visible == true)
      {
         DrawObjects(dt, "T11"+IntegerToString(i), Line_11_Time, T11_End);
      }
      if(Line_12_Visible == true)
      {
         DrawObjects(dt, "T12"+IntegerToString(i), Line_12_Time, T12_End);
      }
      if(Line_13_Visible == true)
      {
         DrawObjects(dt, "T13"+IntegerToString(i), Line_13_Time, T13_End);
      }
      if(Line_14_Visible == true)
      {
         DrawObjects(dt, "T14"+IntegerToString(i), Line_14_Time, T14_End);
      }
      if(Line_15_Visible == true)
      {
         DrawObjects(dt, "T15"+IntegerToString(i), Line_15_Time, T15_End);
      }
      if(Line_16_Visible == true)
      {
         DrawObjects(dt, "T16"+IntegerToString(i), Line_16_Time, T16_End);
      }
      if(Line_17_Visible == true)
      {
         DrawObjects(dt, "T17"+IntegerToString(i), Line_17_Time, T17_End);
      }
      if(Line_18_Visible == true)
      {
         DrawObjects(dt, "T18"+IntegerToString(i), Line_18_Time, T18_End);
      }
      if(Line_19_Visible == true)
      {
         DrawObjects(dt, "T19"+IntegerToString(i), Line_19_Time, T19_End);
      }
      if(Line_20_Visible == true)
      {
         DrawObjects(dt, "T20"+IntegerToString(i), Line_20_Time, T20_End);
      }
      if(Line_21_Visible == true)
      {
         DrawObjects(dt, "T21"+IntegerToString(i), Line_21_Time, T21_End);
      }
      if(Line_22_Visible == true)
      {
         DrawObjects(dt, "T22"+IntegerToString(i), Line_22_Time, T22_End);
      }
      if(Line_23_Visible == true)
      {
         DrawObjects(dt, "T23"+IntegerToString(i), Line_23_Time, T23_End);
      }
      if(Line_24_Visible == true)
      {
         DrawObjects(dt, "T24"+IntegerToString(i), Line_24_Time, T24_End);
      }

        
      dt=decDateTradeDay(dt);
      while (TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
      
   }

   return(rates_total);
}

