//+------------------------------------------------------------------+
//|                                           Aliev market hours.mq4 |
//|                                                         eevviill |
//|                                        itisallillusion@gmail.com |
//+------------------------------------------------------------------+
#property copyright "eevviill"
#property link      "itisallillusion@gmail.com"

#property indicator_chart_window


extern int Hour_shift_from_broker = -2;

extern bool use_sound = true;
extern string sound = "alert2";

extern int Size = 14;
extern int Corner = 1;
extern color america_europ_color = Blue;
extern color america_color = Green;
extern color europ_asia_color = Purple;
extern color europ_color = Red;
extern color asia_pacific_color = Lime;
extern color asia_color = LightBlue;
extern color pacific_america_color = White;
extern color pacific_color = Maroon;

extern string c_t = "Candle_time";
extern bool use_candle_time = true;
extern int TF = 0;
extern color TimeColor = Orange;
extern int TimeFontSize = 10;
extern bool Display_moving_on_bid_line? = FALSE;
extern bool __Bracket_moving_display? = FALSE;
extern bool Display_fixed_on_chart? = TRUE;
extern bool __Bracket_fixed_display? = FALSE;
extern int __Show_in_chart_window_0123 = 0;
extern int __Show_in_window_corner_0123 = 1;
extern int ____Adjust_Vertical_Indent = 0;
extern int ____Adjust_Horizontal_Indent = 1;
extern string Change_heading_of_fixed_display = "Candle:";




string chek_change_session = "nch";

////////////////////
void init()
  {
if(TF==0) TF=Period();
}

////////////////////
void deinit()
  {
if(ObjectFind("ses1")!=-1)
ObjectDelete("ses1");
  
if(ObjectFind("end_ses")!=-1)
ObjectDelete("end_ses");

 string l_name_8;
   int l_objs_total_0 = ObjectsTotal();
   for (int l_objs_total_4 = l_objs_total_0; l_objs_total_4 >= 0; l_objs_total_4--) {
      l_name_8 = ObjectName(l_objs_total_4);
      if (StringSubstr(l_name_8, 0, 19) == "[CandleClockMoving]") ObjectDelete(l_name_8);
      if (StringSubstr(l_name_8, 0, 18) == "[CandleClockFixed]") ObjectDelete(l_name_8);
   }
  }




///////////////////
void start()
  {
  //chek sound
  if(use_sound)
  {
  if(chek_change_session!=chek_ses1())
  PlaySound(sound+".wav");
  }
   
  chek_change_session=chek_ses1();
  
  
  //session
if(ObjectFind("ses1")==-1)
{
ObjectCreate("ses1",OBJ_LABEL,0,0,0);
ObjectSet("ses1",OBJPROP_CORNER,Corner);
ObjectSet("ses1", OBJPROP_XDISTANCE,20);
ObjectSet("ses1", OBJPROP_YDISTANCE, 20);
}
 ObjectSetText("ses1",chek_ses1(),Size,"Arrial",chek_col());
 
 //end session
 if(ObjectFind("end_ses")==-1)
{
ObjectCreate("end_ses",OBJ_LABEL,0,0,0);
ObjectSet("end_ses",OBJPROP_CORNER,Corner);
ObjectSet("end_ses", OBJPROP_XDISTANCE,20);
ObjectSet("end_ses", OBJPROP_YDISTANCE, 48);
}
 ObjectSetText("end_ses",DoubleToStr(MathCeil(chek_to_end()),0)+":"+DoubleToStr(60-Minute(),0),Size,"Arrial",chek_col());
 
 
 //candle time
 if(use_candle_time)
 {
  string l_name_8;
   int li_84;
   int l_objs_total_0 = ObjectsTotal();
   for (int l_objs_total_4 = l_objs_total_0; l_objs_total_4 >= 0; l_objs_total_4--) {
      l_name_8 = ObjectName(l_objs_total_4);
      if (StringSubstr(l_name_8, 0, 19) == "[CandleClockMoving]") ObjectDelete(l_name_8);
      if (StringSubstr(l_name_8, 0, 18) == "[CandleClockFixed]") ObjectDelete(l_name_8);
   }
   double ld_16 = WindowPriceMax();
   double ld_24 = WindowPriceMin();
   double ld_32 = ld_16 - ld_24;
   double ld_40 = ld_32 / 50.0;
   double l_x_48 = ____Adjust_Horizontal_Indent;
   if (l_x_48 <= 0.0) l_x_48 = 1;
   double l_y_56 = ____Adjust_Vertical_Indent;
   if (l_y_56 <= 0.0) l_y_56 = 1;
   double l_time_64 = iTime(Symbol(),TF,0);
   double l_price_72 = iClose(Symbol(),TF,0) + ld_32 / 60.0;
   string ls_100 = "  ";
   string ls_108 = "  ";
   string ls_116 = "                         ";
   int li_96 = iTime(Symbol(),TF,0) + 60 * TF - TimeCurrent();
   int li_92 = li_96 % 60;
   string ls_124 = li_92;
   if (li_92 < 10) ls_124 = "0" + ls_124;
   int li_88 = (li_96 - li_96 % 60) / 60;
   for (int l_count_80 = 0; l_count_80 < 24; l_count_80++) {
      if (li_88 >= 60) {
         li_88 -= 60;
         li_84++;
      }
   }
   string ls_132 = li_88;
   if (li_88 < 10) ls_132 = "0" + ls_132;
   string ls_140 = li_84;
   if (li_84 < 10) ls_140 = "0" + ls_140;
   string ls_148 = ls_132 + ":" + ls_124;
   if (li_84 >= 1) {
      ls_148 = ls_140 + ":" + ls_132 + ":" + ls_124;
      ls_116 = ls_116 + "      ";
   }
   if (Display_fixed_on_chart? == TRUE) {
      if (__Bracket_fixed_display? == TRUE) {
         ls_100 = " [ ";
         ls_108 = " ]";
      }
      if (ObjectFind("[CandleClockFixed]") != 0) {
         ObjectCreate("[CandleClockFixed]", OBJ_LABEL, __Show_in_chart_window_0123, 0, 0);
         ObjectSet("[CandleClockFixed]", OBJPROP_CORNER, __Show_in_window_corner_0123);
         ObjectSet("[CandleClockFixed]", OBJPROP_XDISTANCE, l_x_48);
         ObjectSet("[CandleClockFixed]", OBJPROP_YDISTANCE, l_y_56);
         ObjectSetText("[CandleClockFixed]", Change_heading_of_fixed_display + ls_100 + ls_148 + ls_108, TimeFontSize, "Arial Bold", TimeColor);
      } else ObjectMove("[CandleClockFixed]", __Show_in_chart_window_0123, l_x_48, l_y_56);
   }
   if (Display_moving_on_bid_line? == TRUE) {
      if (__Bracket_moving_display? == TRUE) {
         ls_100 = "<  ";
         ls_108 = "  ";
      }
      if (ObjectFind("[CandleClockMoving]") != 0) {
         ObjectCreate("[CandleClockMoving]", OBJ_TEXT, 0, l_time_64, l_price_72);
         ObjectSetText("[CandleClockMoving]", ls_116 + ls_100 + ls_148 + ls_108, TimeFontSize, "Arial Bold", TimeColor);
      } else ObjectMove("[CandleClockMoving]", 0, l_time_64, l_price_72);
   }
 
 }
 
 
  }

