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

//#import "metabot.dll"
   //int Activate(int a0, int a1);
 //  int GetState(int a0, int a1);
  // int Filter1(int a0, int a1, int a2, int a3, int a4, int a5);
   //double TradeFunction2(int a0, int a1, double a2, double a3, double a4);
  // double FractalEfficiency(int a0, int a1, int a2, double a3);
#import "NN.dll"
   int TimeEfficiency(int a0, int a1, int a2, int a3);
   int CloseEfficiency(int a0, int a1, int a2, int a3, int a4);
   int Entropy(int a0, int a1, int a2, int a3);
   int AdvancedForecast(int a0, int a1, double a2, int a3);
   double NeuralNetworkAlgorithm(int a0, int a1, int a2, int a3);
#import "kernel32.dll"
   int GetTimeZoneInformation(int& a0[]);
#import

extern string Version = "2.0";
extern string _A = "System Parameters";
extern bool MoneyManagement = FALSE;
extern bool Aggressive = FALSE;
extern bool SuperAggressive = FALSE;
extern string _B = "If MM=false, Lots below will be used";
extern double Lots = 1;
extern bool MicroLots = FALSE;
extern int MaximumTrades = 2;
extern int MaxSpread = 4;
extern int TradesSlippage = 0;
extern string _C = "Platform Hours";
extern bool SetAutoGMT = TRUE;
extern int SetManualGMT = 0;
extern bool UseDST = FALSE;
extern string _D = "Pair Traded";
extern string _D1 = "EU=1 GU=2 UCF=3 EC=4 EG=5 UCD=6";
extern int Logic = 1;
extern string _E = "Magic Numbers";
extern int magic1 = 8410001;
extern int magic2 = 8654753;
extern int magic3 = 7854239;
extern int magic4 = 9865173;
extern int magic5 = 8751397;
extern int magic6 = 5672137;
extern string _F = "Comment Change";
extern string EAName = "Metabot";
double gd_224;
double gd_232;
double gd_240;
double gd_248;
double gd_256;
double gd_264;
double gd_272;
double gd_280;
int gi_288 = 1;
double gd_292;
double gd_300 = 0.0001;
bool gi_unused_308 = TRUE;
bool gi_unused_312 = TRUE;
double gd_316 = 4.0;
int g_slippage_324 = 3;
int gi_328 = 32;
int gi_332 = 15;
double gd_unused_336 = 0.0;
double gd_unused_344 = 0.0;
int gi_352 = 0;
int gi_unused_356 = 0;
//double gd_360 = 0.0;
int gi_368 = 0;
string gs_372;
bool gi_unused_380 = FALSE;
bool gi_unused_384 = FALSE;
int gi_388;
int gi_392;
int g_ticket_396;
double g_ifractals_400;
double g_ifractals_408;
double g_ifractals_416;
double g_ifractals_424;
double gd_unused_432;
double gd_unused_440;
double gd_unused_448;
double gd_unused_456;

int init() {
   if (Digits == 5) {
      g_slippage_324 = 10 * g_slippage_324;
      TradesSlippage = 10 * TradesSlippage;
   }
   return (0);
}

int deinit() {
   return (0);
}

void ScreenMsg() {
   string ls_0;
   string ls_unused_8;
   string ls_16;
   string ls_24;
   string ls_32;
   int li_40;
   if (SetAutoGMT) li_40 = GetGmtOffset();
   else li_40 = SetManualGMT;
   gi_392 = 1;
   if (gi_392 == 1) gs_372 = "Authenticated";
   else
      if (gi_392 == 2) gs_372 = "Not Authenticated";
   double ld_44 = 10000.0 * (Ask - Bid);
   int li_unused_52 = NormalizeDouble(ld_44, 0);
   string ls_56 = "\n";
   string ls_64 = "--------------------\n";
   string ls_unused_72 = "\n";
   if (Minute() < 10) ls_16 = Hour() + ":0" + Minute();
   else ls_16 = Hour() + ":" + Minute();
   string ls_80 = "\n" 
      + "\n" 
      + " metabot" 
   + "\n";
   string ls_88 = " Account Number:  " + AccountNumber() 
      + "\n" 
      + " Server Time:        " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
      + "\n" 
      + " TIMEFRAME:      M15\n" + " " + gs_372 
      + "\n" 
   + " GMT Offset= " + li_40;
   Comment(ls_80 + ls_56 + ls_64 + ls_0 + ls_32 + ls_24 + ls_88);
}

