#property copyright "Copyright© 2009 FOREX Developers, LLC"
#property link      "http://www.forexshocker.com"

#import "shocker2.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 int VerificationCode = 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 = 0.1;
extern bool MicroLots = FALSE;
extern int MaximumTrades = 2;
extern int MaxSpread = 4;
extern int TradesSlippage = 3;
extern string _C = "Platform Hours";
extern bool SetAutoGMT = TRUE;
extern int SetManualGMT = 1;
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 = "Forex Shocker 2.0";
double gd_228;
double gd_236;
double gd_244;
double gd_252;
double gd_260;
double gd_268;
double gd_276;
double gd_284;
int gi_292 = 1;
double gd_296;
double gd_304 = 0.0001;
bool gi_unused_312 = TRUE;
bool gi_unused_316 = TRUE;
double gd_320 = 4.0;
int g_slippage_328 = 3;
int gi_332 = 32;
int gi_336 = 15;
double gd_unused_340 = 0.0;
double gd_unused_348 = 0.0;
int gi_356 = 0;
int gi_unused_360 = 0;
double gd_364 = 0.0;
int gi_372 = 0;
string gs_376;
bool gi_unused_384 = FALSE;
bool gi_unused_388 = FALSE;
int gi_392;
int gi_396;
int g_ticket_400;
double g_ifractals_424;
double g_ifractals_432;
double g_ifractals_440;
double g_ifractals_448;
double gd_unused_456;
double gd_unused_464;
double gd_unused_472;
double gd_unused_480;

