
#property indicator_chart_window

extern int     DaysToShow  = 30;
extern string  DailyStart  = "01:00";
extern string  DailyEnd    = "24:00";
extern color   DailyColor  = CLR_NONE;//DarkSlateBlue;

extern string  AsiaStart  = "03:00";
extern string  AsiaEnd    = "09:00";
extern color   AsiaColor  = SaddleBrown;

extern string  EurStart   = "10:00";
extern string  EurEnd     = "14:00";
extern color   EurColor   = CLR_NONE;//MediumSeaGreen;

extern string  USStart    = "14:00";
extern string  USEnd      = "18:00";
extern color   USColor    = CLR_NONE;

extern bool    DisplayBreakOuts   = true;
extern bool    ShowSolidRectangle = true;
extern int     Line_Style = 4;
extern int     Line_Width = 0;

int            move.sideways     = 0;
int            move.up.down      = 0;
int            Corner            = 2;
int            box.style         = 0;
int            box.width         = 1;
color          box.color         = Yellow;
bool           box.color.fill    = false;
//int            box.bar.size      = 5;
//int            box.offset        = 0;
string         buffer.name       = "Sessions: ";

int g_datetime_352;
int g_str2time_356;
int g_str2time_360;
int g_str2time_364;
int g_str2time_368;
int g_str2time_372;
int g_str2time_376;
int g_str2time_380;
int g_str2time_384;

int i;
int g_shift_392;
int g_shift_396;
int g_shift_400;
int g_shift_404;
int g_shift_408;
int g_shift_412;
int g_shift_416;
int g_shift_420;

int StartTime, EndTime;
double highest, lowest;

int g_shift_536;
int g_shift_540;
int g_shift_544;
int g_shift_548;

bool gi_552;
int gi_556;

int init() {
   DeleteObjects();
   for (i = 0; i < DaysToShow; i++) 
      {
      
      CreateObjects5("AS_REC" + i, AsiaColor);
      CreateObjects5("EU_REC" + i, EurColor);
      CreateObjects5("US_REC" + i, USColor);
      CreateObjects5("DA_REC" + i, DailyColor);
      }

   return (0);
}

int deinit() {
   DeleteObjects();
  
   return (0);
}

int start() {
   int l_ind_counted_0 = IndicatorCounted();
   g_datetime_352 = TimeCurrent();
   for (i = 0; i < DaysToShow; i++) 
      {
      DrawObjects5(g_datetime_352, "DA_REC" + i, DailyStart, DailyEnd,DailyColor);
      DrawObjects5(g_datetime_352, "AS_REC" + i, AsiaStart, AsiaEnd,AsiaColor);
      DrawObjects5(g_datetime_352, "EU_REC" + i, EurStart, EurEnd,EurColor);
      DrawObjects5(g_datetime_352, "US_REC" + i, USStart, USEnd,USColor);
      
      for (g_datetime_352 = decDateTradeDay(g_datetime_352); TimeDayOfWeek(g_datetime_352) > 5; g_datetime_352 = decDateTradeDay(g_datetime_352)) {
      }
  
   }
   
   return (0);
}


void CreateObjects5(string buffer, color a_color_8) 
{
   buffer=buffer.name+buffer;
   ObjectCreate(buffer, OBJ_RECTANGLE, 0, 0, 0);
   ObjectSet(buffer, OBJPROP_COLOR, a_color_8);
   ObjectSet(buffer, OBJPROP_WIDTH, 2);
   ObjectSet(buffer, OBJPROP_STYLE, STYLE_DOT);
   ObjectSet(buffer, OBJPROP_BACK, ShowSolidRectangle);
}

