/*
   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_separate_window
#property indicator_buffers 8
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Purple
#property indicator_color4 Orange
#property indicator_color5 Blue
#property indicator_color6 White
#property indicator_color7 Yellow
#property indicator_color8 Brown

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

bool gi_76 = FALSE;
bool gi_80 = FALSE;
bool gi_84 = FALSE;
bool gi_88 = FALSE;
extern string Copyright = "Copyright 2010, Forex Impact LLC.";
extern int BarsBack = 500;
int gi_104 = 0;
extern color TextColor = White;
int gi_112 = 0;
string gsa_116[20];
string gsa_120[20];
int gi_unused_124;
int g_count_128;
int g_count_132;
int g_count_136;
int g_count_140;
int g_count_144;
int g_count_148;
int g_count_152;
string gs_156 = "";
double g_ibuf_164[];
double g_ibuf_168[];
double g_ibuf_172[];
double g_ibuf_176[];
double g_ibuf_180[];
double g_ibuf_184[];
double g_ibuf_188[];
double g_ibuf_192[];
string gsa_196[500][3];
int g_index_200 = 0;
string gsa_204[500][3];
int g_index_208 = 0;
int gi_212 = -1;
string gsa_216[5][3];
bool gi_unused_220 = FALSE;
bool gi_224 = TRUE;
int g_file_228;
bool gi_232 = FALSE;
string gs_unused_236;

int loginStart() {
   int l_str2int_0;
   bool li_4;
   int li_8;
   g_file_228 = FileOpen("fxi_d.bin", FILE_CSV|FILE_READ);
   if (g_file_228 < 1) li_4 = FALSE;
   else {
      l_str2int_0 = StrToInteger(FileReadString(g_file_228));
      FileClose(g_file_228);
      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_228 = FileOpen("fxi_d.bin", FILE_WRITE, 8);
         if (g_file_228 < 1) {
            Print("Cannot open password cache!");
            return (0);
         }
         FileWrite(g_file_228, TimeLocal());
         FileClose(g_file_228);
         break;
      case 1:
         Alert("Invalid key provided!! Please re-install the software with the correct key.");
         gi_232 = TRUE;
         break;
      case 4:
         Alert("Your account has been disabled! Please contact support@fximpact.com");
         gi_232 = TRUE;
         break;
      case 5:
         Alert("Server error!! Please make sure you are connected to the Internet and try again.");
         gi_232 = TRUE;
         break;
      case 6:
         Alert("No key found in your registry (bad install)! Please re-install the product.");
         gi_232 = 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_236 = 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() {
 //  loginStart();
 //  if (gi_232) return (0);
   gi_76 = FALSE;
   gi_80 = FALSE;
   gi_84 = FALSE;
   gi_88 = FALSE;
   if (Period() < PERIOD_D1) gi_76 = TRUE;
   else {
      if (Period() < PERIOD_W1) gi_80 = TRUE;
      else {
         if (Period() < PERIOD_MN1) gi_84 = TRUE;
         else gi_88 = TRUE;
      }
   }
   if (gi_76 + gi_84 + gi_80 + gi_88 > 1) Alert("Can not select more than one reset mode.");
   gsa_116[0] = "USD";
   gsa_116[1] = "JPY";
   gsa_116[2] = "EUR";
   gsa_116[3] = "GBP";
   gsa_116[4] = "CAD";
   gsa_116[5] = "AUD";
   gsa_116[6] = "NZD";
   gsa_116[7] = "CHF";
   gi_unused_124 = 0;
   g_count_128 = 0;
   g_count_132 = 0;
   g_count_136 = 0;
   g_count_140 = 0;
   g_count_144 = 0;
   g_count_148 = 0;
   g_count_152 = 0;
   if (StringLen(Symbol()) > 6) gs_156 = StringSubstr(Symbol(), 6);
   else gs_156 = "";
   gi_112 = buildUSDPairs();
   if (gi_112 == 0) Print("Could not find any basis USD pairs.");
   else for (int l_index_0 = 0; l_index_0 < gi_112; l_index_0++) Print("USD Pair #" + ((l_index_0 + 1)) + " = ", gsa_120[l_index_0]);
   SetIndexBuffer(0, g_ibuf_164);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexLabel(0, "USD");
   SetIndexEmptyValue(0, 0.0);
   SetIndexBuffer(1, g_ibuf_168);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexLabel(1, "JPY");
   SetIndexEmptyValue(1, 0.0);
   SetIndexBuffer(2, g_ibuf_172);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexLabel(2, "EUR");
   SetIndexEmptyValue(2, 0.0);
   SetIndexBuffer(3, g_ibuf_176);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexLabel(3, "GBP");
   SetIndexEmptyValue(3, 0.0);
   SetIndexBuffer(4, g_ibuf_180);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexLabel(4, "CAD");
   SetIndexEmptyValue(4, 0.0);
   SetIndexBuffer(5, g_ibuf_184);
   SetIndexStyle(5, DRAW_LINE);
   SetIndexLabel(5, "AUD");
   SetIndexEmptyValue(5, 0.0);
   SetIndexBuffer(6, g_ibuf_188);
   SetIndexStyle(6, DRAW_LINE);
   SetIndexLabel(6, "NZD");
   SetIndexEmptyValue(6, 0.0);
   SetIndexBuffer(7, g_ibuf_192);
   SetIndexStyle(7, DRAW_LINE);
   SetIndexLabel(7, "CHF");
   SetIndexEmptyValue(7, 0.0);
   IndicatorShortName("FXI+IndexLines -- Index Baskets For Each Currency");
   return (0);
}

int deinit() {
   ObjectsDeleteAll(WindowFind("FXI+IndexLines -- Index Baskets For Each Currency"));
   ObjectsDeleteAll(0);
   Comment("");
   return (0);
}

int start() {
 //  if (gi_232) return (0);
   for (int l_index_0 = 0; l_index_0 < gi_112; l_index_0++) {
      if (downloadData(gsa_120[l_index_0], Period()) < 0) {
         Comment("-==--==-- DOWNLOADING DATA -==--==--\nWhen All Neccesary Data Is Downloaded, This Indicator Will Update\nOn The Next Tick. If You Choose Not To Wait, You\nMay Re-Attach The Indicator When The Data Is Finished Loading.");
         gi_224 = FALSE;
         return (0);
      }
      if (downloadData(gsa_120[l_index_0], PERIOD_M1) < 0) {
         Comment("-==--==-- DOWNLOADING DATA -==--==--\nWhen All Neccesary Data Is Downloaded, This Indicator Will Update\nOn The Next Tick. If You Choose Not To Wait, You\nMay Re-Attach The Indicator When The Data Is Finished Loading.");
         gi_224 = FALSE;
         return (0);
      }
   }
   Comment("");
   int l_ind_counted_4 = IndicatorCounted();
   int li_8 = Bars - l_ind_counted_4;
   if (li_8 > 0) li_8--;
   if (li_8 < 0) return (-1);
   if (li_8 > BarsBack) li_8 = BarsBack;
   if (!gi_224) li_8 = BarsBack;
   for (int li_12 = li_8; li_12 >= 0; li_12--) {
      if ((TimeHour(Time[li_12]) == gi_104 && TimeMinute(Time[li_12]) == 0 && gi_76) || (gi_80 && TimeDayOfWeek(Time[li_12]) < TimeDayOfWeek(Time[li_12 + 1])) || (gi_84 &&
         TimeDay(Time[li_12]) < TimeDay(Time[li_12 + 1])) || (gi_88 && TimeDayOfYear(Time[li_12]) < TimeDayOfYear(Time[li_12 + 1]))) {
         if (li_12 == 0) {
            g_ibuf_164[li_12] = findMashUSD("USD", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_168[li_12] = findMash2("JPY", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_172[li_12] = findMash2("EUR", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_176[li_12] = findMash2("GBP", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_180[li_12] = findMash2("CAD", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_184[li_12] = findMash2("AUD", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_188[li_12] = findMash2("NZD", PERIOD_M1, Period(), TimeCurrent());
            g_ibuf_192[li_12] = findMash2("CHF", PERIOD_M1, Period(), TimeCurrent());
         } else {
            g_ibuf_164[li_12] = findMashUSD("USD", Period(), Period(), Time[li_12]);
            g_ibuf_168[li_12] = findMash2("JPY", Period(), Period(), Time[li_12]);
            g_ibuf_172[li_12] = findMash2("EUR", Period(), Period(), Time[li_12]);
            g_ibuf_176[li_12] = findMash2("GBP", Period(), Period(), Time[li_12]);
            g_ibuf_180[li_12] = findMash2("CAD", Period(), Period(), Time[li_12]);
            g_ibuf_184[li_12] = findMash2("AUD", Period(), Period(), Time[li_12]);
            g_ibuf_188[li_12] = findMash2("NZD", Period(), Period(), Time[li_12]);
            g_ibuf_192[li_12] = findMash2("CHF", Period(), Period(), Time[li_12]);
            continue;
         }
      }
      if (li_12 == 0) {
         g_ibuf_164[li_12] = g_ibuf_164[li_12 + 1] + findMashUSD("USD", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_168[li_12] = g_ibuf_168[li_12 + 1] + findMash2("JPY", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_172[li_12] = g_ibuf_172[li_12 + 1] + findMash2("EUR", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_176[li_12] = g_ibuf_176[li_12 + 1] + findMash2("GBP", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_180[li_12] = g_ibuf_180[li_12 + 1] + findMash2("CAD", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_184[li_12] = g_ibuf_184[li_12 + 1] + findMash2("AUD", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_188[li_12] = g_ibuf_188[li_12 + 1] + findMash2("NZD", PERIOD_M1, Period(), TimeCurrent());
         g_ibuf_192[li_12] = g_ibuf_192[li_12 + 1] + findMash2("CHF", PERIOD_M1, Period(), TimeCurrent());
      } else {
         g_ibuf_164[li_12] = g_ibuf_164[li_12 + 1] + findMashUSD("USD", Period(), Period(), Time[li_12]);
         g_ibuf_168[li_12] = g_ibuf_168[li_12 + 1] + findMash2("JPY", Period(), Period(), Time[li_12]);
         g_ibuf_172[li_12] = g_ibuf_172[li_12 + 1] + findMash2("EUR", Period(), Period(), Time[li_12]);
         g_ibuf_176[li_12] = g_ibuf_176[li_12 + 1] + findMash2("GBP", Period(), Period(), Time[li_12]);
         g_ibuf_180[li_12] = g_ibuf_180[li_12 + 1] + findMash2("CAD", Period(), Period(), Time[li_12]);
         g_ibuf_184[li_12] = g_ibuf_184[li_12 + 1] + findMash2("AUD", Period(), Period(), Time[li_12]);
         g_ibuf_188[li_12] = g_ibuf_188[li_12 + 1] + findMash2("NZD", Period(), Period(), Time[li_12]);
         g_ibuf_192[li_12] = g_ibuf_192[li_12 + 1] + findMash2("CHF", Period(), Period(), Time[li_12]);
      }
   }
   g_index_200 = 0;
   g_index_208 = 0;
   for (int l_index_16 = 0; l_index_16 <= 7; l_index_16++) fillGlobalArray(gsa_116[l_index_16]);
   buildHUD();
   gi_224 = TRUE;
   return (0);
}

void buildHUD() {
   buildTopThree();
   int l_window_0 = WindowFind("FXI+IndexLines -- Index Baskets For Each Currency");
   if (ObjectFind("HUD_" + l_window_0 + "_Title") == -1) {
      ObjectCreate("HUD_" + l_window_0 + "_Title", OBJ_LABEL, l_window_0, 0, 0);
      ObjectSet("HUD_" + l_window_0 + "_Title", OBJPROP_XDISTANCE, 5);
      ObjectSet("HUD_" + l_window_0 + "_Title", OBJPROP_YDISTANCE, 15);
   }
   ObjectSetText("HUD_" + l_window_0 + "_Title", "Pairs Of Interest (On This Candle):", 8, "Tahoma", TextColor);
   if (ObjectFind("HUD_" + l_window_0 + "_Number1") == -1) {
      ObjectCreate("HUD_" + l_window_0 + "_Number1", OBJ_LABEL, l_window_0, 0, 0);
      ObjectSet("HUD_" + l_window_0 + "_Number1", OBJPROP_XDISTANCE, 5);
      ObjectSet("HUD_" + l_window_0 + "_Number1", OBJPROP_YDISTANCE, 30);
   }
   ObjectSetText("HUD_" + l_window_0 + "_Number1", "1) " + gsa_216[0][0] + " - " + gsa_216[0][2], 8, "Tahoma", TextColor);
   if (ObjectFind("HUD_" + l_window_0 + "_Number2") == -1) {
      ObjectCreate("HUD_" + l_window_0 + "_Number2", OBJ_LABEL, l_window_0, 0, 0);
      ObjectSet("HUD_" + l_window_0 + "_Number2", OBJPROP_XDISTANCE, 5);
      ObjectSet("HUD_" + l_window_0 + "_Number2", OBJPROP_YDISTANCE, 42);
   }
   ObjectSetText("HUD_" + l_window_0 + "_Number2", "2) " + gsa_216[1][0] + " - " + gsa_216[1][2], 8, "Tahoma", TextColor);
   if (ObjectFind("HUD_" + l_window_0 + "_Number3") == -1) {
      ObjectCreate("HUD_" + l_window_0 + "_Number3", OBJ_LABEL, l_window_0, 0, 0);
      ObjectSet("HUD_" + l_window_0 + "_Number3", OBJPROP_XDISTANCE, 5);
      ObjectSet("HUD_" + l_window_0 + "_Number3", OBJPROP_YDISTANCE, 54);
   }
   ObjectSetText("HUD_" + l_window_0 + "_Number3", "3) " + gsa_216[2][0] + " - " + gsa_216[2][2], 8, "Tahoma", TextColor);
}

void buildTopThree() {
   gsa_216[0][0] = "";
   gsa_216[0][1] = "0";
   gsa_216[0][2] = "";
   gsa_216[1][0] = "";
   gsa_216[1][1] = "0";
   gsa_216[1][2] = "";
   gsa_216[2][0] = "";
   gsa_216[2][1] = "0";
   gsa_216[2][2] = "";
   for (int l_index_0 = 0; l_index_0 < g_index_200; l_index_0++) {
      if (StrToDouble(gsa_196[l_index_0][1]) > StrToDouble(gsa_216[0][1])) {
         gsa_216[2][0] = gsa_216[1][0];
         gsa_216[2][1] = gsa_216[1][1];
         gsa_216[2][2] = gsa_216[1][2];
         gsa_216[1][0] = gsa_216[0][0];
         gsa_216[1][1] = gsa_216[0][1];
         gsa_216[1][2] = gsa_216[0][2];
         gsa_216[0][0] = gsa_196[l_index_0][0];
         gsa_216[0][1] = gsa_196[l_index_0][1];
         gsa_216[0][2] = gsa_196[l_index_0][2];
      } else {
         if (StrToDouble(gsa_196[l_index_0][1]) > StrToDouble(gsa_216[1][1])) {
            gsa_216[2][0] = gsa_216[1][0];
            gsa_216[2][1] = gsa_216[1][1];
            gsa_216[2][2] = gsa_216[1][2];
            gsa_216[1][0] = gsa_196[l_index_0][0];
            gsa_216[1][1] = gsa_196[l_index_0][1];
            gsa_216[1][2] = gsa_196[l_index_0][2];
         } else {
            if (StrToDouble(gsa_196[l_index_0][1]) > StrToDouble(gsa_216[2][1])) {
               gsa_216[2][0] = gsa_196[l_index_0][0];
               gsa_216[2][1] = gsa_196[l_index_0][1];
               gsa_216[2][2] = gsa_196[l_index_0][2];
            }
         }
      }
   }
   for (l_index_0 = 0; l_index_0 < g_index_208; l_index_0++) {
      if (StrToDouble(gsa_204[l_index_0][1]) > StrToDouble(gsa_216[0][1])) {
         gsa_216[2][0] = gsa_216[1][0];
         gsa_216[2][1] = gsa_216[1][1];
         gsa_216[2][2] = gsa_216[1][2];
         gsa_216[1][0] = gsa_216[0][0];
         gsa_216[1][1] = gsa_216[0][1];
         gsa_216[1][2] = gsa_216[0][2];
         gsa_216[0][0] = gsa_204[l_index_0][0];
         gsa_216[0][1] = gsa_204[l_index_0][1];
         gsa_216[0][2] = gsa_204[l_index_0][2];
      } else {
         if (StrToDouble(gsa_204[l_index_0][1]) > StrToDouble(gsa_216[1][1])) {
            gsa_216[2][0] = gsa_216[1][0];
            gsa_216[2][1] = gsa_216[1][1];
            gsa_216[2][2] = gsa_216[1][2];
            gsa_216[1][0] = gsa_204[l_index_0][0];
            gsa_216[1][1] = gsa_204[l_index_0][1];
            gsa_216[1][2] = gsa_204[l_index_0][2];
         } else {
            if (StrToDouble(gsa_204[l_index_0][1]) > StrToDouble(gsa_216[2][1])) {
               gsa_216[2][0] = gsa_204[l_index_0][0];
               gsa_216[2][1] = gsa_204[l_index_0][1];
               gsa_216[2][2] = gsa_204[l_index_0][2];
            }
         }
      }
   }
}

double findMashUSD(string as_unused_0, int a_timeframe_8, int a_timeframe_12, int ai_16) {
   int li_ret_20 = 0;
   int l_shift_24 = 0;
   int l_shift_28 = 0;
   for (int l_index_32 = 0; l_index_32 < gi_112; l_index_32++) {
      l_shift_24 = iBarShift(gsa_120[l_index_32], a_timeframe_8, ai_16);
      l_shift_28 = iBarShift(gsa_120[l_index_32], a_timeframe_12, ai_16);
      if (StringFind(gsa_120[l_index_32], "USD") == 0) li_ret_20 += (iClose(gsa_120[l_index_32], a_timeframe_8, l_shift_24) - iOpen(gsa_120[l_index_32], a_timeframe_12, l_shift_28)) / MarketInfo(gsa_120[l_index_32], MODE_POINT);
      else li_ret_20 += (iOpen(gsa_120[l_index_32], a_timeframe_12, l_shift_28) - iClose(gsa_120[l_index_32], a_timeframe_8, l_shift_24)) / MarketInfo(gsa_120[l_index_32], MODE_POINT);
   }
   return (li_ret_20);
}

int buildUSDPairs() {
   string l_str_concat_0;
   int l_index_8 = 0;
   for (int li_12 = 1; li_12 <= 7; li_12++) {
      l_str_concat_0 = StringConcatenate(gsa_116[0], gsa_116[li_12], gs_156);
      if (MarketInfo(l_str_concat_0, MODE_BID) > 0.0 && MarketInfo(l_str_concat_0, MODE_ASK) > 0.0) {
         gsa_120[l_index_8] = l_str_concat_0;
         l_index_8++;
         if (StringFind(gsa_116[li_12], "JPY", 0) != -1) g_count_128++;
         if (StringFind(gsa_116[li_12], "EUR", 0) != -1) g_count_132++;
         if (StringFind(gsa_116[li_12], "GBP", 0) != -1) g_count_136++;
         if (StringFind(gsa_116[li_12], "CAD", 0) != -1) g_count_140++;
         if (StringFind(gsa_116[li_12], "AUD", 0) != -1) g_count_144++;
         if (StringFind(gsa_116[li_12], "NZD", 0) != -1) g_count_148++;
         if (StringFind(gsa_116[li_12], "CHF", 0) != -1) g_count_152++;
      }
      l_str_concat_0 = StringConcatenate(gsa_116[li_12], gsa_116[0], gs_156);
      if (MarketInfo(l_str_concat_0, MODE_BID) > 0.0 && MarketInfo(l_str_concat_0, MODE_ASK) > 0.0) {
         gsa_120[l_index_8] = l_str_concat_0;
         l_index_8++;
         if (StringFind(gsa_116[li_12], "JPY", 0) != -1) g_count_128++;
         if (StringFind(gsa_116[li_12], "EUR", 0) != -1) g_count_132++;
         if (StringFind(gsa_116[li_12], "GBP", 0) != -1) g_count_136++;
         if (StringFind(gsa_116[li_12], "CAD", 0) != -1) g_count_140++;
         if (StringFind(gsa_116[li_12], "AUD", 0) != -1) g_count_144++;
         if (StringFind(gsa_116[li_12], "NZD", 0) != -1) g_count_148++;
         if (StringFind(gsa_116[li_12], "CHF", 0) != -1) g_count_152++;
      }
   }
   return (l_index_8);
}

double findMash2(string as_0, int a_timeframe_8, int a_timeframe_12, int ai_16) {
   double l_point_36;
   double ld_44;
   double ld_52;
   int l_shift_80;
   double l_digits_84;
   double l_digits_92;
   int l_shift_112;
   string ls_20 = "";
   double ld_ret_28 = 0;
   int li_100 = -1;
   for (int l_index_104 = 0; l_index_104 < gi_112; l_index_104++) {
      if (StringFind(gsa_120[l_index_104], as_0, 0) != -1) {
         ls_20 = gsa_120[l_index_104];
         break;
      }
   }
   if (ls_20 == "") return (0);
   if (StringFind(ls_20, "USD") == 0) li_100 = 50;
   else li_100 = 60;
   int l_shift_76 = iBarShift(ls_20, a_timeframe_8, ai_16);
   int l_shift_108 = iBarShift(ls_20, a_timeframe_12, ai_16);
   double ld_unused_60 = 1;
   double ld_unused_68 = 1;
   for (l_index_104 = 0; l_index_104 < gi_112; l_index_104++) {
      if (gsa_120[l_index_104] != ls_20) {
         l_digits_84 = MarketInfo(ls_20, MODE_DIGITS);
         l_digits_92 = MarketInfo(gsa_120[l_index_104], MODE_DIGITS);
         l_point_36 = MarketInfo(gsa_120[l_index_104], MODE_POINT);
         l_shift_80 = iBarShift(gsa_120[l_index_104], a_timeframe_8, ai_16);
         l_shift_112 = iBarShift(gsa_120[l_index_104], a_timeframe_12, ai_16);
         if (li_100 == 50) {
            if (StringFind(gsa_120[l_index_104], "USD") == 0) {
               ld_44 = 1 / iOpen(ls_20, a_timeframe_12, l_shift_108) / (1 / iOpen(gsa_120[l_index_104], a_timeframe_12, l_shift_112));
               ld_52 = 1 / iClose(ls_20, a_timeframe_8, l_shift_76) / (1 / iClose(gsa_120[l_index_104], a_timeframe_8, l_shift_80));
               if (StringFind(ls_20, "JPY") != -1) {
                  if (Digits == 5 || Digits == 3) ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT) / 10.0;
                  else ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT);
               } else ld_ret_28 += (ld_52 - ld_44) / l_point_36;
            } else {
               ld_44 = 1 / iOpen(ls_20, a_timeframe_12, l_shift_108) / iOpen(gsa_120[l_index_104], a_timeframe_12, l_shift_112);
               ld_52 = 1 / iClose(ls_20, a_timeframe_8, l_shift_76) / iClose(gsa_120[l_index_104], a_timeframe_8, l_shift_80);
               if (StringFind(ls_20, "JPY") != -1) {
                  if (Digits == 5 || Digits == 3) ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT) / 10.0;
                  else ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT);
               } else ld_ret_28 += (ld_52 - ld_44) / l_point_36;
            }
         } else {
            if (li_100 == 60) {
               if (StringFind(gsa_120[l_index_104], "USD") == 0) {
                  ld_44 = iOpen(ls_20, a_timeframe_12, l_shift_108) / (1 / iOpen(gsa_120[l_index_104], a_timeframe_12, l_shift_112));
                  ld_52 = iClose(ls_20, a_timeframe_8, l_shift_76) / (1 / iClose(gsa_120[l_index_104], a_timeframe_8, l_shift_80));
                  if (StringFind(ls_20, "JPY") != -1) {
                     if (Digits == 5 || Digits == 3) ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT) / 10.0;
                     else ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT);
                  } else ld_ret_28 += (ld_52 - ld_44) / l_point_36;
               } else {
                  ld_44 = iOpen(ls_20, a_timeframe_12, l_shift_108) / iOpen(gsa_120[l_index_104], a_timeframe_12, l_shift_112);
                  ld_52 = iClose(ls_20, a_timeframe_8, l_shift_76) / iClose(gsa_120[l_index_104], a_timeframe_8, l_shift_80);
                  if (StringFind(ls_20, "JPY") != -1) {
                     if (Digits == 5 || Digits == 3) ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT) / 10.0;
                     else ld_ret_28 += (ld_52 - ld_44) / l_point_36 / MarketInfo(ls_20, MODE_POINT);
                  } else ld_ret_28 += (ld_52 - ld_44) / l_point_36;
               }
            }
         }
      }
   }
   return (ld_ret_28);
}

void fillGlobalArray(string as_0) {
   string l_str_concat_8;
   int li_16 = 0;
   int li_20 = 0;
   for (int l_index_24 = 0; l_index_24 <= 7; l_index_24++) {
      if (as_0 != gsa_116[l_index_24]) {
         l_str_concat_8 = StringConcatenate(as_0, gsa_116[l_index_24], gs_156);
         if (MarketInfo(l_str_concat_8, MODE_BID) > 0.0 && MarketInfo(l_str_concat_8, MODE_ASK) > 0.0) {
            li_16 = isAlligator(as_0, gsa_116[l_index_24], 70);
            li_20 = isAlligator(as_0, gsa_116[l_index_24], 80);
            if (li_16 > 0) addToArray(l_str_concat_8, li_16, 70, as_0, gsa_116[l_index_24]);
            if (li_20 > 0) addToArray(l_str_concat_8, li_20, 80, as_0, gsa_116[l_index_24]);
         }
         l_str_concat_8 = StringConcatenate(gsa_116[l_index_24], as_0, gs_156);
         if (MarketInfo(l_str_concat_8, MODE_BID) > 0.0 && MarketInfo(l_str_concat_8, MODE_ASK) > 0.0) {
            li_16 = isAlligator(as_0, gsa_116[l_index_24], 70);
            if (li_16 > 0) addToArray(l_str_concat_8, li_16, 70, as_0, gsa_116[l_index_24]);
            li_20 = isAlligator(as_0, gsa_116[l_index_24], 80);
            if (li_20 > 0) addToArray(l_str_concat_8, li_20, 80, as_0, gsa_116[l_index_24]);
         }
      }
   }
}

void addToArray(string as_0, int ai_8, int ai_12, string as_16, string as_24) {
   int li_32 = gi_212;
   if (ai_12 == 70) {
      for (int l_index_36 = 0; l_index_36 < g_index_200; l_index_36++)
         if (gsa_196[l_index_36][0] == as_0) return;
      if (li_32 == 90) {
         if (StringFind(as_0, as_16) == 0) gsa_196[g_index_200][2] = "LONG";
         else gsa_196[g_index_200][2] = "SHORT";
      } else {
         if (StringFind(as_0, as_24) == 0) gsa_196[g_index_200][2] = "LONG";
         else gsa_196[g_index_200][2] = "SHORT";
      }
      gsa_196[g_index_200][0] = as_0;
      gsa_196[g_index_200][1] = DoubleToStr(ai_8, Digits);
      g_index_200++;
   }
   if (ai_12 == 80) {
      for (l_index_36 = 0; l_index_36 < g_index_208; l_index_36++)
         if (gsa_204[l_index_36][0] == as_0) return;
      if (li_32 == 90) {
         if (StringFind(as_0, as_16) == 0) gsa_204[g_index_208][2] = "SHORT";
         else gsa_204[g_index_208][2] = "LONG";
      } else {
         if (StringFind(as_0, as_24) == 0) gsa_204[g_index_208][2] = "SHORT";
         else gsa_204[g_index_208][2] = "LONG";
      }
      gsa_204[g_index_208][0] = as_0;
      gsa_204[g_index_208][1] = DoubleToStr(ai_8, Digits);
      g_index_208++;
   }
}

int isAlligator(string as_0, string as_8, int ai_16) {
   gi_212 = -1;
   double ld_unused_20 = 0;
   double ld_unused_28 = 0;
   double ld_36 = 0;
   double ld_44 = 0;
   double ld_52 = 0;
   double ld_60 = 0;
   int li_unused_68 = 0;
   if (as_0 == "USD") {
      ld_unused_20 = g_ibuf_164[0];
      ld_36 = g_ibuf_164[0];
      ld_44 = g_ibuf_164[1];
   }
   if (as_0 == "JPY") {
      ld_unused_20 = g_ibuf_168[0];
      ld_36 = g_ibuf_168[0];
      ld_44 = g_ibuf_168[1];
   }
   if (as_0 == "EUR") {
      ld_unused_20 = g_ibuf_172[0];
      ld_36 = g_ibuf_172[0];
      ld_44 = g_ibuf_172[1];
   }
   if (as_0 == "GBP") {
      ld_unused_20 = g_ibuf_176[0];
      ld_36 = g_ibuf_176[0];
      ld_44 = g_ibuf_176[1];
   }
   if (as_0 == "CAD") {
      ld_unused_20 = g_ibuf_180[0];
      ld_36 = g_ibuf_180[0];
      ld_44 = g_ibuf_180[1];
   }
   if (as_0 == "AUD") {
      ld_unused_20 = g_ibuf_184[0];
      ld_36 = g_ibuf_184[0];
      ld_44 = g_ibuf_184[1];
   }
   if (as_0 == "NZD") {
      ld_unused_20 = g_ibuf_188[0];
      ld_36 = g_ibuf_188[0];
      ld_44 = g_ibuf_188[1];
   }
   if (as_0 == "CHF") {
      ld_unused_20 = g_ibuf_192[0];
      ld_36 = g_ibuf_192[0];
      ld_44 = g_ibuf_192[1];
   }
   if (as_8 == "USD") {
      ld_unused_28 = g_ibuf_164[0];
      ld_52 = g_ibuf_164[0];
      ld_60 = g_ibuf_164[1];
   }
   if (as_8 == "JPY") {
      ld_unused_28 = g_ibuf_168[0];
      ld_52 = g_ibuf_168[0];
      ld_60 = g_ibuf_168[1];
   }
   if (as_8 == "EUR") {
      ld_unused_28 = g_ibuf_172[0];
      ld_52 = g_ibuf_172[0];
      ld_60 = g_ibuf_172[1];
   }
   if (as_8 == "GBP") {
      ld_unused_28 = g_ibuf_176[0];
      ld_52 = g_ibuf_176[0];
      ld_60 = g_ibuf_176[1];
   }
   if (as_8 == "CAD") {
      ld_unused_28 = g_ibuf_180[0];
      ld_52 = g_ibuf_180[0];
      ld_60 = g_ibuf_180[1];
   }
   if (as_8 == "AUD") {
      ld_unused_28 = g_ibuf_184[0];
      ld_52 = g_ibuf_184[0];
      ld_60 = g_ibuf_184[1];
   }
   if (as_8 == "NZD") {
      ld_unused_28 = g_ibuf_188[0];
      ld_52 = g_ibuf_188[0];
      ld_60 = g_ibuf_188[1];
   }
   if (as_8 == "CHF") {
      ld_unused_28 = g_ibuf_192[0];
      ld_52 = g_ibuf_192[0];
      ld_60 = g_ibuf_192[1];
   }
   if (ld_36 > ld_52) {
      gi_212 = 90;
      if (ai_16 == 70) {
         if (!(ld_36 > ld_44 && ld_52 < ld_60)) return (-1);
         return (MathAbs(ld_36 - ld_52));
      }
      if (ld_36 < ld_44 && ld_52 > ld_60) return (MathAbs(ld_52 - ld_36));
   } else {
      gi_212 = 100;
      if (ai_16 == 70) {
         if (!(ld_36 < ld_44 && ld_52 > ld_60)) return (-1);
         return (MathAbs(ld_52 - ld_36));
      }
      if (ld_36 > ld_44 && ld_52 < ld_60) return (MathAbs(ld_36 - ld_52));
   }
   return (-1);
}

int downloadData(string a_symbol_0, int a_timeframe_8) {
   int li_unused_12 = 1;
   if (!IsConnected()) return (-2);
   RefreshRates();
   if (MarketInfo(a_symbol_0, MODE_BID) == iClose(a_symbol_0, a_timeframe_8, 0)) return (0);
   return (-1);
}