/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © www.EA-BOSS.com"
#property link      "eabossteam@yahoo.com"

#import "Boss.dll"
   bool boss1(double a0, int a1, double a2, double a3, int a4, int a5, double a6, int a7);
   bool boss2(double a0, int a1, double a2, double a3, int a4, int a5, double a6, int a7);
   bool boss3(double a0, int a1, int a2);
#import

extern string Use_EA_BOSS_only_on = "EURGPB,EURCHF,GBPCHF";
extern int MM_percent_0_100 = 5;
extern int GMT_hours_plus = 0;
double gd_92 = 100.0;
double gd_100 = 0.1;
int g_magic_108 = 0;
int gi_112 = 0;
int gi_116 = 0;
int gi_120 = 6;
int gi_124 = 5;
int gi_128 = 10;
int gi_unused_132 = 99;
int g_period_136 = 4;
int g_period_140 = 12;
int gi_144 = 47;
int g_period_148 = 15;
int gi_152 = 14;
int gi_156 = 14;
int g_period_160 = 9;
int g_applied_price_164 = PRICE_HIGH;
int g_ma_method_168 = MODE_SMA;
int gi_172 = 7;
int gi_176 = 5;
int gi_180 = 170;
int gi_184 = 70;
int gi_188 = 111;
int gi_192 = 55;
int gi_196 = 77;
int gi_unused_200 = 0;
int gi_204 = 25;
int gi_208 = 24;
int gi_212 = 77;
int gi_unused_216 = 0;
int gi_220 = 59;
int gi_224 = 77;
int gi_228 = 81;
int gi_232 = 3;
int gi_236 = 3;
int gi_240 = 3;
int gi_244 = 139;
int gi_248 = 99;
int gi_252 = 139;
int gi_256 = 2;
int gi_260 = 2;
int gi_264 = 2;
int gi_268 = 169;
int gi_272 = 139;
int gi_276 = 179;
int gi_280 = 0;
int gi_284 = 0;
int gi_288 = 0;
int gi_292 = 199;
int gi_296 = 203;
int gi_300 = 203;
int g_color_304 = Green;
int g_color_308 = Red;
int gi_312 = -1;
int gi_316 = -1;
int gi_320 = -1;
int gi_324 = 239;
int gi_328 = 250;
int gi_332 = 255;
int gi_336;
int gi_340;
int gi_344;
double gd_348 = 0.29;
double gd_356 = 0.21;
double gd_364 = 0.15;
double gd_unused_372 = 0.36;
bool gi_380 = TRUE;
int gi_384 = 20;
int gi_388 = 0;
int gi_392 = 50;
bool gi_unused_396 = TRUE;
bool gi_400 = TRUE;
int gi_404;
double gd_408;
string gs_416;
bool gi_424 = TRUE;
bool gi_428 = TRUE;
int g_datetime_432;
int g_datetime_436;
int gi_440;
int gi_444;
int gi_448;
int gi_452;
int gi_456;
int gi_460;
int gi_464;
int gi_468;
int gi_472;
int gi_476;
int gi_480;
int gi_484;
int gi_488;
int gi_492;
int gi_496;
int gi_500;
int gi_504;
int gi_508;
int gi_512;
int gi_516;
int gi_520;
int gi_524;
int gi_528;
int gi_532;
double gd_536;
double gd_544;
double gd_552;
double gd_560;
double gd_568;
double gd_576;
double gd_584;
double gd_592;
double gd_600;
double gd_608;
double gd_616;