void DeleteObjects() {
   for (i = 0; i < DaysToShow; i++) 
      {
      ObjectDelete(buffer.name+"DA_REC" + i);
      ObjectDelete(buffer.name+"AS_REC" + i);
      ObjectDelete(buffer.name+"EU_REC" + i);
      ObjectDelete(buffer.name+"US_REC" + i);
      ObjectDelete("H "+buffer.name+"DA_REC" + i);
      ObjectDelete("H "+buffer.name+"AS_REC" + i);
      ObjectDelete("H "+buffer.name+"EU_REC" + i);
      ObjectDelete("H "+buffer.name+"US_REC" + i);
      ObjectDelete("L "+buffer.name+"DA_REC" + i);
      ObjectDelete("L "+buffer.name+"AS_REC" + i);
      ObjectDelete("L "+buffer.name+"EU_REC" + i);
      ObjectDelete("L "+buffer.name+"US_REC" + i);
      
   }
}

void DrawObjects5(int ai_0, string buffer, string as_12, string as_20,color Color) {
   StartTime = StrToTime(TimeToStr(ai_0, TIME_DATE) + " " + as_12);
   EndTime =   StrToTime(TimeToStr(ai_0, TIME_DATE) + " " + as_20);
   int endtime=StrToTime(TimeToStr(ai_0, TIME_DATE) + " " + DailyEnd);
   
   g_shift_536 = iBarShift(NULL, 0, StartTime - 60 * Period());
   g_shift_540 = iBarShift(NULL, 0, EndTime);
   
   highest = High[iHighest(NULL, 0, MODE_HIGH, g_shift_536 - g_shift_540, g_shift_540)] - 0.75 * Point;
   lowest =  Low[iLowest(NULL, 0, MODE_LOW, g_shift_536 - g_shift_540, g_shift_540)] + Point / 2.0;
  
   double percent.line = (highest-lowest)/6.66;
  
   buffer=buffer.name+buffer;
   ObjectSet(buffer, OBJPROP_TIME1, StartTime);
   ObjectSet(buffer, OBJPROP_PRICE1, highest);
   ObjectSet(buffer, OBJPROP_TIME2, EndTime);
   ObjectSet(buffer, OBJPROP_PRICE2, lowest);
   if(!DisplayBreakOuts)  return;
   
   Createline("H " +buffer,highest-percent.line,endtime,Color,2);
   Createline("L "+buffer,lowest+percent.line,endtime, Color,2);
}
void Createline(string buffer, double start,  int endtime, color Color, int width)
   {
   ObjectDelete(buffer);
   ObjectCreate(buffer, OBJ_TREND,   0, 0, 0);
   ObjectSet   (buffer, OBJPROP_STYLE,  box.style);
   ObjectSet   (buffer, OBJPROP_WIDTH,  width);
   ObjectSet   (buffer, OBJPROP_COLOR,  Color); 
   ObjectSet   (buffer, OBJPROP_RAY,    0);
   ObjectSet   (buffer, OBJPROP_BACK,   box.color.fill);
   ObjectSet   (buffer, OBJPROP_TIME1 , StartTime);
   ObjectSet   (buffer, OBJPROP_PRICE1, start);
   ObjectSet   (buffer, OBJPROP_TIME2 , endtime);
   ObjectSet   (buffer, OBJPROP_PRICE2, start);
   } 

int decDateTradeDay(int ai_0) {
   int li_4 = TimeYear(ai_0);
   int li_8 = TimeMonth(ai_0);
   int li_12 = TimeDay(ai_0);
   int l_hour_16 = TimeHour(ai_0);
   int l_minute_20 = TimeMinute(ai_0);
   li_12--;
   if (li_12 == 0) {
      li_8--;
      if (li_8 == 0) {
         li_4--;
         li_8 = 12;
      }
      if (li_8 == 1 || li_8 == 3 || li_8 == 5 || li_8 == 7 || li_8 == 8 || li_8 == 10 || li_8 == 12) li_12 = 31;
      if (li_8 == 2) {
         if (MathMod(li_4, 4) == 0.0) li_12 = 29;
         else li_12 = 28;
      }
      if (li_8 == 4 || li_8 == 6 || li_8 == 9 || li_8 == 11) li_12 = 30;
   }
   return (StrToTime(li_4 + "." + li_8 + "." + li_12 + " " + l_hour_16 + ":" + l_minute_20));
}

