/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website:  hTT P ://w w w.me T aQ UO Te S . n E T
   E-mail : s U PP O r T@mET aQu o t eS. nE t
*/
#property copyright "Copyright © 2012, DMITRIUS"
#property link      ""

double G_maxlot_76 = 0.0;
string Gs_84 = "KLERIK ABSOLUT V 6.1";
double Gd_92 = 2.0;
string Gs_100 = "KLERIK ABSOLUT V 6.1";
int Gi_unused_108 = 1;
extern string __1__ = " 1 for Martingale or 2 for constants lots";
extern int MMType = 1;
bool Gi_124 = TRUE;
extern string __2__ = "Martingale level increase";
extern double LotMultiplikator = 2.0;
double Gd_144;
double G_slippage_152 = 5.0;
extern string __3__ = "same lot or recalculate";
extern string _____ = "true - lot constant, or false - recalculate by balance";
extern bool LotConst_or_not = FALSE;
extern double Lot = 0.1;
extern double RiskPercent = 10.0;
double Gd_196;
extern string __4__ = "Profit taking";
extern double TakeProfit = 5.0;
double Gd_220;
double G_pips_228 = 0.0;
double Gd_236 = 10.0;
double Gd_244 = 10.0;
extern string __5__ = "Network orders";
extern double Step = 5.0;
double Gd_268;
extern string __6__ = "maximum number of open trades at the same time";
extern int MaxTrades = 30;
extern string __7__ = "Percentage of maximum loss to stop trade";
extern bool UseEquityStop = FALSE;
extern double TotalEquityRisk = 20.0;
bool Gi_308 = FALSE;
bool Gi_312 = FALSE;
bool Gi_316 = FALSE;
double Gd_320 = 48.0;
bool Gi_328 = FALSE;
int Gi_332 = 2;
int Gi_336 = 16;
extern string __8__ = "Identification number for this EA";
extern int Magic = 1111111;
int Gi_352;
extern string __9__ = "Show relationship Earnings";
extern bool ShowTableOnTesting = TRUE;
extern string _ = "(True list above shows)";
double G_price_376;
double Gd_384;
double Gd_unused_392;
double Gd_unused_400;
double G_price_408;
double G_bid_416;
double G_ask_424;
double Gd_432;
double Gd_440;
double Gd_448;
bool Gi_456;
datetime G_time_460 = 0;
int Gi_464;
int Gi_468 = 0;
double Gd_472;
int G_pos_480 = 0;
int Gi_484;
double Gd_488 = 0.0;
bool Gi_496 = FALSE;
bool Gi_500 = FALSE;
bool Gi_504 = FALSE;
int Gi_508;
bool Gi_512 = FALSE;
int G_datetime_516 = 0;
int G_datetime_520 = 0;
double Gd_524;
double Gd_532;
extern string __10__ = "level of protection";
extern double POROG = 0.99;
extern string __11__ = "protection fund";
extern double STEP = 200.0;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   Gd_448 = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   if (IsTesting() == TRUE) f0_9();
   if (IsTesting() == FALSE) f0_9();
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double order_lots_0;
   double order_lots_8;
   double iclose_16;
   double iclose_24;
   int Li_unused_32 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   int Li_unused_36 = MarketInfo(Symbol(), MODE_SPREAD);
   double point_40 = MarketInfo(Symbol(), MODE_POINT);
   double bid_48 = MarketInfo(Symbol(), MODE_BID);
   double ask_56 = MarketInfo(Symbol(), MODE_ASK);
   int Li_unused_64 = MarketInfo(Symbol(), MODE_DIGITS);
   if (G_maxlot_76 == 0.0) G_maxlot_76 = MarketInfo(Symbol(), MODE_MAXLOT);
   double minlot_68 = MarketInfo(Symbol(), MODE_MINLOT);
   if (((!IsOptimization()) && (!IsTesting()) && (!IsVisualMode())) || (ShowTableOnTesting && IsTesting() && (!IsOptimization()))) f0_12();
   if (LotConst_or_not) Gd_196 = Lot;
   else Gd_196 = AccountBalance() * RiskPercent / 100.0 / 10000.0;
   if (Gd_196 < minlot_68) Print("Расчетный лот  " + Gd_196 + "  меньше минимально допустимого для торговли  " + minlot_68);
   if (Gd_196 > G_maxlot_76 && G_maxlot_76 > 0.0) Print("Расчетный лот  " + Gd_196 + "  больше максимально допустимого для торговли  " + G_maxlot_76);
   Gd_144 = LotMultiplikator;
   if (AccountFreeMargin() <= AccountBalance() * POROG) {
      Gd_220 = 0;
      Gd_268 = STEP;
   } else {
      Gd_220 = TakeProfit;
      Gd_268 = Step;
   }
   Gi_352 = Magic;
   string Ls_76 = "false";
   string Ls_84 = "false";
   if (Gi_328 == FALSE || (Gi_328 && (Gi_336 > Gi_332 && (Hour() >= Gi_332 && Hour() <= Gi_336)) || (Gi_332 > Gi_336 && (!Hour() >= Gi_336 && Hour() <= Gi_332)))) Ls_76 = "true";
   if (Gi_328 && (Gi_336 > Gi_332 && (!Hour() >= Gi_332 && Hour() <= Gi_336)) || (Gi_332 > Gi_336 && (Hour() >= Gi_336 && Hour() <= Gi_332))) Ls_84 = "true";
   if (Gi_312) f0_17(Gd_236, Gd_244, G_price_408);
   if (Gi_316) {
      if (TimeCurrent() >= Gi_464) {
         f0_3();
         Print("Closed All due to TimeOut");
      }
   }
   if (G_time_460 == Time[0]) return (0);
   G_time_460 = Time[0];
   double Ld_92 = f0_5();
   if (UseEquityStop) {
      if (Ld_92 < 0.0 && MathAbs(Ld_92) > TotalEquityRisk / 100.0 * f0_7()) {
         f0_3();
         Print("Closed All due to Stop Out");
         Gi_512 = FALSE;
      }
   }
   Gi_484 = f0_15();
   if (Gi_484 == 0) Gi_456 = FALSE;
   for (G_pos_480 = OrdersTotal() - 1; G_pos_480 >= 0; G_pos_480--) {
      OrderSelect(G_pos_480, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
         if (OrderType() == OP_BUY) {
            Gi_500 = TRUE;
            Gi_504 = FALSE;
            order_lots_0 = OrderLots();
            break;
         }
      }
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
         if (OrderType() == OP_SELL) {
            Gi_500 = FALSE;
            Gi_504 = TRUE;
            order_lots_8 = OrderLots();
            break;
         }
      }
   }
   if (Gi_484 > 0 && Gi_484 <= MaxTrades) {
      RefreshRates();
      Gd_432 = f0_2();
      Gd_440 = f0_6();
      if (Gi_500 && Gd_432 - Ask >= Gd_268 * Point) Gi_496 = TRUE;
      if (Gi_504 && Bid - Gd_440 >= Gd_268 * Point) Gi_496 = TRUE;
   }
   if (Gi_484 < 1) {
      Gi_504 = FALSE;
      Gi_500 = FALSE;
      Gi_496 = TRUE;
      Gd_384 = AccountEquity();
   }
   if (Gi_496) {
      Gd_432 = f0_2();
      Gd_440 = f0_6();
      if (Gi_504) {
         if (Gi_308 || Ls_84 == "true") {
            f0_1(0, 1);
            Gd_472 = NormalizeDouble(Gd_144 * order_lots_8, Gd_92);
         } else Gd_472 = f0_13(OP_SELL);
         if (Gi_124 && Ls_76 == "true") {
            Gi_468 = Gi_484;
            if (Gd_472 > 0.0) {
               RefreshRates();
               Gi_508 = f0_14(1, Gd_472, Bid, G_slippage_152, Ask, 0, 0, Symbol() + "-" + Gs_84 + "-" + Gi_468, Gi_352, 0, HotPink);
               if (Gi_508 < 0) {
                  Print("Error: ", GetLastError());
                  return (0);
               }
               Gd_440 = f0_6();
               Gi_496 = FALSE;
               Gi_512 = TRUE;
            }
         }
      } else {
         if (Gi_500) {
            if (Gi_308 || Ls_84 == "true") {
               f0_1(1, 0);
               Gd_472 = NormalizeDouble(Gd_144 * order_lots_0, Gd_92);
            } else Gd_472 = f0_13(OP_BUY);
            if (Gi_124 && Ls_76 == "true") {
               Gi_468 = Gi_484;
               if (Gd_472 > 0.0) {
                  Gi_508 = f0_14(0, Gd_472, Ask, G_slippage_152, Bid, 0, 0, Symbol() + "-" + Gs_84 + "-" + Gi_468, Gi_352, 0, Lime);
                  if (Gi_508 < 0) {
                     Print("Error: ", GetLastError());
                     return (0);
                  }
                  Gd_432 = f0_2();
                  Gi_496 = FALSE;
                  Gi_512 = TRUE;
               }
            }
         }
      }
   }
   if (Gi_496 && Gi_484 < 1) {
      iclose_16 = iClose(Symbol(), 0, 2);
      iclose_24 = iClose(Symbol(), 0, 1);
      G_bid_416 = Bid;
      G_ask_424 = Ask;
      if ((!Gi_504) && (!Gi_500) && Ls_76 == "true") {
         Gi_468 = Gi_484;
         if (iclose_16 > iclose_24) {
            Gd_472 = f0_13(OP_SELL);
            if (Gd_472 > 0.0) {
               Gi_508 = f0_14(1, Gd_472, G_bid_416, G_slippage_152, G_bid_416, 0, 0, Symbol() + "-" + Gs_84 + "-" + Gi_468, Gi_352, 0, HotPink);
               if (Gi_508 < 0) {
                  Print(Gd_472, "Error: ", GetLastError());
                  return (0);
               }
               Gd_432 = f0_2();
               Gi_512 = TRUE;
            }
         } else {
            Gd_472 = f0_13(OP_BUY);
            if (Gd_472 > 0.0) {
               Gi_508 = f0_14(0, Gd_472, G_ask_424, G_slippage_152, G_ask_424, 0, 0, Symbol() + "-" + Gs_84 + "-" + Gi_468, Gi_352, 0, Lime);
               if (Gi_508 < 0) {
                  Print(Gd_472, "Error: ", GetLastError());
                  return (0);
               }
               Gd_440 = f0_6();
               Gi_512 = TRUE;
            }
         }
      }
      if (Gi_508 > 0) Gi_464 = TimeCurrent() + 60.0 * (60.0 * Gd_320);
      Gi_496 = FALSE;
   }
   Gi_484 = f0_15();
   G_price_408 = 0;
   double Ld_100 = 0;
   for (G_pos_480 = OrdersTotal() - 1; G_pos_480 >= 0; G_pos_480--) {
      OrderSelect(G_pos_480, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
         if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
            G_price_408 += OrderOpenPrice() * OrderLots();
            Ld_100 += OrderLots();
         }
      }
   }
   if (Gi_484 > 0) G_price_408 = NormalizeDouble(G_price_408 / Ld_100, Digits);
   if (Gi_512) {
      for (G_pos_480 = OrdersTotal() - 1; G_pos_480 >= 0; G_pos_480--) {
         OrderSelect(G_pos_480, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
            if (OrderType() == OP_BUY) {
               G_price_376 = G_price_408 + Gd_220 * Point;
               Gd_unused_392 = G_price_376;
               Gd_488 = G_price_408 - G_pips_228 * Point;
               Gi_456 = TRUE;
            }
         }
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
            if (OrderType() == OP_SELL) {
               G_price_376 = G_price_408 - Gd_220 * Point;
               Gd_unused_400 = G_price_376;
               Gd_488 = G_price_408 + G_pips_228 * Point;
               Gi_456 = TRUE;
            }
         }
      }
   }
   if (Gi_512) {
      if (Gi_456 == TRUE) {
         for (G_pos_480 = OrdersTotal() - 1; G_pos_480 >= 0; G_pos_480--) {
            OrderSelect(G_pos_480, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) OrderModify(OrderTicket(), G_price_408, OrderStopLoss(), G_price_376, 0, Yellow);
            Gi_512 = FALSE;
         }
      }
   }
   return (0);
}