int init() {
   gi_400 = TRUE;
   Comment("Waiting for quotes...");
   if (!IsDllsAllowed()) {
      Alert("Set \"AllowDLL Imports\" ON in menu Tools->Options->ExpertAdvisors!");
      Print("Set \"AllowDLL Imports\" ON in menu Tools->Options->ExpertAdvisors!");
      Comment("Warning: Set Parameter \"AllowDLL Imports\" ON in menu Tools -> Options -> ExpertAdvisors!");
      gi_400 = FALSE;
      return (0);
   }
   if (gi_116 < 0) gi_116 = 0;
   if (gi_112 < 0) gi_112 = 0;
   gs_416 = Symbol();
   if (Digits < 4) {
      gd_408 = 0.01;
      gi_404 = 2;
   } else {
      gd_408 = 0.0001;
      gi_404 = 4;
   }
   if (Digits == 5) {
      gd_408 = 0.0001;
      gi_404 = 5;
   }
   string ls_0 = StringSubstr(gs_416, 0, 6);
   if (ls_0 != "EURGBP" && ls_0 != "EURCHF" && ls_0 != "GBPCHF") {
      Alert("Use EA BOSS on EURCHF,EURGPB,GBPCHF only!");
      Print("Use EA BOSS on EURCHF,EURGPB,GBPCHF only!");
      Comment("Error: Wrong Currency Pair! Use EA BOSS on EURCHF,EURGPB,GBPCHF only!");
      gi_400 = FALSE;
      return (0);
   }
   if (ls_0 == "EURGBP") {
      gi_456 = gi_120;
      gi_460 = gi_188;
      gi_464 = gi_204;
      gd_536 = gd_348;
      gi_468 = gi_220;
      gi_476 = gi_244;
      gi_484 = gi_268;
      gi_492 = gi_292;
      gi_500 = gi_324;
      gi_472 = gi_232;
      gi_480 = gi_256;
      gi_488 = gi_280;
      gi_496 = gi_312;
      gi_504 = gi_336;
   } else {
      if (ls_0 == "EURCHF") {
         gi_456 = gi_124;
         gi_460 = gi_192;
         gi_464 = gi_208;
         gd_536 = gd_356;
         gi_468 = gi_224;
         gi_476 = gi_248;
         gi_484 = gi_272;
         gi_492 = gi_296;
         gi_500 = gi_328;
         gi_472 = gi_236;
         gi_480 = gi_260;
         gi_488 = gi_284;
         gi_496 = gi_316;
         gi_504 = gi_340;
      } else {
         if (ls_0 == "GBPCHF") {
            gi_456 = gi_128;
            gi_460 = gi_196;
            gi_464 = gi_212;
            gd_536 = gd_364;
            gi_468 = gi_228;
            gi_476 = gi_252;
            gi_484 = gi_276;
            gi_492 = gi_300;
            gi_500 = gi_332;
            gi_472 = gi_240;
            gi_480 = gi_264;
            gi_488 = gi_288;
            gi_496 = gi_320;
            gi_504 = gi_344;
         }
      }
   }
   gd_552 = (-1 * gi_460) * gd_408;
   if (gi_112 != 0) gd_552 = (-1 * gi_112) * gd_408;
   gd_544 = (gi_456 - gi_116) * gd_408;
   gi_508 = 60 * gi_468;
   gi_512 = 60 * gi_476;
   gi_516 = 60 * gi_484;
   gi_520 = 60 * gi_492;
   gi_524 = 60 * gi_500;
   gd_560 = (gi_472 - gi_116) * gd_408;
   gd_568 = (gi_480 - gi_116) * gd_408;
   gd_576 = (gi_488 - gi_116) * gd_408;
   gd_584 = (gi_496 - gi_116) * gd_408;
   gd_592 = (gi_504 - gi_116) * gd_408;
   gd_616 = NormalizeDouble(gi_464 * gd_408, gi_404);
   gd_608 = (MarketInfo(gs_416, MODE_SPREAD) + 0.1) * Point;
   gd_600 = NormalizeDouble(gi_460 * gd_408, gi_404);
   gi_440 = 100 - gi_144;
   gi_444 = 100 - gi_152;
   gi_448 = gi_156 / 2 + 50;
   gi_452 = 50 - gi_156 / 2;
   gi_528 = gi_384 + GMT_hours_plus;
   gi_532 = gi_388 + GMT_hours_plus;
   while (true) {
      if (gi_528 >= 24) {
         gi_528 -= 24;
         continue;
      }
      if (gi_528 >= 0) break;
      gi_528 += 24;
   }
   while (true) {
      if (gi_532 >= 24) {
         gi_532 -= 24;
         continue;
      }
      if (gi_532 >= 0) break;
      gi_532 += 24;
   }
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   if (!gi_400) return (0);
   if (gi_380) {
      Comment("" 
         + "\n" 
         + "EA BOSS full version." 
         + "\n" 
         + "For information visit our site www.EA-BOSS.com" 
         + "\n" 
         + "_________________________________________" 
         + "\n" 
         + "\n" 
         + "Leverage:                        1:" + DoubleToStr(AccountLeverage(), 0) 
         + "\n" 
         + "Now spread is                  " + DoubleToStr((Ask - Bid) / gd_408, 1) + " pips" 
         + "\n" 
         + "Broker`s Server Time       " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
         + "\n" 
      + "_________________________________________");
   }
   g_datetime_432 = TimeCurrent();
   if (BOSS_orders()) {
      Close_orders_now();
      BOSS_close_orders();
      ModifyOrderECN();
      ModifyTP();
   }
   if (DayOfWeek() == 5 || DayOfWeek() == 6 || DayOfWeek() == 0) return (0);
   if (DayOfWeek() == 1 && Hour() < gi_528) return (0);
   if (!BOSS_IsTradeTime()) return (0);
   if (Ask - Bid > gd_608) return (0);
   if (BOSS_CheckBOSSvolaFilter()) return (0);
   if (BOSS_CheckTrendFilter()) return (0);
   HideTestIndicators(TRUE);
   double l_irsi_0 = iRSI(NULL, PERIOD_M15, g_period_140, PRICE_CLOSE, 0);
   double ld_8 = Ask + 0.0002;
   double l_ima_16 = iMA(NULL, PERIOD_M15, g_period_136, 0, MODE_SMA, PRICE_MEDIAN, 1);
   double ld_24 = Bid - 0.0002;
   double l_irsi_32 = iRSI(NULL, PERIOD_M1, g_period_148, PRICE_CLOSE, 0);
   if (boss1(ld_8, BOSS_orders(), l_irsi_0, l_irsi_32, gi_152, gi_144, l_ima_16, 1)) {
      if (gi_424) {
         OrderNOW(OP_BUY, gi_456, gi_460);
         gi_424 = FALSE;
         gi_428 = TRUE;
      }
   }
   if (boss2(ld_24, BOSS_orders(), l_irsi_0, l_irsi_32, gi_444, gi_440, l_ima_16, 1)) {
      if (gi_428) {
         OrderNOW(OP_SELL, gi_456, gi_460);
         gi_428 = FALSE;
         gi_424 = TRUE;
      }
   }
   if (boss3(l_irsi_0, gi_448, gi_452)) {
      gi_428 = TRUE;
      gi_424 = TRUE;
   }
   return (0);
}

