/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
//#property copyright "Copyright © 2010, Forex Impact LLC."
//#property link      "http://www.foreximpact.com"

#property indicator_chart_window

#import "FXI.dll"
   string gGrab(string a0, string a1);
#import "corr_upd.dll"
   string returnReg(string a0, string a1);
#import

//extern string lbl1 = "Copyright 2010, Forex Impact LLC.";
extern int HourStart = 9;
extern int HourEnd = 18;
extern color BoxColor = Blue;
bool gi_96 = TRUE;
int gi_100 = -1;
int gi_unused_104 = -1;
int g_bars_108;
int g_file_112;
bool gi_116 = FALSE;
string gs_unused_120;

//int loginStart() {
//  int l_str2int_0;
//   bool li_4;
//   int li_8;
//   g_file_112 = FileOpen("fxi_d.bin", FILE_CSV|FILE_READ);
//   if (g_file_112 < 1) li_4 = FALSE;
//   else {
//      l_str2int_0 = StrToInteger(FileReadString(g_file_112));
//      FileClose(g_file_112);
//      li_4 = TRUE;
//   }
//   if (TimeLocal() - l_str2int_0 >= 259200 || li_4 == FALSE) {
//      li_8 = doLogin();
//      switch (li_8) {
 //     case 0:
//         Alert("Delphi Scalping -- Logged In");
//         g_file_112 = FileOpen("fxi_d.bin", FILE_WRITE, 8);
//         if (g_file_112 < 1) {
//            Print("Cannot open password cache!");
//            return (0);
//         }
//         FileWrite(g_file_112, TimeLocal());
//         FileClose(g_file_112);
 //        break;
//      case 1:
//         Alert("Invalid key provided!! Please re-install the software with the correct key.");
//         gi_116 = TRUE;
//         break;
//      case 4:
//         Alert("Your account has been disabled! Please contact support@fximpact.com");
  //       gi_116 = TRUE;
    //     break;
      //case 5:
//         Alert("Server error!! Please make sure you are connected to the Internet and try again.");
  //       gi_116 = TRUE;
    //     break;
//      case 6:
  //       Alert("No key found in your registry (bad install)! Please re-install the product.");
    //     gi_116 = TRUE;
//      }
//   }
//   return (0);
//}

int doLogin() {
   string ls_unused_0;
   string ls_unused_8;
   string ls_unused_16;
   string ls_24 = returnReg("Software\\FXI\\Delphi", "key");
   if (ls_24 == "") return (6);
   string ls_32 = "key=" + ls_24;
   string ls_40 = gGrab("http://www.foreximpact.com/delphi/d_login.php", ls_32);
   if (StringSubstr(ls_40, 0, 1) == "0") {
      gs_unused_120 = ls_40;
      return (0);
   }
   if (StringSubstr(ls_40, 0, 1) == "1") return (1);
   if (StringSubstr(ls_40, 0, 1) == "4") return (4);
   return (5);
}

int init() {
  
   //if (gi_116) return (0);
   g_bars_108 = Bars;
   return (0);
}

int deinit() {
   bool li_4 = TRUE;
   bool li_8 = FALSE;
   if (li_4) {
      for (int li_0 = 0; li_0 <= ObjectsTotal(); li_0++) {
         if (StringFind(ObjectName(li_0), "Box_", 0) != -1) {
            ObjectDelete(ObjectName(li_0));
            li_8 = TRUE;
         }
      }
      if (li_8) {
         li_8 = FALSE;
//???/*empty:1636:(@)*/
      }
   }
   return (0);
}