// 9A116C50D133C8648404081885194300
double f0_10(double Ad_0) {
   return (NormalizeDouble(Ad_0, Digits));
}

// 169720DB8C7DA7F48F483E787B4A2725
int f0_1(bool Ai_0 = TRUE, bool Ai_4 = TRUE) {
   int Li_ret_8 = 0;
   for (int pos_12 = OrdersTotal() - 1; pos_12 >= 0; pos_12--) {
      if (OrderSelect(pos_12, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
            if (OrderType() == OP_BUY && Ai_0) {
               RefreshRates();
               if (!IsTradeContextBusy()) {
                  if (!OrderClose(OrderTicket(), OrderLots(), f0_10(Bid), 5, CLR_NONE)) {
                     Print("Error close BUY " + OrderTicket());
                     Li_ret_8 = -1;
                  }
               } else {
                  if (G_datetime_516 == iTime(NULL, 0, 0)) return (-2);
                  G_datetime_516 = iTime(NULL, 0, 0);
                  Print("Need close BUY " + OrderTicket() + ". Trade Context Busy");
                  return (-2);
               }
            }
            if (OrderType() == OP_SELL && Ai_4) {
               RefreshRates();
               if (!IsTradeContextBusy()) {
                  if (!(!OrderClose(OrderTicket(), OrderLots(), f0_10(Ask), 5, CLR_NONE))) continue;
                  Print("Error close SELL " + OrderTicket());
                  Li_ret_8 = -1;
                  continue;
               }
               if (G_datetime_520 == iTime(NULL, 0, 0)) return (-2);
               G_datetime_520 = iTime(NULL, 0, 0);
               Print("Need close SELL " + OrderTicket() + ". Trade Context Busy");
               return (-2);
            }
         }
      }
   }
   return (Li_ret_8);
}