int start() {
   double ld_0;
   double ld_8;
   double l_lots_16;
   int l_ord_total_24;
   int l_count_28;
   int l_ord_total_32;
  // double ld_36 = FractalEfficiency(2764, 4963984, 1, iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0));
  // double ld_44 = FractalEfficiency(2764, 4963984, 2, iRSI(Symbol(), 0, 21, PRICE_CLOSE, 0));
  // double ld_52 = FractalEfficiency(2764, 4963984, 3, iRSI(Symbol(), 0, 7, PRICE_CLOSE, 0));
  // double ld_60 = FractalEfficiency(2764, 4963984, 4, iRSI(Symbol(), 0, 1, PRICE_CLOSE, 0));
   //double ld_68 = FractalEfficiency(2764, 4963984, 5, iRSI(Symbol(), 0, 50, PRICE_CLOSE, 0));
  // double ld_76 = FractalEfficiency(2764, 4963984, 6, iRSI(Symbol(), 0, 28, PRICE_CLOSE, 0));
  // double ld_84 = FractalEfficiency(2764, 4963984, 7, iRSI(Symbol(), 0, 42, PRICE_CLOSE, 0));
   int l_timeframe_92 = AdvancedForecast(2764, 4963984, Close[0] - Close[1], 1);
   int l_period_96 = AdvancedForecast(2764, 4963984, Close[0] - Close[1], 2);
   int l_timeframe_100 = AdvancedForecast(2764, 4963984, High[1] - High[0], 3);
   int l_period_104 = AdvancedForecast(2764, 4963984, High[1] - High[0], 4);
   int l_timeframe_108 = AdvancedForecast(2764, 4963984, Low[2] - Low[1], 5);
   int l_period_112 = AdvancedForecast(2764, 4963984, Low[2] - Low[1], 6);
   int l_timeframe_116 = AdvancedForecast(2764, 4963984, Open[0] - Open[2], 7);
   int l_period_120 = AdvancedForecast(2764, 4963984, Open[0] - Open[2], 8);
   int l_timeframe_124 = AdvancedForecast(2764, 4963984, Open[0] - Open[1], 9);
   int l_period_128 = AdvancedForecast(2764, 4963984, Open[0] - Open[1], 10);
   int l_timeframe_132 = AdvancedForecast(2764, 4963984, Low[0] - Low[1], 11);
   int l_period_136 = AdvancedForecast(2764, 4963984, Low[0] - Low[1], 12);
   int l_timeframe_140 = AdvancedForecast(2764, 4963984, High[0] - High[14], 13);
   int l_period_144 = AdvancedForecast(2764, 4963984, High[0] - High[14], 14);
   int li_148 = AdvancedForecast(2764, 4963984, High[0] - High[14], 15);
   int li_152 = AdvancedForecast(2764, 4963984, High[0] - High[14], 16);
   int li_156 = AdvancedForecast(2764, 4963984, Low[0] - Low[14], 13);
   int li_160 = AdvancedForecast(2764, 4963984, Low[0] - Low[14], 14);
   int li_164 = AdvancedForecast(2764, 4963984, Low[0] - Low[14], 15);
   int li_168 = AdvancedForecast(2764, 4963984, Low[0] - Low[14], 16);
   int l_timeframe_172 = AdvancedForecast(2764, 4963984, Close[1] - Close[14], 17);
   int l_period_176 = AdvancedForecast(2764, 4963984, Close[1] - Close[14], 18);
   int li_180 = AdvancedForecast(2764, 4963984, Close[1] - Close[14], 19);
   int l_timeframe_184 = AdvancedForecast(2764, 4963984, Volume[1] - Volume[14], 17);
   int l_period_188 = AdvancedForecast(2764, 4963984, Volume[1] - Volume[14], 18);
   int li_192 = AdvancedForecast(2764, 4963984, Volume[1] - Volume[14], 19);
   int l_timeframe_196 = AdvancedForecast(2764, 4963984, Open[1] - Open[14], 20);
   int l_period_200 = AdvancedForecast(2764, 4963984, Open[1] - Open[14], 21);
   int l_timeframe_204 = AdvancedForecast(2764, 4963984, High[1] - High[14], 22);
   int l_period_208 = AdvancedForecast(2764, 4963984, High[1] - High[14], 23);
   int li_212 = AdvancedForecast(2764, 4963984, High[1] - High[14], 24);
   int l_timeframe_216 = AdvancedForecast(2764, 4963984, Low[1] - Low[14], 22);
   int l_period_220 = AdvancedForecast(2764, 4963984, Low[1] - Low[14], 23);
   int li_224 = AdvancedForecast(2764, 4963984, Low[1] - Low[14], 24);
   int l_timeframe_228 = AdvancedForecast(2764, 4963984, Low[1] - Low[7], 25);
   int l_period_232 = AdvancedForecast(2764, 4963984, Low[1] - Low[7], 26);
   int li_236 = AdvancedForecast(2764, 4963984, Low[1] - Low[7], 27);
   double l_irsi_240 = iRSI(NULL, l_timeframe_92, l_period_96, PRICE_CLOSE, 0);
   double l_irsi_248 = iRSI(NULL, l_timeframe_100, l_period_104, PRICE_CLOSE, 0);
   double l_icci_256 = iCCI(Symbol(), l_timeframe_108, l_period_112, PRICE_CLOSE, 0);
   double l_icci_264 = iCCI(Symbol(), l_timeframe_116, l_period_120, PRICE_CLOSE, 0);
   double l_icci_272 = iCCI(Symbol(), l_timeframe_124, l_period_128, PRICE_CLOSE, 0);
   double l_icci_280 = iCCI(Symbol(), l_timeframe_132, l_period_136, PRICE_CLOSE, 0);
   double l_ibands_288 = iBands(Symbol(), l_timeframe_140, l_period_144, li_148, li_152, PRICE_WEIGHTED, MODE_UPPER, 1);
   double l_ibands_296 = iBands(Symbol(), l_timeframe_140, l_period_144, li_148, li_152, PRICE_WEIGHTED, MODE_LOWER, 1);
   double ld_304 = NormalizeDouble(iMA(NULL, l_timeframe_172, l_period_176, li_180, MODE_SMA, PRICE_WEIGHTED, 1), 4);
   double ld_312 = NormalizeDouble(iMA(NULL, l_timeframe_184, l_period_188, li_192, MODE_SMA, PRICE_WEIGHTED, 1), 4);
   double l_imomentum_320 = iMomentum(Symbol(), l_timeframe_196, l_period_200, PRICE_CLOSE, 0);
   double l_ima_328 = iMA(Symbol(), l_timeframe_204, l_period_208, li_212, MODE_EMA, PRICE_HIGH, 0);
   double l_ima_336 = iMA(Symbol(), l_timeframe_216, l_period_220, li_224, MODE_EMA, PRICE_LOW, 0);
   double l_iwpr_344 = iWPR(Symbol(), l_timeframe_228, l_period_232, li_236);
   //gi_388 = Activate(2764, 4963984);
   if (IsExpertEnabled() == FALSE) {
      Alert("Please allow expert advisors");
      Sleep(4000);
      return (0);
   }
   if (Period() != PERIOD_M15) {
      Alert("Please attach the EA to the M15 Timeframe");
      Sleep(4000);
      return (0);
   }
   gi_392 = 1;//GetState(gi_388, 2764);
   if (gi_392 == 1) gs_372 = "Authenticated";
   /*else {if (gi_392 == 2) {gs_372 = "Not Authenticated";return (0);}}*/
   CloseTrades();
   TimedClosing();
   SetLogic();
   SetStops();
   ScreenMsg();
   if (DayOfWeek() == 1 && Hour() >= 0 && Hour() <= 3) return (0);
   if (DayOfWeek() == 0) return (0);
   MaxSpreadFilter();
   HideTestIndicators(false);
   gd_unused_336 = gd_316;
   gd_unused_344 = 0;
   int li_352 = CheckOpenTrade(magic1);
   int li_356 = CheckOpenTrade(magic2);
   int li_360 = CheckOpenTrade(magic3);
   int li_364 = CheckOpenTrade(magic4);
   int li_368 = CheckOpenTrade(magic5);
   int li_372 = CheckOpenTrade(magic6);
   for (int li_376 = 1; li_376 < Bars; li_376++) {
      if (iFractals(NULL, PERIOD_M15, MODE_LOWER, li_376) != 0.0) {
         g_ifractals_408 = iFractals(NULL, PERIOD_M15, MODE_LOWER, li_376);
         gd_unused_440 = Time[li_376];
         break;
      }
   }
   for (int li_380 = 1; li_380 < Bars; li_380++) {
      if (iFractals(NULL, PERIOD_M15, MODE_UPPER, li_380) != 0.0) {
         g_ifractals_400 = iFractals(NULL, PERIOD_M15, MODE_UPPER, li_380);
         gd_unused_432 = Time[li_380];
         break;
      }
   }
   for (int li_384 = 1; li_384 < Bars; li_384++) {
      if (iFractals(NULL, PERIOD_H1, MODE_LOWER, li_384) != 0.0) {
         g_ifractals_424 = iFractals(NULL, PERIOD_H1, MODE_LOWER, li_384);
         gd_unused_448 = Time[li_376];
         break;
      }
   }
   for (int li_388 = 1; li_388 < Bars; li_388++) {
      if (iFractals(NULL, PERIOD_H1, MODE_UPPER, li_388) != 0.0) {
         g_ifractals_416 = iFractals(NULL, PERIOD_H1, MODE_UPPER, li_388);
         gd_unused_456 = Time[li_388];
         break;
      }
   }
   gi_352 = MathRound((g_ifractals_400 - g_ifractals_408) / gd_300);
   gi_unused_356 = MathRound((g_ifractals_416 - g_ifractals_424) / gd_300);
   //gd_360 = 0;
   //gd_360 = TradeFunction2(2764, 4963984, g_ifractals_400, g_ifractals_400, g_ifractals_408);
   gi_368 = MathRound(iATR(Symbol(), PERIOD_M15, 4, 0) / gd_300);
   bool li_392 = FALSE;
   if (Close[0] <= g_ifractals_416 && Close[0] >= g_ifractals_424) li_392 = TRUE;
   if (iOpen(Symbol(), PERIOD_M5, 0) < Ask + 0.001) {
      if (iOpen(Symbol(), PERIOD_M5, 0) > Bid - 0.001) {
         if (iOpen(Symbol(), PERIOD_M5, 1) < Ask + 0.001) {
            if (iOpen(Symbol(), PERIOD_M5, 1) > Bid - 0.001) {
               if (iOpen(Symbol(), PERIOD_M5, 2) < Ask + 0.0012) {
                  if (iOpen(Symbol(), PERIOD_M5, 2) > Bid - 0.0012) {
                     if (MoneyManagement == TRUE && Aggressive == FALSE && SuperAggressive == FALSE) gi_288 = 1;
                     else {
                        if (MoneyManagement == TRUE && Aggressive == TRUE && SuperAggressive == TRUE) gi_288 = 1;
                        else {
                           if (MoneyManagement == TRUE && Aggressive == TRUE && SuperAggressive == FALSE) gi_288 = 2;
                           else
                              if (MoneyManagement == TRUE && Aggressive == FALSE && SuperAggressive == TRUE) gi_288 = 3;
                        }
                     }
                     if (MicroLots == TRUE && AccountFreeMargin() < 980.0) {
                        if (AccountFreeMargin() >= 100.0 && AccountFreeMargin() <= 200.0) gd_292 = gi_288 / 100.0;
                        else {
                           if (AccountFreeMargin() > 200.0 && AccountFreeMargin() <= 300.0) gd_292 = gi_288 / 50.0;
                           else {
                              if (AccountFreeMargin() > 300.0 && AccountFreeMargin() <= 400.0) gd_292 = 0.03 * gi_288;
                              else {
                                 if (AccountFreeMargin() > 400.0 && AccountFreeMargin() <= 500.0) gd_292 = 0.04 * gi_288;
                                 else {
                                    if (AccountFreeMargin() > 500.0 && AccountFreeMargin() <= 600.0) gd_292 = 0.05 * gi_288;
                                    else {
                                       if (AccountFreeMargin() > 600.0 && AccountFreeMargin() <= 700.0) gd_292 = 0.06 * gi_288;
                                       else {
                                          if (AccountFreeMargin() > 700.0 && AccountFreeMargin() <= 800.0) gd_292 = 0.07 * gi_288;
                                          else {
                                             if (AccountFreeMargin() > 800.0 && AccountFreeMargin() <= 900.0) gd_292 = 0.08 * gi_288;
                                             else
                                                if (AccountFreeMargin() > 900.0 && AccountFreeMargin() < 980.0) gd_292 = 0.09 * gi_288;
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     } else {
                        if (!MicroLots && AccountFreeMargin() < 980.0) gd_292 = 0.1;
                        else {
                           if (AccountFreeMargin() >= 980.0 && AccountFreeMargin() <= 1980.0) gd_292 = gi_288 / 10.0;
                           else {
                              if (AccountFreeMargin() > 1980.0 && AccountFreeMargin() <= 2980.0) gd_292 = 0.2 * gi_288;
                              else {
                                 if (AccountFreeMargin() > 2980.0 && AccountFreeMargin() <= 3980.0) gd_292 = 0.3 * gi_288;
                                 else {
                                    if (AccountFreeMargin() > 3980.0 && AccountFreeMargin() <= 4980.0) gd_292 = gi_288 / 2.0;
                                    else {
                                       if (AccountFreeMargin() > 4980.0 && AccountFreeMargin() <= 5980.0) gd_292 = gi_288 / 2.0;
                                       else {
                                          if (AccountFreeMargin() > 5980.0 && AccountFreeMargin() <= 6980.0) gd_292 = 0.6 * gi_288;
                                          else {
                                             if (AccountFreeMargin() > 6980.0 && AccountFreeMargin() <= 7980.0) gd_292 = 0.7 * gi_288;
                                             else {
                                                if (AccountFreeMargin() > 7980.0 && AccountFreeMargin() <= 8980.0) gd_292 = 0.8 * gi_288;
                                                else {
                                                   if (AccountFreeMargin() > 8980.0 && AccountFreeMargin() <= 9980.0) gd_292 = 0.9 * gi_288;
                                                   else {
                                                      if (AccountFreeMargin() > 9980.0 && AccountFreeMargin() < 100000.0 && MicroLots == TRUE) gd_292 = AccountFreeMargin() / 10000.0 * gi_288;
                                                      else {
                                                         if (AccountFreeMargin() > 9980.0 && AccountFreeMargin() < 999980.0 && MicroLots == FALSE) {
                                                            ld_0 = AccountFreeMargin() / 1000.0;
                                                            ld_8 = MathFloor(ld_0);
                                                            gd_292 = ld_8 / 10.0 * gi_288;
                                                         } else
                                                            if (AccountFreeMargin() >= 999980.0 && AccountFreeMargin() < 1000000.0) gd_292 = NormalizeDouble(AccountFreeMargin() / 10000.0, 1) * gi_288;
                                                      }
                                                   }
                                                }
                                             }
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                     if (MoneyManagement) l_lots_16 = gd_292;
                     else l_lots_16 = Lots;
                     if (DayOfWeek() == 0 || DayOfWeek() == 5 && Hour() >= 14) return (0);
                     if (TradeSession()) {
                        if (!IsTradeContextBusy()) {
                           if (li_392) {
                              if (!li_352 && l_irsi_240 < gd_240 || l_irsi_248 < gd_248 && ld_304 >= Ask + 20.0 * gd_300) {
                                 l_ord_total_24 = OrdersTotal();
                                 for (int l_pos_396 = l_ord_total_24 - 1; l_pos_396 >= 0; l_pos_396--) {
                                    OrderSelect(l_pos_396, SELECT_BY_POS);
                                    if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
                                       OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) return (0);
                                 }
                                 l_count_28 = 0;
                                 l_ord_total_32 = OrdersTotal();
                                 for (int l_pos_400 = l_ord_total_32 - 1; l_pos_400 >= 0; l_pos_400--) {
                                    OrderSelect(l_pos_400, SELECT_BY_POS);
                                    if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 ||
                                       OrderMagicNumber() == magic6) {
                                       l_count_28++;
                                       if (l_count_28 >= MaximumTrades) return (0);
                                    }
                                 }
                                 RefreshRates();
                                 g_ticket_396 = OrderSend(Symbol(), OP_BUY, l_lots_16, Ask, TradesSlippage, 0, 0, EAName + " - GLIVV", magic1, 0, Green);
                                 if (g_ticket_396 < 0) Print("OrderSend Error ", GetLastError());
                              }
                              if (!li_356 && l_irsi_240 > gd_224 || l_irsi_248 > gd_232 && ld_312 <= Bid - 20.0 * gd_300) {
                                 l_ord_total_24 = OrdersTotal();
                                 for (l_pos_396 = l_ord_total_24 - 1; l_pos_396 >= 0; l_pos_396--) {
                                    OrderSelect(l_pos_396, SELECT_BY_POS);
                                    if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
                                       OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) return (0);
                                 }
                                 l_count_28 = 0;
                                 l_ord_total_32 = OrdersTotal();
                                 for (l_pos_400 = l_ord_total_32 - 1; l_pos_400 >= 0; l_pos_400--) {
                                    OrderSelect(l_pos_400, SELECT_BY_POS);
                                    if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 ||
                                       OrderMagicNumber() == magic6) {
                                       l_count_28++;
                                       if (l_count_28 >= MaximumTrades) return (0);
                                    }
                                 }
                                 RefreshRates();
                                 g_ticket_396 = OrderSend(Symbol(), OP_SELL, l_lots_16, Bid, TradesSlippage, 0, 0, EAName + " - GLIVV", magic2, 0, Red);
                                 if (g_ticket_396 < 0) Print("OrderSend Error ", GetLastError());
                              }
                           }
                           if (gi_352 < gi_328 && gi_368 < gi_332 && li_392) {
                              if (!li_360   && Bid <=  3.0 * gd_300) {
                                 l_ord_total_24 = OrdersTotal();
                                 for (l_pos_396 = l_ord_total_24 - 1; l_pos_396 >= 0; l_pos_396--) {
                                    OrderSelect(l_pos_396, SELECT_BY_POS);
                                    if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
                                       OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) return (0);
                                 }
                                 l_count_28 = 0;
                                 l_ord_total_32 = OrdersTotal();
                                 for (l_pos_400 = l_ord_total_32 - 1; l_pos_400 >= 0; l_pos_400--) {
                                    OrderSelect(l_pos_400, SELECT_BY_POS);
                                    if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 ||
                                       OrderMagicNumber() == magic6) {
                                       l_count_28++;
                                       if (l_count_28 >= MaximumTrades) return (0);
                                    }
                                 }
                                 RefreshRates();
                                 g_ticket_396 = OrderSend(Symbol(), OP_BUY, l_lots_16, Ask, TradesSlippage, 0, 0, EAName + " - GLIVV", magic3, 0, Green);
                                 if (g_ticket_396 < 0) Print("OrderSend Error ", GetLastError());
                              }
                           }
                           if (!li_364  &&l_icci_256 >= gd_272  && Ask >=  3.0 * gd_300) {
                              l_ord_total_24 = OrdersTotal();
                              for (l_pos_396 = l_ord_total_24 - 1; l_pos_396 >= 0; l_pos_396--) {
                                 OrderSelect(l_pos_396, SELECT_BY_POS);
                                 if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
                                    OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) return (0);
                              }
                              l_count_28 = 0;
                              l_ord_total_32 = OrdersTotal();
                              for (l_pos_400 = l_ord_total_32 - 1; l_pos_400 >= 0; l_pos_400--) {
                                 OrderSelect(l_pos_400, SELECT_BY_POS);
                                 if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 ||
                                    OrderMagicNumber() == magic6) {
                                    l_count_28++;
                                    if (l_count_28 >= MaximumTrades) return (0);
                                 }
                              }
                              RefreshRates();
                              g_ticket_396 = OrderSend(Symbol(), OP_SELL, l_lots_16, Bid, TradesSlippage, 0, 0, EAName + " - GLIVV", magic4, 0, Red);
                              if (g_ticket_396 < 0) Print("OrderSend Error ", GetLastError());
                           }
                           if (!li_368 && l_imomentum_320 <= gd_256 && l_icci_280 >= 200.0 && Ask >=  3.0 * gd_300) {
                              l_ord_total_24 = OrdersTotal();
                              for (l_pos_396 = l_ord_total_24 - 1; l_pos_396 >= 0; l_pos_396--) {
                                 OrderSelect(l_pos_396, SELECT_BY_POS);
                                 if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
                                    OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) return (0);
                              }
                              l_count_28 = 0;
                              l_ord_total_32 = OrdersTotal();
                              for (l_pos_400 = l_ord_total_32 - 1; l_pos_400 >= 0; l_pos_400--) {
                                 OrderSelect(l_pos_400, SELECT_BY_POS);
                                 if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 ||
                                    OrderMagicNumber() == magic6) {
                                    l_count_28++;
                                    if (l_count_28 >= MaximumTrades) return (0);
                                 }
                              }
                              RefreshRates();
                              g_ticket_396 = OrderSend(Symbol(), OP_SELL, l_lots_16, Bid, TradesSlippage, 0, 0, EAName + " - GLIVV", magic5, 0, Red);
                              if (g_ticket_396 < 0) Print("OrderSend Error ", GetLastError());
                           }
                           if (DayOfWeek() == 0 || DayOfWeek() == 5 && Hour() >= 14) return (0);
                           if (!li_372 && l_iwpr_344 >= gd_280 && l_ima_328 > l_ibands_288 && Bid >=  3.0 * gd_300) {
                              l_ord_total_24 = OrdersTotal();
                              for (l_pos_396 = l_ord_total_24 - 1; l_pos_396 >= 0; l_pos_396--) {
                                 OrderSelect(l_pos_396, SELECT_BY_POS);
                                 if (OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
                                    OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) return (0);
                              }
                              l_count_28 = 0;
                              l_ord_total_32 = OrdersTotal();
                              for (l_pos_400 = l_ord_total_32 - 1; l_pos_400 >= 0; l_pos_400--) {
                                 OrderSelect(l_pos_400, SELECT_BY_POS);
                                 if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 ||
                                    OrderMagicNumber() == magic6) {
                                    l_count_28++;
                                    if (l_count_28 >= MaximumTrades) return (0);
                                 }
                              }
                              RefreshRates();
                              g_ticket_396 = OrderSend(Symbol(), OP_SELL, l_lots_16, Bid, TradesSlippage, 0, 0, EAName + " - GLIVV", magic6, 0, Red);
                              if (g_ticket_396 < 0) Print("OrderSend Error ", GetLastError());
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
   return (0);
}

bool TradeSession() {
   int li_0;
   bool li_4;
   if (SetAutoGMT) li_0 = GetGmtOffset();
   else li_0 = SetManualGMT;
   int l_hour_8 = Hour();
   if (UseDST) li_4 = FALSE;
   else li_4 = TRUE;
   //if (Filter1(2764, 4963984, li_0, l_hour_8, li_4, Logic) == 1) return (TRUE);
   return (TRUE);
}

double GetGmtOffset() {
   return (TimeZoneServer());
}

double TimeZoneServer() {
   int li_0 = (TimeCurrent() - TimeLocal()) / 60;
   int li_4 = MathRound(li_0 / 30.0);
   li_0 = 30 * li_4;
   double ld_ret_8 = TimeZoneLocal() + li_0 / 60.0;
   return (ld_ret_8);
}

double TimeZoneLocal() {
   int lia_0[43];
   switch (GetTimeZoneInformation(lia_0)) {
   case 0:
      return (lia_0[0] / (-60.0));
   case 1:
      return (lia_0[0] / (-60.0));
   case 2:
      return ((lia_0[0] + lia_0[42]) / (-60.0));
   }
   return (0);
}

void MaxSpreadFilter() {
   RefreshRates();
   if (10000.0 * (Ask - Bid) > MaxSpread) {
      Print("Spread is too high");
      return;
   }
}

void SetLogic() {
   gd_224 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 1);
   gd_232 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 2);
   gd_240 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 3);
   gd_248 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 4);
   gd_256 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 5);
   gd_264 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 6);
   gd_272 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 7);
   gd_280 = NeuralNetworkAlgorithm(2764, 4963984, Logic, 8);
}

void CloseTrades() {
   bool l_ord_close_0;
   int l_ord_total_4 = OrdersTotal();
   for (int l_pos_8 = l_ord_total_4 - 1; l_pos_8 >= 0; l_pos_8--) {
      OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUY) {
         if (OrderMagicNumber() == magic1 || OrderMagicNumber() == magic3 && OrderSymbol() == Symbol()) {
            if (Bid >= OrderOpenPrice() + gd_316 * gd_300) {
               RefreshRates();
               l_ord_close_0 = OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_324, Orange);
               if (!l_ord_close_0) {
                  Print("There was an error closing the trade.Error is:", GetLastError());
                  return;
               }
            }
         }
      }
      if (OrderType() == OP_SELL) {
         if (OrderMagicNumber() == magic2 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6 && OrderSymbol() == Symbol()) {
            if (Ask <= OrderOpenPrice() - gd_316 * gd_300) {
               RefreshRates();
               l_ord_close_0 = OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_324, Orange);
               if (!l_ord_close_0) {
                  Print("There was an error closing the trade.Error is: ", GetLastError());
                  return;
               }
            }
         }
      }
   }
}

void TimedClosing() {
   int li_0;
   bool l_ord_close_4;
   if (Digits == 4) li_0 = 1;
   else
      if (Digits == 5) li_0 = 10;
   int li_8 = TimeEfficiency(2764, 4963984, Logic, 1);
   int li_12 = CloseEfficiency(2764, 4963984, Logic, li_0, 1);
   int li_16 = TimeEfficiency(2764, 4963984, Logic, 2);
   int li_20 = CloseEfficiency(2764, 4963984, Logic, li_0, 2);
   int l_ord_total_24 = OrdersTotal();
   for (int l_pos_28 = l_ord_total_24 - 1; l_pos_28 >= 0; l_pos_28--) {
      OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic3) {
         if (TimeCurrent() - OrderOpenTime() >= 60 * li_8 && Bid >= OrderOpenPrice() + li_12 * Point) {
            RefreshRates();
            l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_324, Orange);
            if (!l_ord_close_4) {
               Print("There was an error closing the trade.Error is: ", GetLastError());
               return;
            }
         }
         if (DayOfWeek() == 5 && Hour() >= 19) {
            RefreshRates();
            l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_324, Orange);
         }
      }
      if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magic2 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) {
         if (TimeCurrent() - OrderOpenTime() >= 60 * li_16 && Ask <= OrderOpenPrice() - li_20 * Point) {
            RefreshRates();
            l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_324, Orange);
            if (!l_ord_close_4) {
               Print("There was an error closing the trade.Error is: ", GetLastError());
               return;
            }
         }
         if (DayOfWeek() == 5 && Hour() >= 19) {
            RefreshRates();
            l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_324, Orange);
         }
      }
   }
}