int start() {
   //if (gi_116) return (0);
   int l_ind_counted_0 = IndicatorCounted();
   int li_4 = Bars - l_ind_counted_0;
   if (li_4 > 0) li_4--;
   if (li_4 < 0) return (-1);
   if (MathAbs(Bars - g_bars_108) >= 2.0) {
      l_ind_counted_0 = 0;
      li_4 = Bars - 1;
      gi_96 = TRUE;
      Print("More Than 1 Bar Fed To Indicator...Reloading!");
   }
   g_bars_108 = Bars;
   for (int li_8 = li_4; li_8 >= 0; li_8--) {
      if (gi_96) {
         if (HourStart < HourEnd) {
            if (gi_100 == -1) {
               if (TimeHour(Time[li_8]) == HourStart) gi_100 = li_8;
            } else {
               if (TimeHour(Time[li_8]) == HourEnd) {
                  if (ObjectFind("Box_" + Time[li_8]) == -1) {
                     ObjectCreate("Box_" + Time[li_8], OBJ_RECTANGLE, 0, Time[gi_100], High[iHighest(Symbol(), 0, MODE_HIGH, gi_100 - li_8, li_8)], Time[li_8], Low[iLowest(Symbol(), 0, MODE_LOW, gi_100 - li_8, li_8)]);
                     ObjectSet("Box_" + Time[li_8], OBJPROP_COLOR, BoxColor);
                  }
                  gi_100 = -1;
               }
            }
         } else {
            if (gi_100 == -1) {
               if (TimeHour(Time[li_8]) == HourStart) gi_100 = li_8;
            } else {
               if (TimeHour(Time[li_8]) == HourEnd) {
                  if (ObjectFind("Box_" + Time[li_8]) == -1) {
                     ObjectCreate("Box_" + Time[li_8], OBJ_RECTANGLE, 0, Time[gi_100], High[iHighest(Symbol(), 0, MODE_HIGH, gi_100 - li_8, li_8)], Time[li_8], Low[iLowest(Symbol(), 0, MODE_LOW, gi_100 - li_8, li_8)]);
                     ObjectSet("Box_" + Time[li_8], OBJPROP_COLOR, BoxColor);
                  }
                  gi_100 = -1;
               }
            }
         }
      }
   }
   if (gi_96) {
      gi_96 = FALSE;
      if (gi_100 != -1) {
         gi_100 = Time[gi_100];
         if (ObjectFind("Box_" + gi_100) == -1) {
            ObjectCreate("Box_" + gi_100, OBJ_RECTANGLE, 0, Time[iBarShift(Symbol(), 0, gi_100, TRUE)], High[iHighest(Symbol(), 0, MODE_HIGH, iBarShift(Symbol(), 0, gi_100, TRUE) +
               1, 0)], Time[0], Low[iLowest(Symbol(), 0, MODE_LOW, iBarShift(Symbol(), 0, gi_100, TRUE) + 1, 0)]);
         } else {
            ObjectSet("Box_" + gi_100, OBJPROP_PRICE1, High[iHighest(Symbol(), 0, MODE_HIGH, iBarShift(Symbol(), 0, gi_100, TRUE) + 1, 0)]);
            ObjectSet("Box_" + gi_100, OBJPROP_PRICE2, Low[iLowest(Symbol(), 0, MODE_LOW, iBarShift(Symbol(), 0, gi_100, TRUE) + 1, 0)]);
            ObjectSet("Box_" + gi_100, OBJPROP_TIME2, Time[0]);
         }
      }
   } else {
      if (gi_100 == -1) {
         if (TimeHour(Time[0]) == HourStart) gi_100 = Time[0];
      } else {
         if (ObjectFind("Box_" + gi_100) == -1) {
            ObjectCreate("Box_" + gi_100, OBJ_RECTANGLE, 0, Time[iBarShift(Symbol(), 0, gi_100, TRUE)], High[iHighest(Symbol(), 0, MODE_HIGH, iBarShift(Symbol(), 0, gi_100, TRUE) +
               1, 0)], Time[0], Low[iLowest(Symbol(), 0, MODE_LOW, iBarShift(Symbol(), 0, gi_100, TRUE) + 1, 0)]);
         } else {
            ObjectSet("Box_" + gi_100, OBJPROP_PRICE1, High[iHighest(Symbol(), 0, MODE_HIGH, iBarShift(Symbol(), 0, gi_100, TRUE) + 1, 0)]);
            ObjectSet("Box_" + gi_100, OBJPROP_PRICE2, Low[iLowest(Symbol(), 0, MODE_LOW, iBarShift(Symbol(), 0, gi_100, TRUE) + 1, 0)]);
            ObjectSet("Box_" + gi_100, OBJPROP_TIME2, Time[0]);
         }
         if (TimeHour(Time[0]) == HourEnd) gi_100 = -1;
      }
   }
   return (0);
}