// BD1F338B493E3233DF78411E167716E8
double f0_13(int A_cmd_0) {
   double Ld_ret_4;
   int datetime_12;
   switch (MMType) {
   case 0:
      Ld_ret_4 = Gd_196;
      break;
   case 1:
      Ld_ret_4 = NormalizeDouble(Gd_196 * MathPow(Gd_144, Gi_468), Gd_92);
      break;
   case 2:
      datetime_12 = 0;
      Ld_ret_4 = Gd_196;
      for (int pos_20 = OrdersHistoryTotal() - 1; pos_20 >= 0; pos_20--) {
         if (OrderSelect(pos_20, SELECT_BY_POS, MODE_HISTORY)) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
               if (datetime_12 < OrderCloseTime()) {
                  datetime_12 = OrderCloseTime();
                  if (OrderProfit() < 0.0) {
                     Ld_ret_4 = NormalizeDouble(OrderLots() * Gd_144, Gd_92);
                     continue;
                  }
                  Ld_ret_4 = Gd_196;
               }
            }
         } else return (-3);
      }
   }
   if (AccountFreeMarginCheck(Symbol(), A_cmd_0, Ld_ret_4) <= 0.0) return (-1);
   if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) return (-2);
   return (Ld_ret_4);
}

// CBBD1151F6D49BC6C817A0B96D15036D
int f0_15() {
   int count_0 = 0;
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352)
         if (OrderType() == OP_SELL || OrderType() == OP_BUY) count_0++;
   }
   return (count_0);
}