int CheckOpenTrade(int a_magic_0) {
   int l_ord_total_4 = OrdersTotal();
   for (int l_pos_8 = l_ord_total_4 - 1; l_pos_8 >= 0; l_pos_8--) {
      if (OrderSelect(l_pos_8, SELECT_BY_POS) == TRUE)
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0) return (1);
   }
   return (0);
}

void SetStops() {
   int li_0;
   bool l_bool_4;
   int l_ord_total_8 = OrdersTotal();
   if (Digits == 4) li_0 = 1;
   else
      if (Digits == 5) li_0 = 10;
   int li_12 = Entropy(2764, 4963984, Logic, li_0);
   for (int l_pos_16 = l_ord_total_8 - 1; l_pos_16 >= 0; l_pos_16--) {
      if (OrderSelect(l_pos_16, SELECT_BY_POS) == TRUE) {
         if (!((OrderSymbol() == Symbol() && OrderStopLoss() == 0.0 && OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2 || OrderMagicNumber() == magic3 || OrderMagicNumber() == magic4 ||
            OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6))) continue;
         if (OrderType() == OP_SELL) {
            l_bool_4 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + li_12 * Point, 0, 0, Green);
            if (!((!l_bool_4))) continue;
            Print("There was an error modifying the trade.Error is: ", GetLastError());
            return;
         }
         if (OrderType() != OP_BUY) continue;
         l_bool_4 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - li_12 * Point, 0, 0, Green);
         if (!((!l_bool_4))) continue;
         Print("There was an error modifying the trade.Error is: ", GetLastError());
         return;
      }
      Print("There was an error selecting the trade. Error is: ", GetLastError());
   }
}