//func
/////////////////////////////////////////////
string chek_ses1()
{
//america
if(Hour()>=14+Hour_shift_from_broker && Hour()<=23+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker)
return("American & European session");
if(Hour()>=14+Hour_shift_from_broker && Hour()<=23+Hour_shift_from_broker)
return("American session");

//europe
if(Hour()>=8+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker)
return("European & Asian session");
if(Hour()>=8+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker)
return("European session");

//asia
if(Hour()>=1+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker && Hour()<8+Hour_shift_from_broker)
return("Asian & Pacific session");
if(Hour()>=1+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker)
return("Asian session");

//pacific
if((Hour()>=21+Hour_shift_from_broker) || (Hour()<8+Hour_shift_from_broker) && Hour()<=23+Hour_shift_from_broker)
return("Pacific & American session");
if((Hour()>=21+Hour_shift_from_broker) || (Hour()<8+Hour_shift_from_broker))
return("Pacific session");
}

///////////////////////////////////////////////////////////
color chek_col()
{
//america
if(Hour()>=14+Hour_shift_from_broker && Hour()<=23+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker)
return(america_europ_color);
if(Hour()>=14+Hour_shift_from_broker && Hour()<=23+Hour_shift_from_broker)
return(america_color);

//europe
if(Hour()>=8+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker)
return(europ_asia_color);
if(Hour()>=8+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker)
return(europ_color);

//asia
if(Hour()>=1+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker && Hour()<8+Hour_shift_from_broker)
return(asia_pacific_color);
if(Hour()>=1+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker)
return(asia_color);

//pacific
if((Hour()>=21+Hour_shift_from_broker) || (Hour()<8+Hour_shift_from_broker) && Hour()<=23+Hour_shift_from_broker)
return(pacific_america_color);
if((Hour()>=21+Hour_shift_from_broker) || (Hour()<8+Hour_shift_from_broker))
return(pacific_color);
}

///////////////////////////////////////////////////////////
int chek_to_end()
{
//america
if(Hour()>=14+Hour_shift_from_broker && Hour()<=23+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker)
return((23+Hour_shift_from_broker)-Hour());
if(Hour()>=14+Hour_shift_from_broker && Hour()<=23+Hour_shift_from_broker)
return((23+Hour_shift_from_broker)-Hour());

//europe
if(Hour()>=8+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker)
return((18+Hour_shift_from_broker)-Hour());
if(Hour()>=8+Hour_shift_from_broker && Hour()<18+Hour_shift_from_broker)
return((18+Hour_shift_from_broker)-Hour());

//asia
if(Hour()>=1+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker && Hour()<8+Hour_shift_from_broker)
return((11+Hour_shift_from_broker)-Hour());
if(Hour()>=1+Hour_shift_from_broker && Hour()<11+Hour_shift_from_broker)
return((11+Hour_shift_from_broker)-Hour());

//pacific
if((Hour()>=21+Hour_shift_from_broker) || (Hour()<8+Hour_shift_from_broker) && Hour()<=23+Hour_shift_from_broker)
return((8+Hour_shift_from_broker)-Hour());
if((Hour()>=21+Hour_shift_from_broker) || (Hour()<8+Hour_shift_from_broker))
return((8+Hour_shift_from_broker)-Hour());
}