// 41BB59E8D36C416E4C62910D9E765220
void f0_3() {
   for (int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--) {
      OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352) {
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, G_slippage_152, Blue);
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, G_slippage_152, Red);
         }
         Sleep(1000);
      }
   }
}

// C159FD8BED695B6E6A109D3B72C199C3
int f0_14(int Ai_0, double A_lots_4, double A_price_12, int A_slippage_20, double Ad_24, int Ai_unused_32, int Ai_36, string A_comment_40, int A_magic_48, int A_datetime_52, color A_color_56) {
   int ticket_60 = 0;
   int error_64 = 0;
   int count_68 = 0;
   int Li_72 = 100;
   switch (Ai_0) {
   case 2:
      for (count_68 = 0; count_68 < Li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_BUYLIMIT, A_lots_4, A_price_12, A_slippage_20, f0_11(Ad_24, G_pips_228), f0_16(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
            A_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(1000);
      }
      break;
   case 4:
      for (count_68 = 0; count_68 < Li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_BUYSTOP, A_lots_4, A_price_12, A_slippage_20, f0_11(Ad_24, G_pips_228), f0_16(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
            A_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 0:
      for (count_68 = 0; count_68 < Li_72; count_68++) {
         RefreshRates();
         ticket_60 = OrderSend(Symbol(), OP_BUY, A_lots_4, Ask, A_slippage_20, f0_11(Bid, G_pips_228), f0_16(Ask, Ai_36), A_comment_40, A_magic_48, A_datetime_52, A_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 3:
      for (count_68 = 0; count_68 < Li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_SELLLIMIT, A_lots_4, A_price_12, A_slippage_20, f0_0(Ad_24, G_pips_228), f0_4(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
            A_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 5:
      for (count_68 = 0; count_68 < Li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_SELLSTOP, A_lots_4, A_price_12, A_slippage_20, f0_0(Ad_24, G_pips_228), f0_4(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
            A_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 1:
      for (count_68 = 0; count_68 < Li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_SELL, A_lots_4, Bid, A_slippage_20, f0_0(Ask, G_pips_228), f0_4(Bid, Ai_36), A_comment_40, A_magic_48, A_datetime_52, A_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
   }
   return (ticket_60);
}

// A04259EF619300E271488B8ABD9DF8A9
double f0_11(double Ad_0, int Ai_8) {
   if (Ai_8 == 0) return (0);
   return (Ad_0 - Ai_8 * Point);
}

// 0D578CA46072792DE50D5B9F5F5F8784
double f0_0(double Ad_0, int Ai_8) {
   if (Ai_8 == 0) return (0);
   return (Ad_0 + Ai_8 * Point);
}

// CE75B31DDDC1519B313C4C612EF22D86
double f0_16(double Ad_0, int Ai_8) {
   if (Ai_8 == 0) return (0);
   return (Ad_0 + Ai_8 * Point);
}

// 4347D7B92E8469B198EAA742F66BBE62
double f0_4(double Ad_0, int Ai_8) {
   if (Ai_8 == 0) return (0);
   return (Ad_0 - Ai_8 * Point);
}

// 4A186EA1A04A05E39FD2E7A94BB28576
double f0_5() {
   double Ld_ret_0 = 0;
   for (G_pos_480 = OrdersTotal() - 1; G_pos_480 >= 0; G_pos_480--) {
      OrderSelect(G_pos_480, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352)
         if (OrderType() == OP_BUY || OrderType() == OP_SELL) Ld_ret_0 += OrderProfit();
   }
   return (Ld_ret_0);
}

// FDD5E0C68EEEAC73C07299767285F173
void f0_17(int Ai_0, int Ai_4, double A_price_8) {
   int Li_16;
   double order_stoploss_20;
   double price_28;
   if (Ai_4 != 0) {
      for (int pos_36 = OrdersTotal() - 1; pos_36 >= 0; pos_36--) {
         if (OrderSelect(pos_36, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
            if (OrderSymbol() == Symbol() || OrderMagicNumber() == Gi_352) {
               if (OrderType() == OP_BUY) {
                  Li_16 = NormalizeDouble((Bid - A_price_8) / Point, 0);
                  if (Li_16 < Ai_0) continue;
                  order_stoploss_20 = OrderStopLoss();
                  price_28 = Bid - Ai_4 * Point;
                  if (order_stoploss_20 == 0.0 || (order_stoploss_20 != 0.0 && price_28 > order_stoploss_20)) OrderModify(OrderTicket(), A_price_8, price_28, OrderTakeProfit(), 0, Aqua);
               }
               if (OrderType() == OP_SELL) {
                  Li_16 = NormalizeDouble((A_price_8 - Ask) / Point, 0);
                  if (Li_16 < Ai_0) continue;
                  order_stoploss_20 = OrderStopLoss();
                  price_28 = Ask + Ai_4 * Point;
                  if (order_stoploss_20 == 0.0 || (order_stoploss_20 != 0.0 && price_28 < order_stoploss_20)) OrderModify(OrderTicket(), A_price_8, price_28, OrderTakeProfit(), 0, Red);
               }
            }
            Sleep(1000);
         }
      }
   }
}

// 91C97865111C4DD6B44C584F4B9358BB
double f0_7() {
   if (f0_15() == 0) Gd_524 = AccountEquity();
   if (Gd_524 < Gd_532) Gd_524 = Gd_532;
   else Gd_524 = AccountEquity();
   Gd_532 = AccountEquity();
   return (Gd_524);
}

// 262336F736ADFEEC641C03BB3514631C
double f0_2() {
   double order_open_price_0;
   int ticket_8;
   double Ld_unused_12 = 0;
   int ticket_20 = 0;
   for (int pos_24 = OrdersTotal() - 1; pos_24 >= 0; pos_24--) {
      OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352 && OrderType() == OP_BUY) {
         ticket_8 = OrderTicket();
         if (ticket_8 > ticket_20) {
            order_open_price_0 = OrderOpenPrice();
            Ld_unused_12 = order_open_price_0;
            ticket_20 = ticket_8;
         }
      }
   }
   return (order_open_price_0);
}

// 599A26C25DF2561FBAA884F47E1B315C
double f0_6() {
   double order_open_price_0;
   int ticket_8;
   double Ld_unused_12 = 0;
   int ticket_20 = 0;
   for (int pos_24 = OrdersTotal() - 1; pos_24 >= 0; pos_24--) {
      OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Gi_352) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Gi_352 && OrderType() == OP_SELL) {
         ticket_8 = OrderTicket();
         if (ticket_8 > ticket_20) {
            order_open_price_0 = OrderOpenPrice();
            Ld_unused_12 = order_open_price_0;
            ticket_20 = ticket_8;
         }
      }
   }
   return (order_open_price_0);
}

// 938363B042E987609BD8B876255B9679
void f0_9() {
   Comment("            KLERIK ABSOLUT  " + Symbol() + "  " + Period(), 
      "\n", "            Forex Account Server:", AccountServer(), 
      "\n", "            Lots:  ", Gd_196, 
      "\n", "            Symbol: ", Symbol(), 
      "\n", "            Price:  ", NormalizeDouble(Bid, 4), 
      "\n", "            Date: ", Month(), "-", Day(), "-", Year(), " Server Time: ", Hour(), ":", Minute(), ":", Seconds(), 
   "\n");
}

// B53A5EDA65DD2C5C76918FE4BE35941D
void f0_12() {
   double Ld_0 = f0_8(0);
   string name_8 = Gs_100 + "1";
   if (ObjectFind(name_8) == -1) {
      ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name_8, OBJPROP_CORNER, 1);
      ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(name_8, OBJPROP_YDISTANCE, 15);
   }
   ObjectSetText(name_8, "Earnings today: " + DoubleToStr(Ld_0, 2), 10, "Courier New", Yellow);
   Ld_0 = f0_8(1);
   name_8 = Gs_100 + "2";
   if (ObjectFind(name_8) == -1) {
      ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name_8, OBJPROP_CORNER, 1);
      ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(name_8, OBJPROP_YDISTANCE, 30);
   }
   ObjectSetText(name_8, "Earnings yesterday: " + DoubleToStr(Ld_0, 2), 10, "Courier New", Yellow);
   Ld_0 = f0_8(2);
   name_8 = Gs_100 + "3";
   if (ObjectFind(name_8) == -1) {
      ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name_8, OBJPROP_CORNER, 1);
      ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(name_8, OBJPROP_YDISTANCE, 45);
   }
   ObjectSetText(name_8, "Earnings last week: " + DoubleToStr(Ld_0, 2), 10, "Courier New", Yellow);
   name_8 = Gs_100 + "4";
   if (ObjectFind(name_8) == -1) {
      ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name_8, OBJPROP_CORNER, 1);
      ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(name_8, OBJPROP_YDISTANCE, 75);
   }
   ObjectSetText(name_8, "Balance: " + DoubleToStr(AccountBalance(), 2), 12, "Courier New", Yellow);
   name_8 = Gs_100 + "5";
   if (ObjectFind(name_8) == -1) {
      ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name_8, OBJPROP_CORNER, 1);
      ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
      ObjectSet(name_8, OBJPROP_YDISTANCE, 95);
   }
   ObjectSetText(name_8, "Free margin: " + DoubleToStr(AccountFreeMargin(), 2), 12, "Courier New", Yellow);
}

// 92106D273A87E0D4E98361E7DB777FFA
double f0_8(int Ai_0) {
   double Ld_ret_4 = 0;
   for (int pos_12 = 0; pos_12 < OrdersHistoryTotal(); pos_12++) {
      if (!(OrderSelect(pos_12, SELECT_BY_POS, MODE_HISTORY))) break;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         if (OrderCloseTime() >= iTime(Symbol(), PERIOD_D1, Ai_0) && OrderCloseTime() < iTime(Symbol(), PERIOD_D1, Ai_0) + 86400) Ld_ret_4 = Ld_ret_4 + OrderProfit() + OrderCommission() + OrderSwap();
   }
   return (Ld_ret_4);
}
