/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright @ Rita Lasker"
#property link      "http://www.ritalasker.com"

#property indicator_chart_window

#include <WinUser32.mqh>

#import "kernel32.dll"
   void GetSystemTime(int& a0[]);
#import

bool gi_76 = TRUE;
int gi_80 = 2;
int gi_84 = 50;
string gs_88 = "07:00";
string gs_96 = "10:00";
extern color BoxColor = DodgerBlue;
string gs_108 = "2015.08.01";
int gi_116 = 31;
double gd_120;
double gd_128;
int gi_136;
bool gi_140 = TRUE;

void init() {
   if (gs_108 != "") {
      if (TimeCurrent() > StrToTime(gs_108) + 86400 * gi_116) {
         Alert("Your version is expired!");
         Comment("Your version is expired!");
         gi_140 = FALSE;
         return;
      }
   }
   DeleteObjects();
   gi_140 = TRUE;
   for (int l_count_0 = 0; l_count_0 < gi_84; l_count_0++) CreateObjects("Box" + l_count_0, BoxColor);
   gd_128 = Point;
   if (Digits == 5 || Digits == 3) gd_128 = 10.0 * gd_128;
   switch (Period()) {
   case PERIOD_M1:
      gd_120 = 7;
      break;
   case PERIOD_M5:
      gd_120 = 10;
      break;
   case PERIOD_M15:
      gd_120 = 12;
      break;
   case PERIOD_M30:
      gd_120 = 18;
      break;
   case PERIOD_H1:
      gd_120 = 21;
      break;
   case PERIOD_H4:
      gd_120 = 24;
      break;
   case PERIOD_D1:
      gd_120 = 27;
      break;
   case PERIOD_W1:
      gd_120 = 30;
      break;
   case PERIOD_MN1:
      gd_120 = 33;
   }
   gd_120 *= gd_128;
}

void deinit() {
   DeleteObjects();
   Comment("");
}

void CreateObjects(string a_name_0, color a_color_8) {
   ObjectCreate(a_name_0, OBJ_RECTANGLE, 0, 0, 0, 0, 0);
   ObjectSet(a_name_0, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_8);
   ObjectSet(a_name_0, OBJPROP_BACK, TRUE);
   ObjectCreate("H" + a_name_0, OBJ_TEXT, 0, 0, 0, 0);
   ObjectCreate("L" + a_name_0, OBJ_TEXT, 0, 0, 0, 0);
}

void DeleteObjects() {
   string l_name_8;
   int l_objs_total_0 = ObjectsTotal();
   for (int li_4 = l_objs_total_0 - 1; li_4 >= 0; li_4--) {
      l_name_8 = ObjectName(li_4);
      if (StringFind(l_name_8, "Box", 0) >= 0) ObjectDelete(l_name_8);
   }
}

void start() {
   int l_datetime_0;
   if (gi_140) {
      if (gs_108 != "") {
         if (TimeCurrent() > StrToTime(gs_108) + 86400 * gi_116) {
            Alert("Your version is expired!");
            Comment("Your version is expired!");
            gi_140 = FALSE;
            return;
         }
      }
      if (IsTesting()) {
         if (gi_76) {
            MessageBoxA(0, "AutoTimeSettings should be (false) at the test mode. Using ManualGMT_Offset", "Error", 0);
            gi_140 = FALSE;
            return;
         }
         gi_136 = gi_80;
      }
      gi_136 = gi_80;
      if (gi_76) gi_136 = get_UTC_OFFSET();
      l_datetime_0 = TimeCurrent();
      for (int l_count_4 = 0; l_count_4 < gi_84; l_count_4++) {
         DrawObjects(l_datetime_0, "Box" + l_count_4, TimeToStr(StrToTime(gs_88) + 3600 * gi_136, TIME_MINUTES), TimeToStr(StrToTime(gs_96) + 3600 * gi_136, TIME_MINUTES));
         for (l_datetime_0 = decDateTradeDay(l_datetime_0); TimeDayOfWeek(l_datetime_0) > 5; l_datetime_0 = decDateTradeDay(l_datetime_0)) {
         }
      }
      Comment("GMT_Offset = " + gi_136);
   }
}

void DrawObjects(int ai_0, string a_name_4, string as_12, string as_20) {
   int l_str2time_28 = StrToTime(StringConcatenate(TimeToStr(ai_0, TIME_DATE), " ", as_12));
   int l_str2time_32 = StrToTime(StringConcatenate(TimeToStr(ai_0, TIME_DATE), " ", as_20));
   int l_shift_52 = iBarShift(NULL, 0, l_str2time_28);
   int l_shift_56 = iBarShift(NULL, 0, l_str2time_32);
   double l_high_36 = High[iHighest(NULL, 0, MODE_HIGH, l_shift_52 - l_shift_56, l_shift_56)];
   double l_low_44 = Low[iLowest(NULL, 0, MODE_LOW, l_shift_52 - l_shift_56, l_shift_56)];
   ObjectSet(a_name_4, OBJPROP_TIME1, l_str2time_28);
   ObjectSet(a_name_4, OBJPROP_PRICE1, l_high_36);
   ObjectSet(a_name_4, OBJPROP_TIME2, l_str2time_32);
   ObjectSet(a_name_4, OBJPROP_PRICE2, l_low_44);
   ObjectSet("H" + a_name_4, OBJPROP_TIME1, l_str2time_32);
   ObjectSet("H" + a_name_4, OBJPROP_PRICE1, l_high_36 + gd_120);
   ObjectSet("L" + a_name_4, OBJPROP_TIME1, l_str2time_32);
   ObjectSet("L" + a_name_4, OBJPROP_PRICE1, l_low_44);
   ObjectSetText("H" + a_name_4, "High = " + DoubleToStr(l_high_36, 5), 8, "Arial", White);
   ObjectSetText("L" + a_name_4, "Low = " + DoubleToStr(l_low_44, 5), 8, "Arial", White);
}

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(StringConcatenate(li_4, ".", li_8, ".", li_12, " ", l_hour_16, ":", l_minute_20)));
}

int get_UTC_time() {
   int lia_0[4];
   GetSystemTime(lia_0);
   string ls_4 = (lia_0[0] & 65535) + "." + (lia_0[0] >> 16) + "." + (lia_0[1] >> 16) + " " + (lia_0[2] & 65535) + ":" + (lia_0[2] >> 16) + ":" + (lia_0[3] & 65535);
   return (StrToTime(ls_4));
}

int get_UTC_OFFSET() {
   int li_0 = get_UTC_time();
   double ld_4 = TimeCurrent() - li_0;
   ld_4 /= 3600.0;
   ld_4 = MathRound(ld_4);
   int li_ret_12 = ld_4;
   return (li_ret_12);
}