int init() {
   if (Digits == 5) {
      g_slippage_328 = 10 * g_slippage_328;
      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_396 = GetState(gi_392, AccountNumber());
   if (gi_396 == 1) gs_376 = "Authenticated";
   else
      if (gi_396 == 2) gs_376 = "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" 
      + " Forex Shocker v 2.0 Copyright © 2009" 
   + "\n";
   string ls_88 = " Account Number:  " + AccountNumber() 
      + "\n" 
      + " Server Time:        " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
      + "\n" 
      + " TIMEFRAME:      M15\n" + " " + gs_376 
      + "\n" 
   + " GMT Offset= " + li_40;
   Comment(ls_80 + ls_56 + ls_64 + ls_0 + ls_32 + ls_24 + ls_88);
}

int start() {
   double ld_360;
   double ld_368;
   double l_lots_376;
   int l_ord_total_388;
   int l_count_392;
   int l_ord_total_396;
   double ld_0 = FractalEfficiency(AccountNumber(), VerificationCode, 1, iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0));
   double ld_8 = FractalEfficiency(AccountNumber(), VerificationCode, 2, iRSI(Symbol(), 0, 21, PRICE_CLOSE, 0));
   double ld_16 = FractalEfficiency(AccountNumber(), VerificationCode, 3, iRSI(Symbol(), 0, 7, PRICE_CLOSE, 0));
   double ld_24 = FractalEfficiency(AccountNumber(), VerificationCode, 4, iRSI(Symbol(), 0, 1, PRICE_CLOSE, 0));
   double ld_32 = FractalEfficiency(AccountNumber(), VerificationCode, 5, iRSI(Symbol(), 0, 50, PRICE_CLOSE, 0));
   double ld_40 = FractalEfficiency(AccountNumber(), VerificationCode, 6, iRSI(Symbol(), 0, 28, PRICE_CLOSE, 0));
   double ld_48 = FractalEfficiency(AccountNumber(), VerificationCode, 7, iRSI(Symbol(), 0, 42, PRICE_CLOSE, 0));
   int l_timeframe_56 = AdvancedForecast(AccountNumber(), VerificationCode, Close[0] - Close[1], 1);
   int l_period_60 = AdvancedForecast(AccountNumber(), VerificationCode, Close[0] - Close[1], 2);
   int l_timeframe_64 = AdvancedForecast(AccountNumber(), VerificationCode, High[1] - High[0], 3);
   int l_period_68 = AdvancedForecast(AccountNumber(), VerificationCode, High[1] - High[0], 4);
   int l_timeframe_72 = AdvancedForecast(AccountNumber(), VerificationCode, Low[2] - Low[1], 5);
   int l_period_76 = AdvancedForecast(AccountNumber(), VerificationCode, Low[2] - Low[1], 6);
   int l_timeframe_80 = AdvancedForecast(AccountNumber(), VerificationCode, Open[0] - Open[2], 7);
   int l_period_84 = AdvancedForecast(AccountNumber(), VerificationCode, Open[0] - Open[2], 8);
   int l_timeframe_88 = AdvancedForecast(AccountNumber(), VerificationCode, Open[0] - Open[1], 9);
   int l_period_92 = AdvancedForecast(AccountNumber(), VerificationCode, Open[0] - Open[1], 10);
   int l_timeframe_96 = AdvancedForecast(AccountNumber(), VerificationCode, Low[0] - Low[1], 11);
   int l_period_100 = AdvancedForecast(AccountNumber(), VerificationCode, Low[0] - Low[1], 12);
   int l_timeframe_104 = AdvancedForecast(AccountNumber(), VerificationCode, High[0] - High[14], 13);
   int l_period_108 = AdvancedForecast(AccountNumber(), VerificationCode, High[0] - High[14], 14);
   int li_112 = AdvancedForecast(AccountNumber(), VerificationCode, High[0] - High[14], 15);
   int li_116 = AdvancedForecast(AccountNumber(), VerificationCode, High[0] - High[14], 16);
   int li_120 = AdvancedForecast(AccountNumber(), VerificationCode, Low[0] - Low[14], 13);
   int li_124 = AdvancedForecast(AccountNumber(), VerificationCode, Low[0] - Low[14], 14);
   int li_128 = AdvancedForecast(AccountNumber(), VerificationCode, Low[0] - Low[14], 15);
   int li_132 = AdvancedForecast(AccountNumber(), VerificationCode, Low[0] - Low[14], 16);
   int l_timeframe_136 = AdvancedForecast(AccountNumber(), VerificationCode, Close[1] - Close[14], 17);
   int l_period_140 = AdvancedForecast(AccountNumber(), VerificationCode, Close[1] - Close[14], 18);
   int li_144 = AdvancedForecast(AccountNumber(), VerificationCode, Close[1] - Close[14], 19);
   int l_timeframe_148 = AdvancedForecast(AccountNumber(), VerificationCode, Volume[1] - Volume[14], 17);
   int l_period_152 = AdvancedForecast(AccountNumber(), VerificationCode, Volume[1] - Volume[14], 18);
   int li_156 = AdvancedForecast(AccountNumber(), VerificationCode, Volume[1] - Volume[14], 19);
   int l_timeframe_160 = AdvancedForecast(AccountNumber(), VerificationCode, Open[1] - Open[14], 20);
   int l_period_164 = AdvancedForecast(AccountNumber(), VerificationCode, Open[1] - Open[14], 21);
   int l_timeframe_168 = AdvancedForecast(AccountNumber(), VerificationCode, High[1] - High[14], 22);
   int l_period_172 = AdvancedForecast(AccountNumber(), VerificationCode, High[1] - High[14], 23);
   int li_176 = AdvancedForecast(AccountNumber(), VerificationCode, High[1] - High[14], 24);
   int l_timeframe_180 = AdvancedForecast(AccountNumber(), VerificationCode, Low[1] - Low[14], 22);
   int l_period_184 = AdvancedForecast(AccountNumber(), VerificationCode, Low[1] - Low[14], 23);
   int li_188 = AdvancedForecast(AccountNumber(), VerificationCode, Low[1] - Low[14], 24);
   int l_timeframe_192 = AdvancedForecast(AccountNumber(), VerificationCode, Low[1] - Low[7], 25);
   int l_period_196 = AdvancedForecast(AccountNumber(), VerificationCode, Low[1] - Low[7], 26);
   int li_200 = AdvancedForecast(AccountNumber(), VerificationCode, Low[1] - Low[7], 27);
   double l_irsi_204 = iRSI(NULL, l_timeframe_56, l_period_60, PRICE_CLOSE, 0);
   double l_irsi_212 = iRSI(NULL, l_timeframe_64, l_period_68, PRICE_CLOSE, 0);
   double l_icci_220 = iCCI(Symbol(), l_timeframe_72, l_period_76, PRICE_CLOSE, 0);
   double l_icci_228 = iCCI(Symbol(), l_timeframe_80, l_period_84, PRICE_CLOSE, 0);
   double l_icci_236 = iCCI(Symbol(), l_timeframe_88, l_period_92, PRICE_CLOSE, 0);
   double l_icci_244 = iCCI(Symbol(), l_timeframe_96, l_period_100, PRICE_CLOSE, 0);
   double l_ibands_252 = iBands(Symbol(), l_timeframe_104, l_period_108, li_112, li_116, PRICE_WEIGHTED, MODE_UPPER, 1);
   double l_ibands_260 = iBands(Symbol(), l_timeframe_104, l_period_108, li_112, li_116, PRICE_WEIGHTED, MODE_LOWER, 1);
   double ld_268 = NormalizeDouble(iMA(NULL, l_timeframe_136, l_period_140, li_144, MODE_SMA, PRICE_WEIGHTED, 1), 4);
   double ld_276 = NormalizeDouble(iMA(NULL, l_timeframe_148, l_period_152, li_156, MODE_SMA, PRICE_WEIGHTED, 1), 4);
   double l_imomentum_284 = iMomentum(Symbol(), l_timeframe_160, l_period_164, PRICE_CLOSE, 0);
   double l_ima_292 = iMA(Symbol(), l_timeframe_168, l_period_172, li_176, MODE_EMA, PRICE_HIGH, 0);
   double l_ima_300 = iMA(Symbol(), l_timeframe_180, l_period_184, li_188, MODE_EMA, PRICE_LOW, 0);
   double l_iwpr_308 = iWPR(Symbol(), l_timeframe_192, l_period_196, li_200);
   gi_392 = Activate(AccountNumber(), VerificationCode);
   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_396 = GetState(gi_392, AccountNumber());
   if (gi_396 == 1) gs_376 = "Authenticated";
   else {
      if (gi_396 == 2) {
         gs_376 = "Not Authenticated";
         Print("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(TRUE);
   gd_unused_340 = gd_320;
   gd_unused_348 = 0;
   int li_316 = CheckOpenTrade(magic1);
   int li_320 = CheckOpenTrade(magic2);
   int li_324 = CheckOpenTrade(magic3);
   int li_328 = CheckOpenTrade(magic4);
   int li_332 = CheckOpenTrade(magic5);
   int li_336 = CheckOpenTrade(magic6);
   for (int li_340 = 1; li_340 < Bars; li_340++) {
      if (iFractals(NULL, PERIOD_M15, MODE_LOWER, li_340) != 0.0) {
         g_ifractals_432 = iFractals(NULL, PERIOD_M15, MODE_LOWER, li_340);
         gd_unused_464 = Time[li_340];
         break;
      }
   }
   for (int li_344 = 1; li_344 < Bars; li_344++) {
      if (iFractals(NULL, PERIOD_M15, MODE_UPPER, li_344) != 0.0) {
         g_ifractals_424 = iFractals(NULL, PERIOD_M15, MODE_UPPER, li_344);
         gd_unused_456 = Time[li_344];
         break;
      }
   }
   for (int li_348 = 1; li_348 < Bars; li_348++) {
      if (iFractals(NULL, PERIOD_H1, MODE_LOWER, li_348) != 0.0) {
         g_ifractals_448 = iFractals(NULL, PERIOD_H1, MODE_LOWER, li_348);
         gd_unused_472 = Time[li_340];
         break;
      }
   }
   for (int li_352 = 1; li_352 < Bars; li_352++) {
      if (iFractals(NULL, PERIOD_H1, MODE_UPPER, li_352) != 0.0) {
         g_ifractals_440 = iFractals(NULL, PERIOD_H1, MODE_UPPER, li_352);
         gd_unused_480 = Time[li_352];
         break;
      }
   }
   gi_356 = MathRound((g_ifractals_424 - g_ifractals_432) / gd_304);
   gi_unused_360 = MathRound((g_ifractals_440 - g_ifractals_448) / gd_304);
   gd_364 = 0;
   gd_364 = TradeFunction2(AccountNumber(), VerificationCode, g_ifractals_424, g_ifractals_424, g_ifractals_432);
   gi_372 = MathRound(iATR(Symbol(), PERIOD_M15, 4, 0) / gd_304);
   bool li_356 = FALSE;
   if (Close[0] <= g_ifractals_440 && Close[0] >= g_ifractals_448) li_356 = 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_292 = 1;
                     else {
                        if (MoneyManagement == TRUE && Aggressive == TRUE && SuperAggressive == TRUE) gi_292 = 1;
                        else {
                           if (MoneyManagement == TRUE && Aggressive == TRUE && SuperAggressive == FALSE) gi_292 = 2;
                           else
                              if (MoneyManagement == TRUE && Aggressive == FALSE && SuperAggressive == TRUE) gi_292 = 3;
                        }
                     }
                     if (MicroLots == TRUE && AccountFreeMargin() < 980.0) {
                        if (AccountFreeMargin() >= 100.0 && AccountFreeMargin() <= 200.0) gd_296 = gi_292 / 100.0;
                        else {
                           if (AccountFreeMargin() > 200.0 && AccountFreeMargin() <= 300.0) gd_296 = gi_292 / 50.0;
                           else {
                              if (AccountFreeMargin() > 300.0 && AccountFreeMargin() <= 400.0) gd_296 = 0.03 * gi_292;
                              else {
                                 if (AccountFreeMargin() > 400.0 && AccountFreeMargin() <= 500.0) gd_296 = 0.04 * gi_292;
                                 else {
                                    if (AccountFreeMargin() > 500.0 && AccountFreeMargin() <= 600.0) gd_296 = 0.05 * gi_292;
                                    else {
                                       if (AccountFreeMargin() > 600.0 && AccountFreeMargin() <= 700.0) gd_296 = 0.06 * gi_292;
                                       else {
                                          if (AccountFreeMargin() > 700.0 && AccountFreeMargin() <= 800.0) gd_296 = 0.07 * gi_292;
                                          else {
                                             if (AccountFreeMargin() > 800.0 && AccountFreeMargin() <= 900.0) gd_296 = 0.08 * gi_292;
                                             else
                                                if (AccountFreeMargin() > 900.0 && AccountFreeMargin() < 980.0) gd_296 = 0.09 * gi_292;
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     } else {
                        if (!MicroLots && AccountFreeMargin() < 980.0) gd_296 = 0.1;
                        else {
                           if (AccountFreeMargin() >= 980.0 && AccountFreeMargin() <= 1980.0) gd_296 = gi_292 / 10.0;
                           else {
                              if (AccountFreeMargin() > 1980.0 && AccountFreeMargin() <= 2980.0) gd_296 = 0.2 * gi_292;
                              else {
                                 if (AccountFreeMargin() > 2980.0 && AccountFreeMargin() <= 3980.0) gd_296 = 0.3 * gi_292;
                                 else {
                                    if (AccountFreeMargin() > 3980.0 && AccountFreeMargin() <= 4980.0) gd_296 = gi_292 / 2.0;
                                    else {
                                       if (AccountFreeMargin() > 4980.0 && AccountFreeMargin() <= 5980.0) gd_296 = gi_292 / 2.0;
                                       else {
                                          if (AccountFreeMargin() > 5980.0 && AccountFreeMargin() <= 6980.0) gd_296 = 0.6 * gi_292;
                                          else {
                                             if (AccountFreeMargin() > 6980.0 && AccountFreeMargin() <= 7980.0) gd_296 = 0.7 * gi_292;
                                             else {
                                                if (AccountFreeMargin() > 7980.0 && AccountFreeMargin() <= 8980.0) gd_296 = 0.8 * gi_292;
                                                else {
                                                   if (AccountFreeMargin() > 8980.0 && AccountFreeMargin() <= 9980.0) gd_296 = 0.9 * gi_292;
                                                   else {
                                                      if (AccountFreeMargin() > 9980.0 && AccountFreeMargin() < 100000.0 && MicroLots == TRUE) gd_296 = AccountFreeMargin() / 10000.0 * gi_292;
                                                      else {
                                                         if (AccountFreeMargin() > 9980.0 && AccountFreeMargin() < 999980.0 && MicroLots == FALSE) {
                                                            ld_360 = AccountFreeMargin() / 1000.0;
                                                            ld_368 = MathFloor(ld_360);
                                                            gd_296 = ld_368 / 10.0 * gi_292;
                                                         } else
                                                            if (AccountFreeMargin() >= 999980.0 && AccountFreeMargin() < 1000000.0) gd_296 = NormalizeDouble(AccountFreeMargin() / 10000.0, 1) * gi_292;
                                                      }
                                                   }
                                                }
                                             }
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                     if (MoneyManagement) l_lots_376 = gd_296;
                     else l_lots_376 = Lots;
                     if (DayOfWeek() == 0 || DayOfWeek() == 5 && Hour() >= 14) return (0);
                     if (TradeSession()) {
                        if (!IsTradeContextBusy()) {
                           if (li_356) {
                              if (!li_316 && l_irsi_204 < gd_244 || l_irsi_212 < gd_252 && ld_268 >= Ask + 20.0 * gd_304) {
                                 l_ord_total_388 = OrdersTotal();
                                 for (int l_pos_384 = l_ord_total_388 - 1; l_pos_384 >= 0; l_pos_384--) {
                                    OrderSelect(l_pos_384, 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_392 = 0;
                                 l_ord_total_396 = OrdersTotal();
                                 for (int l_pos_400 = l_ord_total_396 - 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_392++;
                                       if (l_count_392 >= MaximumTrades) return (0);
                                    }
                                 }
                                 RefreshRates();
                                 g_ticket_400 = OrderSend(Symbol(), OP_BUY, l_lots_376, Ask, TradesSlippage, 0, 0, EAName, magic1, 0, Green);
                                 if (g_ticket_400 < 0) Print("OrderSend Error ", GetLastError());
                              }
                              if (!li_320 && l_irsi_204 > gd_228 || l_irsi_212 > gd_236 && ld_276 <= Bid - 20.0 * gd_304) {
                                 l_ord_total_388 = OrdersTotal();
                                 for (l_pos_384 = l_ord_total_388 - 1; l_pos_384 >= 0; l_pos_384--) {
                                    OrderSelect(l_pos_384, 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_392 = 0;
                                 l_ord_total_396 = OrdersTotal();
                                 for (l_pos_400 = l_ord_total_396 - 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_392++;
                                       if (l_count_392 >= MaximumTrades) return (0);
                                    }
                                 }
                                 RefreshRates();
                                 g_ticket_400 = OrderSend(Symbol(), OP_SELL, l_lots_376, Bid, TradesSlippage, 0, 0, EAName, magic2, 0, Red);
                                 if (g_ticket_400 < 0) Print("OrderSend Error ", GetLastError());
                              }
                           }
                           if (gi_356 < gi_332 && gi_372 < gi_336 && li_356) {
                              if (!li_324 && l_icci_228 <= ld_0 && l_icci_236 <= ld_8 || l_icci_220 <= ld_16 && l_icci_236 <= gd_268 && Bid <= gd_364 - 3.0 * gd_304) {
                                 l_ord_total_388 = OrdersTotal();
                                 for (l_pos_384 = l_ord_total_388 - 1; l_pos_384 >= 0; l_pos_384--) {
                                    OrderSelect(l_pos_384, 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_392 = 0;
                                 l_ord_total_396 = OrdersTotal();
                                 for (l_pos_400 = l_ord_total_396 - 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_392++;
                                       if (l_count_392 >= MaximumTrades) return (0);
                                    }
                                 }
                                 RefreshRates();
                                 g_ticket_400 = OrderSend(Symbol(), OP_BUY, l_lots_376, Ask, TradesSlippage, 0, 0, EAName, magic3, 0, Green);
                                 if (g_ticket_400 < 0) Print("OrderSend Error ", GetLastError());
                              }
                           }
                           if (!li_328 && l_icci_228 >= ld_24 && l_icci_236 >= ld_32 || l_icci_220 >= gd_276 && l_icci_236 >= ld_40 && Ask >= gd_364 + 3.0 * gd_304) {
                              l_ord_total_388 = OrdersTotal();
                              for (l_pos_384 = l_ord_total_388 - 1; l_pos_384 >= 0; l_pos_384--) {
                                 OrderSelect(l_pos_384, 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_392 = 0;
                              l_ord_total_396 = OrdersTotal();
                              for (l_pos_400 = l_ord_total_396 - 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_392++;
                                    if (l_count_392 >= MaximumTrades) return (0);
                                 }
                              }
                              RefreshRates();
                              g_ticket_400 = OrderSend(Symbol(), OP_SELL, l_lots_376, Bid, TradesSlippage, 0, 0, EAName, magic4, 0, Red);
                              if (g_ticket_400 < 0) Print("OrderSend Error ", GetLastError());
                           }
                           if (!li_332 && l_imomentum_284 <= gd_260 && l_icci_244 >= 200.0 && Ask >= gd_364 + 3.0 * gd_304) {
                              l_ord_total_388 = OrdersTotal();
                              for (l_pos_384 = l_ord_total_388 - 1; l_pos_384 >= 0; l_pos_384--) {
                                 OrderSelect(l_pos_384, 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_392 = 0;
                              l_ord_total_396 = OrdersTotal();
                              for (l_pos_400 = l_ord_total_396 - 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_392++;
                                    if (l_count_392 >= MaximumTrades) return (0);
                                 }
                              }
                              RefreshRates();
                              g_ticket_400 = OrderSend(Symbol(), OP_SELL, l_lots_376, Bid, TradesSlippage, 0, 0, EAName, magic5, 0, Red);
                              if (g_ticket_400 < 0) Print("OrderSend Error ", GetLastError());
                           }
                           if (DayOfWeek() == 0 || DayOfWeek() == 5 && Hour() >= 14) return (0);
                           if (!li_336 && l_iwpr_308 >= gd_284 && l_ima_292 > l_ibands_252 && Bid >= gd_364 + 3.0 * gd_304) {
                              l_ord_total_388 = OrdersTotal();
                              for (l_pos_384 = l_ord_total_388 - 1; l_pos_384 >= 0; l_pos_384--) {
                                 OrderSelect(l_pos_384, 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_392 = 0;
                              l_ord_total_396 = OrdersTotal();
                              for (l_pos_400 = l_ord_total_396 - 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_392++;
                                    if (l_count_392 >= MaximumTrades) return (0);
                                 }
                              }
                              RefreshRates();
                              g_ticket_400 = OrderSend(Symbol(), OP_SELL, l_lots_376, Bid, TradesSlippage, 0, 0, EAName, magic6, 0, Red);
                              if (g_ticket_400 < 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(AccountNumber(), VerificationCode, li_0, l_hour_8, li_4, Logic) == 1) return (TRUE);
   return (FALSE);
}

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_228 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 1);
   gd_236 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 2);
   gd_244 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 3);
   gd_252 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 4);
   gd_260 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 5);
   gd_268 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 6);
   gd_276 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, Logic, 7);
   gd_284 = NeuralNetworkAlgorithm(AccountNumber(), VerificationCode, 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_320 * gd_304) {
               RefreshRates();
               l_ord_close_0 = OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_328, 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_320 * gd_304) {
               RefreshRates();
               l_ord_close_0 = OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_328, 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_20;
   if (Digits == 4) li_0 = 1;
   else
      if (Digits == 5) li_0 = 10;
   int li_4 = TimeEfficiency(AccountNumber(), VerificationCode, Logic, 1);
   int li_8 = CloseEfficiency(AccountNumber(), VerificationCode, Logic, li_0, 1);
   int li_12 = TimeEfficiency(AccountNumber(), VerificationCode, Logic, 2);
   int li_16 = CloseEfficiency(AccountNumber(), VerificationCode, 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_4 && Bid >= OrderOpenPrice() + li_8 * Point) {
            RefreshRates();
            l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_328, Orange);
            if (!l_ord_close_20) {
               Print("There was an error closing the trade.Error is: ", GetLastError());
               return;
            }
         }
         if (DayOfWeek() == 5 && Hour() >= 19) {
            RefreshRates();
            l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_328, Orange);
         }
      }
      if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magic2 || OrderMagicNumber() == magic4 || OrderMagicNumber() == magic5 || OrderMagicNumber() == magic6) {
         if (TimeCurrent() - OrderOpenTime() >= 60 * li_12 && Ask <= OrderOpenPrice() - li_16 * Point) {
            RefreshRates();
            l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_328, Orange);
            if (!l_ord_close_20) {
               Print("There was an error closing the trade.Error is: ", GetLastError());
               return;
            }
         }
         if (DayOfWeek() == 5 && Hour() >= 19) {
            RefreshRates();
            l_ord_close_20 = OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_328, 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_16;
   int l_ord_total_4 = OrdersTotal();
   if (Digits == 4) li_0 = 1;
   else
      if (Digits == 5) li_0 = 10;
   int li_8 = Entropy(AccountNumber(), VerificationCode, Logic, li_0);
   for (int l_pos_12 = l_ord_total_4 - 1; l_pos_12 >= 0; l_pos_12--) {
      if (OrderSelect(l_pos_12, 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_16 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + li_8 * Point, 0, 0, Green);
            if (!(!l_bool_16)) continue;
            Print("There was an error modifying the trade.Error is: ", GetLastError());
         } else {
            if (OrderType() != OP_BUY) continue;
            l_bool_16 = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - li_8 * Point, 0, 0, Green);
            if (!(!l_bool_16)) continue;
            Print("There was an error modifying the trade.Error is: ", GetLastError());
         }
      } else Print("There was an error selecting the trade. Error is: ", GetLastError());
   }
}