/*
   Generated by EX4-TO-MQ4 decompiler V4.0.220.2c []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "© 2009, BJF Trading Group"
#property link      "http://iticsoftware.com"

#import "NeuroCNN.dll"
   int Register(string a0, int a1);
   void UnRegister();
   bool SetProperty(int a0, string a1, string a2);
   int NewNeuro(int a0);
   int NeuroLoad(string a0);
   bool NeuroSave(int a0, string a1);
   bool NeuroInit(int a0, double& a1[], int a2);
   bool NeuroPattern(int a0, double& a1[], int a2, int a3);
   bool NeuroCompute(int a0, double& a1[], int a2, int a3);
   int ChannelNN(double& a0[], int a1, int a2, int a3, double& a4[]);
#import

bool gi_76 = TRUE;
extern bool Training = FALSE;
extern int PatternBars = 100;
extern int EpochCount = 10000;
extern int NeuronsLayer1 = 100;
extern int NeuronsLayer2 = 0;
extern int NeuronsLayer3 = 0;
extern double MinTeachError = 0.0000001;
extern double MaxError = 0.05;
extern int NeuroTakeProfit = 30;
extern int NeuroStopLoss = 67;
extern int NeuroLotPercent = 80;
extern bool acc5digits = FALSE;
extern bool DelayedStops = FALSE;
extern int NoCloseMin = 0;
extern double MaxSpread = 3.0;
extern bool GMTDiferOpt = TRUE;
extern int GMTDifer = 0;
extern double Lots = 1.0;
extern int LotsPercent = 10;
int gi_172 = 100;
int gi_176 = 67;
int gi_180 = 30;
int gi_unused_184 = 0;
int gi_188 = 22;
int gi_192 = 24;
int gi_196 = 24;
int gi_200 = 0;
int gi_204 = 31;
int gi_208 = 29;
bool gi_212 = TRUE;
bool gi_216 = TRUE;
extern bool ShowComments = TRUE;
int gi_224 = 0;
int gi_228 = 18;
int gia_232[] = {0, 1, 5};
int gia_236[] = {0, 5};
int gi_unused_240 = 30;
bool gi_244 = FALSE;
bool gi_248 = TRUE;
int gi_252 = 50;
int gi_unused_256 = 1;
int gi_260 = 0;
int gi_264 = 0;
int gi_268 = 0;
bool gi_272 = FALSE;
bool gi_276 = TRUE;
bool gi_unused_280 = FALSE;
int gi_unused_284 = 10;
bool gi_unused_288 = TRUE;
int gi_unused_292 = 10;
bool gi_unused_296 = FALSE;
int gi_300 = 0;
int gi_304 = 20090208;
bool gi_308 = TRUE;
int gi_unused_312 = 3;
bool gi_316 = TRUE;
bool gi_320 = TRUE;
bool gi_324 = FALSE;
bool gi_328 = FALSE;
bool gi_332 = FALSE;
bool gi_336 = FALSE;
int g_spread_340;
int g_magic_344 = 20090209;
string g_comment_348 = "NeuralScalpingEa";
string gs_356;
double g_lots_364;
double gd_372;
double gd_380;
double gd_388;
double gd_396;
int g_color_404 = Blue;
int g_color_408 = Red;
int gi_unused_412;
int gi_unused_420;
int gi_424;
int gi_unused_428;
double gd_432 = 0.0;
double g_ord_profit_440;
int gi_448 = 0;
bool gi_unused_452 = TRUE;
int gi_460;
int gi_464;
int gi_472;
int gi_476;
int gi_480;
int gi_484;
bool gi_488;
bool gi_492 = FALSE;
int gi_496;
int gi_500 = 3;
int gi_504 = -1;
int g_timeframe_508;
int gi_512 = 7;
int g_datetime_516 = 0;
int g_count_520 = 0;
double gda_524[];
double gda_528[5];
string gs_532;
string gs_540 = ".nnb";
bool gi_548 = TRUE;

int init() {
   string ls_0;
   Comment("");
   g_spread_340 = MarketInfo(Symbol(), MODE_SPREAD);
   if (gi_336) HideTestIndicators(TRUE);
   gd_432 = Time[0];
   g_magic_344 = gi_304;
   gi_472 = gi_188;
   gi_476 = gi_192;
   gi_480 = gi_196;
   gi_484 = gi_200;
   StartRulls();
   gs_356 = " Trade time " + gi_188 + ".00  " + gi_192 + "..00 and " + gi_196 + ".00 " + gi_200 + ".00" 
   + "\n";
   Comments("Initial");
   if (GMTDiferOpt) {
      gi_188 += GMTDifer;
      gi_192 += GMTDifer;
      gi_196 += GMTDifer;
      gi_200 += GMTDifer;
   }
   if (acc5digits) {
      gi_172 = 10 * gi_172;
      gi_176 = 10 * gi_176;
      gi_180 = 10 * gi_180;
      gi_252 = 10 * gi_252;
   }
   g_timeframe_508 = Period();
   if (Register("http://saprlegprom.com/test/slp.php", 0) != 0) {
      if (Register("http://julivi.com/test/slp.php", 1) != 0) Print("Not Registered!");
      else Print("Registered julivi.com!");
   } else Print("Registered saprlegprom.com!");
   if (gi_76 == TRUE) {
      gs_532 = g_comment_348 + Symbol() + g_timeframe_508 + gs_540;
      ArrayResize(gda_524, PatternBars + 1);
      if (Training == FALSE) {
         gi_504 = NeuroLoad(gs_532);
         if (gi_504 >= 0) Print("Loaded neuro net ", gs_532);
      } else {
         if (gi_512 == 2 || gi_512 == 7) {
            gi_504 = NewNeuro(gi_512);
            if (gi_504 >= 0) {
               gda_528[0] = ArraySize(gda_524) - 1;
               gda_528[1] = NeuronsLayer1;
               gda_528[2] = NeuronsLayer2;
               gda_528[3] = NeuronsLayer3;
               gda_528[4] = 1;
               NeuroInit(gi_504, gda_528, 5);
               ls_0 = EpochCount;
               if (gi_512 == 2) SetProperty(gi_504, "BPNet.EpochCount", ls_0);
               else {
                  if (gi_512 == 7) {
                     SetProperty(gi_504, "WizNet.EpochCount", ls_0);
                     if (MinTeachError > 0.0) SetProperty(gi_504, "WizNet.MinTeachError", DoubleToStr(MinTeachError, 12));
                  }
               }
               Print("Init neuro ok 1,", ArraySize(gda_524) - 1);
            } else Print("Error to create training neuro net ", gs_532);
         }
      }
      g_datetime_516 = TimeCurrent();
   }
   return (0);
}

int deinit() {
   if (gi_76 == TRUE && Training == TRUE && gi_504 >= 0)
      if (TrainNeuroNet(gi_504)) NeuroSave(gi_504, gs_532);
   UnRegister();
   return (0);
}

int start() {
   if (!StartRulls()) return (0);
   PrepareIndicators();
   if (isOrderSell() && !TimeCurrentBar()) {
      if (isGroDtoCloseSell() || isMinProfittoClose() || TryToCloseAgain()) {
         if (gi_424 >= 0 && !gi_244) {
            CloseSellOrder();
            if (gi_76 == TRUE && Training == TRUE && gi_504 >= 0) SavePattern(gi_504);
         }
      }
      if (!gi_216) return (0);
   }
   if (isOrderBuy() && !TimeCurrentBar()) {
      if (isGroDtoCloseBuy() || isMinProfittoClose() || TryToCloseAgain()) {
         if (gi_424 >= 0 && !gi_244) {
            CloseBuyOrder();
            if (gi_76 == TRUE && Training == TRUE && gi_504 >= 0) SavePattern(gi_504);
         }
      }
      if (!gi_216) return (0);
   }
   if ((gi_212 && isOrderSell() || isOrderBuy()) || Ask - Bid > MaxSpread * Point || MaxChannelLimit()) return (0);
   if (isGroDtoSell() && !TimeCurrentBar() && isTimetoTrade(gi_188, gi_192) || isTimetoTrade(gi_196, gi_200)) {
      if (gi_76 == TRUE && gi_504 >= 0 && FillPattern()) {
         if (Training == FALSE) {
            if (NeuroIndicator(gi_504) != 1) {
               if (NeuroLotPercent > 0 && NeuroLotPercent <= 100) SendSellOrder(NeuroStopLoss, NeuroTakeProfit, NormalizeDouble(g_lots_364 * NeuroLotPercent / 100.0, gi_496));
               return (0);
            }
         }
      }
      SendSellOrder(gi_176, gi_172, g_lots_364);
      return (0);
   }
   if (isGroDtoBuy() && !TimeCurrentBar() && isTimetoTrade(gi_188, gi_192) || isTimetoTrade(gi_196, gi_200)) {
      if (gi_76 == TRUE && gi_504 >= 0 && FillPattern()) {
         if (Training == FALSE) {
            if (NeuroIndicator(gi_504) != 0) {
               if (NeuroLotPercent > 0 && NeuroLotPercent <= 100) SendBuyOrder(NeuroStopLoss, NeuroTakeProfit, NormalizeDouble(g_lots_364 * NeuroLotPercent / 100.0, gi_496));
               return (0);
            }
         }
      }
      SendBuyOrder(gi_176, gi_172, g_lots_364);
      return (0);
   }
   return (0);
}

int FillPattern() {
   double l_ihigh_0;
   double l_ilow_8;
   double l_iclose_16;
   if (gi_76 != TRUE || ArraySize(gda_524) <= 1) return (0);
   for (int li_24 = 1; li_24 < ArraySize(gda_524); li_24++) {
      l_ihigh_0 = iHigh(Symbol(), g_timeframe_508, li_24);
      l_ilow_8 = iLow(Symbol(), g_timeframe_508, li_24);
      l_iclose_16 = iClose(Symbol(), g_timeframe_508, li_24);
      if (l_ihigh_0 - l_ilow_8 <= 0.0) gda_524[li_24] = 0;
      else gda_524[li_24] = (l_iclose_16 - l_ilow_8 - (l_ihigh_0 - l_iclose_16)) / (l_ihigh_0 - l_ilow_8) / 2.0 + 0.5;
   }
   gi_548 = FALSE;
   return (1);
}

int SavePattern(int ai_0) {
   int l_hist_total_4;
   int l_cmd_12;
   double l_ord_profit_16;
   if (gi_548 == FALSE) {
      l_hist_total_4 = OrdersHistoryTotal();
      if (l_hist_total_4 > 0) {
         for (int l_pos_8 = l_hist_total_4 - 1; l_pos_8 >= 0; l_pos_8--) {
            OrderSelect(l_pos_8, SELECT_BY_POS, MODE_HISTORY);
            if (OrderMagicNumber() == g_magic_344 && OrderSymbol() == Symbol()) {
               l_ord_profit_16 = OrderProfit();
               l_cmd_12 = OrderType();
               if (l_ord_profit_16 < 0.0) {
                  if (l_cmd_12 == OP_BUY) l_cmd_12 = 1;
                  else
                     if (l_cmd_12 == OP_SELL) l_cmd_12 = 0;
               }
               gda_524[0] = l_cmd_12;
               if (ai_0 >= 0) {
                  if (Training == TRUE) {
                     NeuroPattern(ai_0, gda_524, 1, ArraySize(gda_524) - 1);
                     g_count_520++;
                  }
               }
               gi_548 = TRUE;
               return (1);
            }
         }
      }
   }
   return (0);
}

bool TrainNeuroNet(int ai_0) {
   if (ai_0 >= 0) {
      if (gi_512 == 7) SetProperty(ai_0, "WizNet.PatternsMixed", "true");
      Print("Train Neural Network on ", g_count_520, " parrerns");
      SetProperty(ai_0, "Teached", "true");
      g_datetime_516 = TimeCurrent();
      g_count_520 = 0;
      return (TRUE);
   } else return (FALSE);
}

int NeuroIndicator(int ai_0) {
   int li_ret_4 = -1;
   if (ai_0 >= 0 && ArraySize(gda_524) > 1) {
      gda_524[0] = li_ret_4;
      NeuroCompute(ai_0, gda_524, 1, ArraySize(gda_524) - 1);
      if (gda_524[0] > 1.0 - MaxError) li_ret_4 = 1;
      else
         if (gda_524[0] < MaxError) li_ret_4 = 0;
   }
   return (li_ret_4);
}

bool TimeCurrentBar() {
   bool li_ret_0 = FALSE;
   if (gi_272 && Time[0] == gd_432) li_ret_0 = TRUE;
   return (li_ret_0);
}

int isOrderSell() {
   bool li_ret_0 = FALSE;
   int l_pos_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (l_pos_4 = 0; l_pos_4 < l_ord_total_12; l_pos_4++) {
      OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderType() == OP_SELL) {
         if (OrderMagicNumber() == g_magic_344) {
            li_ret_0 = TRUE;
            g_ord_profit_440 = OrderProfit();
            gi_424 = (OrderOpenPrice() - Ask) / Point;
            break;
         }
      }
   }
   if (gi_460 && !li_ret_0)
      if (OrderStopLoss() != 0.0 || OrderTakeProfit() != 0.0) gd_432 = Time[0];
   gi_460 = li_ret_0;
   return (li_ret_0);
}

int isOrderBuy() {
   bool li_ret_0 = FALSE;
   int l_pos_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (l_pos_4 = 0; l_pos_4 < l_ord_total_12; l_pos_4++) {
      OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderType() == OP_BUY) {
         if (OrderMagicNumber() == g_magic_344) {
            li_ret_0 = TRUE;
            g_ord_profit_440 = OrderProfit();
            gi_424 = (Bid - OrderOpenPrice()) / Point;
            break;
         }
      }
   }
   if (gi_464 && !li_ret_0)
      if (OrderStopLoss() != 0.0 || OrderTakeProfit() != 0.0) gd_432 = Time[0];
   gi_464 = li_ret_0;
   return (li_ret_0);
}

int CloseBuyOrder() {
   bool l_bool_8;
   bool li_ret_0 = FALSE;
   int l_pos_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (l_pos_4 = 0; l_pos_4 < l_ord_total_12; l_pos_4++) {
      l_bool_8 = OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderType() == OP_BUY) {
         if (TimeCurrent() - OrderOpenTime() < 60 * NoCloseMin || isFreezLevel()) continue;
         if (OrderMagicNumber() == g_magic_344) {
            if (OrderClose(OrderTicket(), OrderLots(), Bid, g_spread_340, g_color_404)) {
               li_ret_0 = TRUE;
               gd_432 = Time[0];
               gi_488 = FALSE;
            } else {
               Comments("Error close BUY order!");
               gi_488 = TRUE;
            }
         }
      }
   }
   return (li_ret_0);
}

int CloseSellOrder() {
   bool l_bool_8;
   bool li_ret_0 = FALSE;
   int l_pos_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (l_pos_4 = 0; l_pos_4 < l_ord_total_12; l_pos_4++) {
      l_bool_8 = OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderType() == OP_SELL) {
         if (TimeCurrent() - OrderOpenTime() < 60 * NoCloseMin || isFreezLevel()) continue;
         if (OrderMagicNumber() == g_magic_344) {
            if (OrderClose(OrderTicket(), OrderLots(), Ask, g_spread_340, g_color_408)) {
               li_ret_0 = TRUE;
               gd_432 = Time[0];
               gi_488 = FALSE;
            } else {
               Comments("Error close SELL order!");
               gi_488 = TRUE;
            }
         }
      }
   }
   return (li_ret_0);
}

int TryToCloseAgain() {
   bool li_ret_0 = FALSE;
   if (!gi_488) gi_448 = gi_300;
   else {
      gi_448--;
      if (gi_448 > 0) li_ret_0 = TRUE;
      else gi_488 = FALSE;
   }
   return (li_ret_0);
}

int isFreezLevel() {
   double l_price_4;
   double ld_12;
   bool li_ret_0 = FALSE;
   if (gi_248) {
      if (OrderStopLoss() != 0.0 || OrderTakeProfit() != 0.0) {
         if (OrderType() == OP_BUY) l_price_4 = Bid;
         if (OrderType() == OP_SELL) l_price_4 = Ask;
         ld_12 = MarketInfo(Symbol(), MODE_FREEZELEVEL) * Point;
         if (OrderStopLoss() != 0.0 && ld_12 > MathAbs(l_price_4 - OrderStopLoss())) li_ret_0 = TRUE;
         if (OrderTakeProfit() != 0.0 && ld_12 > MathAbs(l_price_4 - OrderTakeProfit())) li_ret_0 = TRUE;
      }
   }
   return (li_ret_0);
}

int SendBuyOrder(double a_price_0, double a_price_8, double a_lots_16) {
   bool l_bool_32;
   int l_ticket_24 = 0;
   gi_488 = FALSE;
   if (a_price_0 != 0.0) {
      if (a_price_0 < MarketInfo(Symbol(), MODE_STOPLEVEL)) a_price_0 = MarketInfo(Symbol(), MODE_STOPLEVEL);
      a_price_0 = NormalizeDouble(Bid - a_price_0 * Point, MarketInfo(Symbol(), MODE_DIGITS));
   }
   if (a_price_8 != 0.0) {
      if (a_price_8 < MarketInfo(Symbol(), MODE_STOPLEVEL)) a_price_8 = MarketInfo(Symbol(), MODE_STOPLEVEL);
      a_price_8 = NormalizeDouble(Ask + a_price_8 * Point, MarketInfo(Symbol(), MODE_DIGITS));
   }
   if (DelayedStops) {
      l_ticket_24 = OrderSend(Symbol(), OP_BUY, a_lots_16, Ask, g_spread_340, 0, 0, g_comment_348, g_magic_344, 0, g_color_404);
      if (l_ticket_24 > 0) {
         OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES);
         for (int l_count_28 = 0; l_count_28 < gi_500; l_count_28++) {
            l_bool_32 = OrderModify(l_ticket_24, OrderOpenPrice(), a_price_0, a_price_8, 0);
            if (l_bool_32) break;
         }
      }
   } else l_ticket_24 = OrderSend(Symbol(), OP_BUY, a_lots_16, Ask, g_spread_340, a_price_0, a_price_8, g_comment_348, g_magic_344, 0, g_color_404);
   if (l_ticket_24 > 0) {
      if (OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES)) {
         gd_432 = Time[0];
         gi_unused_412 = Bars;
         gi_unused_420 = l_ticket_24;
         gi_unused_428 = 0;
      }
   } else {
      Comments("Error open BUY order!");
      return (0);
   }
   return (1);
}

int SendSellOrder(double a_price_0, double a_price_8, double a_lots_16) {
   bool l_bool_32;
   int l_ticket_24 = 0;
   gi_488 = FALSE;
   if (a_price_0 != 0.0) {
      if (a_price_0 < MarketInfo(Symbol(), MODE_STOPLEVEL)) a_price_0 = MarketInfo(Symbol(), MODE_STOPLEVEL);
      a_price_0 = NormalizeDouble(Ask + a_price_0 * Point, MarketInfo(Symbol(), MODE_DIGITS));
   }
   if (a_price_8 != 0.0) {
      if (a_price_8 < MarketInfo(Symbol(), MODE_STOPLEVEL)) a_price_8 = MarketInfo(Symbol(), MODE_STOPLEVEL);
      a_price_8 = NormalizeDouble(Bid - a_price_8 * Point, MarketInfo(Symbol(), MODE_DIGITS));
   }
   if (DelayedStops) {
      l_ticket_24 = OrderSend(Symbol(), OP_SELL, a_lots_16, Bid, g_spread_340, 0, 0, g_comment_348, g_magic_344, 0, g_color_408);
      if (l_ticket_24 > 0) {
         OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES);
         for (int l_count_28 = 0; l_count_28 < gi_500; l_count_28++) {
            l_bool_32 = OrderModify(l_ticket_24, OrderOpenPrice(), a_price_0, a_price_8, 0);
            if (l_bool_32) break;
         }
      }
   } else l_ticket_24 = OrderSend(Symbol(), OP_SELL, a_lots_16, Bid, g_spread_340, a_price_0, a_price_8, g_comment_348, g_magic_344, 0, g_color_408);
   if (l_ticket_24 > 0) {
      if (OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES)) {
         gd_432 = Time[0];
         gi_unused_412 = Bars;
         gi_unused_420 = l_ticket_24;
         gi_unused_428 = 0;
      }
   } else {
      Comments("Error open SELL order!");
      return (0);
   }
   return (1);
}

bool StartRulls() {
   if (!gi_492) gi_492 = TRUE;
   else {
      if (gi_472 != gi_188 || gi_476 != gi_192 || gi_480 != gi_196 || gi_484 != gi_200) {
         gi_472 = gi_188;
         gi_476 = gi_192;
         gi_480 = gi_196;
         gi_484 = gi_200;
         Comments("Another trade time EA");
      }
   }
   if (IsOptimization()) {
      if (gi_188 > 12) return (FALSE);
      if (gi_192 > 12) return (FALSE);
      if (gi_196 < 12) return (FALSE);
      if (gi_200 < 12) return (FALSE);
      if (gi_188 > gi_192 || gi_196 > gi_200) return (FALSE);
   }
   if (Bars < 100) {
      Comments("StartRulls() Bars less than 100");
      return (FALSE);
   }
   double ld_0 = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2);
   double ld_8 = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2);
   double ld_16 = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2);
   if (ld_0 == 0.01) gi_496 = 2;
   else gi_496 = 1;
   if (Lots == 0.0) g_lots_364 = NormalizeDouble(AccountFreeMargin() * LotsPercent / 100000.0, gi_496);
   else g_lots_364 = Lots;
   if (g_lots_364 > ld_16) g_lots_364 = ld_16;
   if (g_lots_364 < ld_8) g_lots_364 = ld_8;
   return (TRUE);
}

int isMinProfittoClose() {
   bool li_ret_0 = FALSE;
   if (gi_424 > 0 && gi_424 >= gi_180 && gi_180 != 0) li_ret_0 = TRUE;
   return (li_ret_0);
}

int isGroDtoBuy() {
   bool li_ret_0 = FALSE;
   if (!gi_332) {
      if (Bid < gd_380 - Point * gi_268 || (gi_276 && Bid <= gd_380 - Point * gi_268)) li_ret_0 = TRUE;
   } else
      if (Bid > gd_372 || (gi_276 && Bid >= gd_372)) li_ret_0 = TRUE;
   return (li_ret_0);
}

int isGroDtoSell() {
   bool li_ret_0 = FALSE;
   if (!gi_332) {
      if (Bid > gd_372 + Point * gi_264 || (gi_276 && Bid >= gd_372 + Point * gi_264)) li_ret_0 = TRUE;
   } else
      if (Bid < gd_380 || (gi_276 && Bid <= gd_380)) li_ret_0 = TRUE;
   return (li_ret_0);
}

int isGroDtoCloseSell() {
   bool li_ret_0 = FALSE;
   if (!gi_332) {
      if (Bid < gd_396 - Point * gi_268 || (gi_276 && Bid <= gd_396 - Point * gi_268)) li_ret_0 = TRUE;
   } else
      if (Bid > gd_388 || (gi_276 && Bid >= gd_388)) li_ret_0 = TRUE;
   return (li_ret_0);
}

int isGroDtoCloseBuy() {
   bool li_ret_0 = FALSE;
   if (!gi_332) {
      if (Bid > gd_388 + Point * gi_264 || (gi_276 && Bid >= gd_388 + Point * gi_264)) li_ret_0 = TRUE;
   } else
      if (Bid < gd_396 || (gi_276 && Bid <= gd_396)) li_ret_0 = TRUE;
   return (li_ret_0);
}

int isTimetoTrade(int ai_0, int ai_4) {
   int l_arr_size_12;
   int l_day_of_week_16 = DayOfWeek();
   if (ai_0 == gi_188 && ai_4 == gi_192) {
      l_arr_size_12 = ArraySize(gia_232);
      for (int l_index_8 = 0; l_index_8 < l_arr_size_12; l_index_8++)
         if (gia_232[l_index_8] == l_day_of_week_16) return (0);
   } else {
      if (ai_0 == gi_196 && ai_4 == gi_200) {
         l_arr_size_12 = ArraySize(gia_236);
         for (l_index_8 = 0; l_index_8 < l_arr_size_12; l_index_8++)
            if (gia_236[l_index_8] == l_day_of_week_16) return (0);
      }
   }
   bool li_ret_20 = FALSE;
   int l_hour_24 = Hour();
   if (ai_0 > 23 || ai_0 < 0) ai_0 = 0;
   if (ai_4 > 23 || ai_4 < 0) ai_4 = 0;
   if (ai_0 < ai_4 && (Hour() >= ai_0 && Hour() < ai_4)) li_ret_20 = TRUE;
   if (ai_0 > ai_4 && Hour() >= ai_0 || Hour() < ai_4) li_ret_20 = TRUE;
   if (DayOfWeek() != gi_260 && gi_260 != 0) li_ret_20 = FALSE;
   return (li_ret_20);
}

int Comments(string as_0) {
   string ls_20;
   bool li_ret_8 = FALSE;
   if (gi_316) {
      ls_20 = "";
      if (gi_320) ls_20 = ls_20 + TimeToStr(TimeCurrent(), TIME_SECONDS) + " : ";
      if (gi_324) ls_20 = ls_20 + g_comment_348;
      if (gi_328) ls_20 = ls_20 + "(" + g_magic_344 + ")";
      if (gi_324 || gi_328) ls_20 = ls_20 + ": ";
      Print(ls_20 + as_0);
   }
   if (gi_308) {
      if (ShowComments) Comment(gs_356 + ls_20 + as_0);
   } else
      if (ShowComments) Comment(ls_20 + as_0);
   return (li_ret_8);
}

int MaxChannelLimit() {
   int li_4;
   int li_8;
   bool li_ret_0 = FALSE;
   if (gi_224 != 0) {
      li_4 = High[iHighest(NULL, 0, MODE_HIGH, gi_228, 1)] / Point;
      li_8 = Low[iLowest(NULL, 0, MODE_LOW, gi_228, 1)] / Point;
      if (li_4 - li_8 > gi_224) li_ret_0 = TRUE;
   }
   return (li_ret_0);
}

void PrepareIndicators() {
   double lda_0[][6];
   double lda_4[4];
   int li_8 = ArrayCopyRates(lda_0);
   int li_12 = gi_204;
   int li_16 = gi_208;
   ChannelNN(lda_0, li_8, li_12, li_16, lda_4);
   gd_380 = lda_4[0];
   gd_372 = lda_4[1];
   gd_396 = lda_4[2];
   gd_388 = lda_4[3];
}