void ModifyTP() {
   int li_0;
   double ld_4;
   double l_price_12;
   double ld_20;
   int li_unused_28;
   double l_price_32;
   double ld_40;
   double ld_unused_48;
   double l_price_56;
   bool l_bool_64;
   string ls_unused_68;
   int li_unused_76 = MarketInfo(gs_416, MODE_SPREAD);
   int li_80 = OrdersTotal() - 1;
   double ld_84 = NormalizeDouble((MarketInfo(gs_416, MODE_STOPLEVEL) + 1.0) * Point, Digits);
   for (int l_pos_92 = li_80; l_pos_92 >= 0; l_pos_92--) {
      if (OrderSelect(l_pos_92, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_108) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == gs_416) {
                  li_0 = g_datetime_432 - OrderOpenTime();
                  if (li_0 > 0) {
                     ld_4 = NormalizeDouble(OrderClosePrice(), gi_404);
                     l_price_12 = NormalizeDouble(OrderOpenPrice(), gi_404);
                     l_price_32 = NormalizeDouble(OrderStopLoss(), gi_404);
                     ld_40 = NormalizeDouble(OrderTakeProfit(), gi_404);
                     ld_unused_48 = 0;
                     ld_20 = 0;
                     li_unused_28 = 0;
                     RefreshRates();
                     if (li_0 > 60 && li_0 < gi_508) {
                        if (OrderType() == OP_BUY) {
                           l_price_56 = NormalizeDouble(l_price_12 + gd_544, gi_404);
                           ld_20 = l_price_56 - Ask;
                        } else {
                           l_price_56 = NormalizeDouble(l_price_12 - gd_544, gi_404);
                           ld_20 = Bid - l_price_56;
                        }
                        if (ld_20 > ld_84 && l_price_56 != ld_40) {
                           l_bool_64 = OrderModify(OrderTicket(), l_price_12, l_price_32, l_price_56, 0, CLR_NONE);
                           if (!l_bool_64) Print("Order modify error = ", GetLastError(), ", new_TP= ", l_price_56, ", ordtp= ", ld_40);
                        }
                     } else {
                        if (li_0 > gi_508 && li_0 < gi_512) {
                           if (OrderType() == OP_BUY) {
                              l_price_56 = NormalizeDouble(l_price_12 + gd_560, gi_404);
                              ld_20 = l_price_56 - Ask;
                           } else {
                              l_price_56 = NormalizeDouble(l_price_12 - gd_560, gi_404);
                              ld_20 = Bid - l_price_56;
                           }
                           if (ld_20 > ld_84 && l_price_56 != ld_40) {
                              l_bool_64 = OrderModify(OrderTicket(), l_price_12, l_price_32, l_price_56, 0, CLR_NONE);
                              if (!l_bool_64) Print("Order modify error = ", GetLastError());
                           }
                        } else {
                           if (li_0 > gi_512 && li_0 < gi_516) {
                              if (OrderType() == OP_BUY) {
                                 l_price_56 = NormalizeDouble(l_price_12 + gd_568, gi_404);
                                 ld_20 = l_price_56 - Ask;
                              } else {
                                 l_price_56 = NormalizeDouble(l_price_12 - gd_568, gi_404);
                                 ld_20 = Bid - l_price_56;
                              }
                              if (ld_20 > ld_84 && l_price_56 != ld_40) {
                                 l_bool_64 = OrderModify(OrderTicket(), l_price_12, l_price_32, l_price_56, 0, CLR_NONE);
                                 if (!l_bool_64) Print("Order modify error = ", GetLastError());
                              }
                           } else {
                              if (li_0 > gi_516 && li_0 < gi_520) {
                                 if (OrderType() == OP_BUY) {
                                    l_price_56 = NormalizeDouble(l_price_12 + gd_576, gi_404);
                                    ld_20 = l_price_56 - Ask;
                                 } else {
                                    l_price_56 = NormalizeDouble(l_price_12 - gd_576, gi_404);
                                    ld_20 = Bid - l_price_56;
                                 }
                                 if (ld_20 > ld_84 && l_price_56 != ld_40) {
                                    l_bool_64 = OrderModify(OrderTicket(), l_price_12, l_price_32, l_price_56, 0, CLR_NONE);
                                    if (!l_bool_64) Print("Order modify error = ", GetLastError());
                                 }
                              } else {
                                 if (li_0 > gi_520 && li_0 < gi_524) {
                                    if (OrderType() == OP_BUY) {
                                       l_price_56 = NormalizeDouble(l_price_12 + gd_584, gi_404);
                                       ld_20 = l_price_56 - Ask;
                                    } else {
                                       l_price_56 = NormalizeDouble(l_price_12 - gd_584, gi_404);
                                       ld_20 = Bid - l_price_56;
                                    }
                                    if (ld_20 > ld_84 && l_price_56 != ld_40) {
                                       l_bool_64 = OrderModify(OrderTicket(), l_price_12, l_price_32, l_price_56, 0, CLR_NONE);
                                       if (!l_bool_64) Print("Order modify error = ", GetLastError());
                                    }
                                 } else {
                                    if (li_0 > gi_524) {
                                       if (OrderType() == OP_BUY) {
                                          l_price_56 = NormalizeDouble(l_price_12 + gd_592, gi_404);
                                          ld_20 = l_price_56 - Ask;
                                       } else {
                                          l_price_56 = NormalizeDouble(l_price_12 - gd_592, gi_404);
                                          ld_20 = Bid - l_price_56;
                                       }
                                       if (ld_20 > ld_84 && l_price_56 != ld_40) {
                                          l_bool_64 = OrderModify(OrderTicket(), l_price_12, l_price_32, l_price_56, 0, CLR_NONE);
                                          if (!l_bool_64) Print("Order modify error = ", GetLastError());
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

bool BOSS_CheckTrendFilter() {
   double ld_0;
   double ld_8;
   double ld_16;
   if (gi_172 <= 0) return (FALSE);
   for (int li_24 = 0; li_24 <= gi_176; li_24++) {
      ld_0 = NormalizeDouble(iMA(NULL, PERIOD_M15, g_period_160, 0, g_ma_method_168, g_applied_price_164, li_24), gi_404);
      ld_8 = NormalizeDouble(iMA(NULL, PERIOD_M15, g_period_160, 0, g_ma_method_168, g_applied_price_164, li_24 + gi_172), gi_404);
      if (ld_8 != 0.0) ld_16 = 100.0 * MathAbs(ld_0 - ld_8) / ld_8;
      if (ld_16 > gd_536) break;
   }
   if (li_24 > gi_176) return (FALSE);
   return (TRUE);
}

bool BOSS_CheckBOSSvolaFilter() {
   int l_datetime_0;
   bool li_4 = FALSE;
   if (NormalizeDouble(iHigh(NULL, PERIOD_M15, 1) - iLow(NULL, PERIOD_M15, 1), gi_404) > gd_616) li_4 = TRUE;
   if (NormalizeDouble(iHigh(NULL, PERIOD_M15, 2) - iLow(NULL, PERIOD_M15, 2), gi_404) > gd_616) li_4 = TRUE;
   if (li_4) {
      l_datetime_0 = iTime(NULL, PERIOD_M15, 0);
      if (g_datetime_436 != l_datetime_0) {
         Print("Trade is forbidden by the EA BOSS Volatility Filter.");
         g_datetime_436 = l_datetime_0;
      }
      return (TRUE);
   }
   return (FALSE);
}

bool BOSS_IsTradeTime() {
   int l_hour_0 = TimeHour(g_datetime_432);
   if (gi_528 < gi_532 && l_hour_0 < gi_528 || l_hour_0 >= gi_532) return (FALSE);
   if (gi_528 > gi_532 && (l_hour_0 < gi_528 && l_hour_0 >= gi_532)) return (FALSE);
   if (gi_532 == 0) gi_532 = 24;
   if (Hour() == gi_532 - 1 && Minute() >= gi_392) return (FALSE);
   return (TRUE);
}

bool BOSS_orders() {
   int l_ord_total_0 = OrdersTotal();
   for (int l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_108) {
            if (OrderSymbol() == gs_416)
               if (OrderType() <= OP_SELL) return (TRUE);
         }
      }
   }
   return (FALSE);
}

int OrderNOW(int a_cmd_0, int ai_unused_4, int ai_unused_8) {
   double l_price_12;
   color l_color_20;
   int l_ticket_24;
   double ld_28 = LotsOptimized();
   if (AccountFreeMarginCheck(gs_416, a_cmd_0, ld_28) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) {
      Print("You don\'t have free margin.");
      Comment("You don\'t have free margin.");
      return (-1);
   }
   if (Ask - Bid > gd_92 / 10000.0) return (0);
   RefreshRates();
   if (a_cmd_0 == OP_BUY) {
      l_price_12 = Ask;
      l_color_20 = g_color_304;
   } else {
      l_price_12 = Bid;
      l_color_20 = g_color_308;
   }
   l_ticket_24 = OrderSend(gs_416, a_cmd_0, ld_28, l_price_12, MarketInfo(gs_416, MODE_SPREAD), 0, 0, 0, g_magic_108, 0, l_color_20);
   return (l_ticket_24);
}

void BOSS_close_orders() {
   int li_0;
   double l_price_4;
   double ld_12;
   int li_20;
   double ld_24;
   bool l_ord_close_32;
   string ls_36;
   int l_spread_44 = MarketInfo(gs_416, MODE_SPREAD);
   int li_48 = OrdersTotal() - 1;
   for (int l_pos_52 = li_48; l_pos_52 >= 0; l_pos_52--) {
      if (OrderSelect(l_pos_52, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_108) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == gs_416) {
                  li_0 = g_datetime_432 - OrderOpenTime();
                  if (li_0 > gi_508) {
                     l_price_4 = NormalizeDouble(OrderClosePrice(), gi_404);
                     ld_12 = NormalizeDouble(OrderOpenPrice(), gi_404);
                     li_20 = 0;
                     if (OrderType() == OP_BUY) ld_24 = l_price_4 - ld_12;
                     else ld_24 = ld_12 - l_price_4;
                     if (li_0 < gi_512 && ld_24 >= gd_560) li_20 = 1;
                     else {
                        if (li_0 > gi_512 && li_0 < gi_516 && ld_24 >= gd_568) li_20 = 2;
                        else {
                           if (li_0 > gi_516 && li_0 < gi_520 && ld_24 >= gd_576) li_20 = 3;
                           else {
                              if (li_0 > gi_520 && li_0 < gi_524 && ld_24 >= gd_584) li_20 = 4;
                              else
                                 if (li_0 > gi_524 && ld_24 >= gd_592) li_20 = 5;
                           }
                        }
                     }
                     if (li_20 != 0) {
                        RefreshRates();
                        l_ord_close_32 = OrderClose(OrderTicket(), OrderLots(), l_price_4, l_spread_44 * 2, g_color_304);
                        if (!l_ord_close_32) {
                           if (OrderType() == OP_BUY) ls_36 = "OP_BUY";
                           else ls_36 = "OP_SELL";
                           Print("OrderClose(", ls_36, ") error = ", GetLastError());
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

void Close_orders_now() {
   double l_price_0;
   double ld_8;
   double ld_16;
   bool l_ord_close_24;
   if (gi_456 <= 0 && gi_460 <= 0) return;
   int l_spread_28 = MarketInfo(gs_416, MODE_SPREAD);
   int li_32 = OrdersTotal() - 1;
   for (int l_pos_36 = li_32; l_pos_36 >= 0; l_pos_36--) {
      if (OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_108) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == gs_416) {
                  l_price_0 = NormalizeDouble(OrderClosePrice(), gi_404);
                  ld_8 = NormalizeDouble(OrderOpenPrice(), gi_404);
                  if (OrderType() == OP_BUY) {
                     ld_16 = l_price_0 - ld_8;
                     if ((gd_544 > 0.0 && ld_16 >= gd_544) || (gd_552 < 0.0 && ld_16 <= gd_552)) {
                        l_ord_close_24 = OrderClose(OrderTicket(), OrderLots(), l_price_0, l_spread_28 * 2, g_color_304);
                        if (!l_ord_close_24) Print("OrderClose(OP_BUY) error = ", GetLastError());
                     }
                  } else {
                     ld_16 = ld_8 - l_price_0;
                     if ((gd_544 > 0.0 && ld_16 >= gd_544) || (gd_552 < 0.0 && ld_16 <= gd_552)) {
                        l_ord_close_24 = OrderClose(OrderTicket(), OrderLots(), l_price_0, l_spread_28 * 2, g_color_308);
                        if (!l_ord_close_24) Print("OrderClose(OP_SELL) error = ", GetLastError());
                     }
                  }
               }
            }
         }
      }
   }
}

double LotsOptimized() {
   double l_marginrequired_0 = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double ld_ret_8 = gd_100;
   if (l_marginrequired_0 != 0.0) ld_ret_8 = MathFloor(MM_percent_0_100 * AccountEquity() / 100.0 / gd_100 / l_marginrequired_0) * gd_100;
   if (ld_ret_8 >= MarketInfo(Symbol(), MODE_MAXLOT)) ld_ret_8 = MarketInfo(Symbol(), MODE_MAXLOT);
   if (ld_ret_8 < gd_100) ld_ret_8 = gd_100;
   return (ld_ret_8);
}

void ModifyOrderECN() {
   double ld_0;
   double l_price_8;
   double ld_16;
   double ld_24;
   bool li_32;
   bool li_36;
   bool li_40;
   double l_price_44;
   double l_price_52;
   bool l_bool_60;
   double ld_64 = NormalizeDouble(MarketInfo(gs_416, MODE_STOPLEVEL) * Point, Digits);
   int li_72 = OrdersTotal() - 1;
   for (int l_pos_76 = li_72; l_pos_76 >= 0; l_pos_76--) {
      if (OrderSelect(l_pos_76, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_108) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == gs_416) {
                  ld_0 = NormalizeDouble(OrderClosePrice(), gi_404);
                  l_price_8 = NormalizeDouble(OrderOpenPrice(), gi_404);
                  ld_16 = NormalizeDouble(OrderStopLoss(), gi_404);
                  ld_24 = NormalizeDouble(OrderTakeProfit(), gi_404);
                  li_32 = TRUE;
                  li_36 = FALSE;
                  li_40 = FALSE;
                  if (ld_16 == 0.0) {
                     li_36 = gi_180;
                     if (li_36 != FALSE) {
                        if (OrderType() == OP_BUY) {
                           l_price_44 = NormalizeDouble(l_price_8 - li_36 * gd_408, gi_404);
                           if (ld_0 - l_price_44 <= ld_64) li_32 = FALSE;
                        } else {
                           l_price_44 = NormalizeDouble(l_price_8 + li_36 * gd_408, gi_404);
                           if (l_price_44 - ld_0 <= ld_64) li_32 = FALSE;
                        }
                     }
                  } else l_price_44 = ld_16;
                  if (ld_24 == 0.0) {
                     li_40 = gi_184;
                     if (li_40 != FALSE) {
                        if (OrderType() == OP_BUY) {
                           l_price_52 = NormalizeDouble(l_price_8 + li_40 * gd_408, gi_404);
                           if (l_price_52 - ld_0 <= ld_64) li_32 = FALSE;
                        } else {
                           l_price_52 = NormalizeDouble(l_price_8 - li_40 * gd_408, gi_404);
                           if (ld_0 - l_price_52 <= ld_64) li_32 = FALSE;
                        }
                     }
                  } else l_price_52 = ld_24;
                  if (li_36 != FALSE && li_40 != FALSE && li_32) l_bool_60 = OrderModify(OrderTicket(), l_price_8, l_price_44, l_price_52, 0, CLR_NONE);
               }
            }
         }
      }
   }
}
