Navigation´╝ÜHome > Content >

Forex_Expertv2.mq4

Time: 2011-10-06 | Download file:Forex_Expertv2.mq4

//+------------------------------------------------------------------+
//|                                               Forex_Expertv2.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


string gs_unused_76 = "";
string gs_unused_84 = "";
int g_magic_92 = 69348;
extern string Expert1 = "=== Time Management ===";
extern bool Use_Time_Mgmt = FALSE;
extern int TradeStartHour = 0;
extern int TradeStartMinutes = 0;
extern int TradeEndHour = 23;
extern int TradeEndMinutes = 0;
extern string Expert2 = "=== Trading Management ===";
extern bool MM = FALSE;
extern double RiskPercent = 10.0;
extern double LotSize = 0.01;
extern double Max_Lot_Size = 100.0;
extern int MaxOrder = 1;
extern double StopTime = 0.0;
extern double TakeProfit = 25.0;
extern double StopLoss = 350.0;
extern double Slippage = 3.0;
extern double TrailingStop = 0.0;
extern bool TrailingProfit = FALSE;
extern int TrailingPips = 1;
extern bool Profit_Protection = FALSE;
extern bool ProtectAll = FALSE;
extern double Percent_Over_Balance = 10.0;
extern bool Balance_Protection = FALSE;
int g_period_232 = 10;
double gd_236 = 10.0;
double gd_unused_244 = 5.0;
double gd_unused_252 = 10.0;
double gd_unused_260 = 22.0;
double gd_unused_268 = 20.0;
double gd_unused_276 = 26.0;
double gd_unused_284 = 13.0;
double gd_unused_292 = 15.0;
double gd_unused_300 = 10.0;
double gd_308;
double g_minlot_316;
double g_lotstep_324;
double gd_332;
int gi_340;
double g_price_344;
double gd_352;
double g_point_360;
int g_slippage_368;
bool gi_372 = TRUE;
bool gi_376 = FALSE;
int gi_380 = 23;
int gi_384 = 30;
int gi_388 = 100;
int gi_392 = 0;
int gi_396 = 0;

int init() {
   if (Point == 0.00001) g_point_360 = 0.0001;
   else {
      if (Point == 0.001) g_point_360 = 0.01;
      else g_point_360 = Point;
   }
   g_slippage_368 = MarketInfo(Symbol(), MODE_SPREAD);
   return (0);
}

int deinit() {
   return (0);
}

int Crossed(double ad_0, double ad_8) {
   if (ad_0 > ad_8) gi_396 = 1;
   if (ad_0 < ad_8) gi_396 = 2;
   if (gi_396 != gi_392) {
      gi_392 = gi_396;
      return (gi_392);
   }
   return (0);
}

double Predict() {
   double l_ima_0;
   double l_ima_8;
   double l_ima_16;
   double l_istddev_24;
   double ld_ret_32;
   double ld_40 = 0;
   double ld_48 = 0;
   double ld_56 = 0;
   double ld_64 = 0;
   double ld_unused_72 = 0;
   double ld_unused_80 = 0;
   double ld_88 = 0;
   double ld_96 = 0;
   double ld_104 = 0;
   double ld_112 = 0;
   double ld_120 = 0;
   double ld_unused_128 = 0;
   double ld_136 = 0;
   double ld_144 = 0;
   double ld_152 = 0;
   double ld_160 = 0;
   double l_ima_168 = iMA(NULL, 0, g_period_232, 0, MODE_SMA, PRICE_CLOSE, 0);
   for (int li_176 = 1; li_176 <= g_period_232; li_176++) {
      l_ima_0 = iMA(NULL, 0, g_period_232, 0, MODE_SMA, PRICE_CLOSE, li_176);
      l_ima_8 = iMA(NULL, 0, g_period_232, 0, MODE_SMA, PRICE_HIGH, li_176);
      l_ima_16 = iMA(NULL, 0, g_period_232, 0, MODE_SMA, PRICE_LOW, li_176);
      l_istddev_24 = iStdDev(NULL, 0, g_period_232, 0, MODE_SMA, PRICE_CLOSE, li_176);
      ld_40 += (High[li_176] + Low[li_176]) / 2.0;
      ld_48 += Close[li_176];
      ld_56 += ld_40 - ld_48;
      ld_64 += l_ima_0;
      ld_112 += l_istddev_24;
      ld_136 += Close[li_176] - Open[li_176] - (Close[li_176 - 1] - (Open[li_176 - 1]));
      ld_160 = ld_160 + (l_ima_8 - l_ima_0) + (l_ima_16 - l_ima_0);
   }
   ld_88 = ld_40 / g_period_232;
   ld_96 = ld_48 / g_period_232;
   ld_104 = ld_64 / g_period_232;
   ld_120 = ld_112 / g_period_232;
   ld_152 = ld_56 / g_period_232;
   ld_144 = ld_136 / g_period_232;
   if (ld_152 > 0.0 && l_ima_168 > ld_104 && ld_144 > 0.0 && Open[0] < l_ima_168 + ld_120 && Open[0] > l_ima_168) {
      ld_ret_32 = 1;
      gd_352 = 10000.0 * (2.0 * ld_120) + gd_236;
   }
   if (ld_152 < 0.0 && l_ima_168 < ld_104 && ld_144 < 0.0 && Open[0] > l_ima_168 - ld_120 && Open[0] < l_ima_168) {
      ld_ret_32 = 2;
      gd_352 = 10000.0 * (2.0 * ld_120) + gd_236;
   }
   if (ld_152 > 0.0 && l_ima_168 > ld_104 && ld_144 > 0.0 && Open[0] < l_ima_168 - ld_120) {
      ld_ret_32 = 3;
      gd_352 = 10000.0 * (2.0 * ld_120) + 10.0;
   }
   if (ld_152 < 0.0 && l_ima_168 < ld_104 && ld_144 < 0.0 && Open[0] > l_ima_168 + ld_120) {
      ld_ret_32 = 4;
      gd_352 = 10000.0 * (2.0 * ld_120) + 10.0;
   }
   return (ld_ret_32);
}

double Predict2() {
   double ld_ret_0;
   double ld_8 = 0;
   double ld_16 = 0;
   double ld_24 = 0;
   double ld_32 = 0;
   double ld_40 = 0;
   double ld_48 = 0;
   double ld_56 = 0;
   double ld_64 = 0;
   double ld_72 = 0;
   double l_istddev_80 = 0;
   double ld_88 = 0;
   double ld_96 = 0;
   double ld_104 = 0;
   l_istddev_80 = iStdDev(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, 0);
   double l_istddev_112 = iStdDev(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0);
   double l_ima_120 = iMA(NULL, PERIOD_M30, 9, 0, MODE_SMA, PRICE_CLOSE, 0);
   double l_ima_128 = iMA(NULL, PERIOD_M30, 9, 0, MODE_SMA, PRICE_CLOSE, 1);
   double l_ima_136 = iMA(NULL, PERIOD_M30, 9, 0, MODE_SMA, PRICE_CLOSE, 2);
   for (int li_144 = 1; li_144 <= 20; li_144++) {
      ld_8 += Close[li_144];
      ld_16 += High[li_144] - Low[li_144];
      ld_24 += Close[li_144] - Open[li_144];
      if (li_144 <= 10) {
         ld_88 += Close[li_144];
         ld_96 += High[li_144] - Low[li_144];
         ld_104 += Close[li_144] - Open[li_144];
      }
   }
   ld_32 = ld_8 / 20.0;
   ld_40 = ld_16 / 20.0;
   ld_48 = ld_24 / 20.0;
   double ld_148 = ld_88 / 10.0;
   double ld_156 = ld_96 / 10.0;
   double ld_164 = ld_104 / 10.0;
   ld_72 = (Open[0] - ld_148) / l_istddev_80;
   double ld_172 = (Open[0] - ld_32) / l_istddev_112;
   ld_56 = ld_148 + 0.308 * ld_156;
   double ld_180 = ld_32 + 0.18 * ld_40;
   ld_64 = ld_148 - 0.308 * ld_156;
   double ld_188 = ld_32 - 0.18 * ld_40;
   if ((l_ima_120 - l_ima_136 > l_ima_128 - l_ima_136 + 0.0002 && ld_164 > 0.0 && ld_104 > 0.0 && Open[0] > ld_64 && Open[0] <= ld_148 + ld_72 * ld_164 && ld_72 < 0.0 &&
      High[1] - Low[1] < 1.777 * ld_156) || (l_ima_120 - l_ima_136 > l_ima_128 - l_ima_136 + 0.0002 && ld_48 > 0.0 && ld_24 > 0.0 && Open[0] > ld_188 && Open[0] <= ld_32 + ld_72 * ld_48 && ld_172 < 0.0 && High[1] - Low[1] < 1.586 * ld_156)) {
      ld_ret_0 = 1;
      gd_352 = 10000.0 * l_istddev_112 + 10.0;
   }
   if ((l_ima_120 - l_ima_136 < l_ima_128 - l_ima_136 - 0.0002 && ld_164 < 0.0 && ld_104 < 0.0 && Open[0] < ld_56 && Open[0] >= ld_148 + ld_72 * ld_164 && ld_72 > 0.0 &&
      High[1] - Low[1] < 1.777 * ld_156) || (l_ima_120 - l_ima_136 < l_ima_128 - l_ima_136 - 0.0002 && ld_48 < 0.0 && ld_24 < 0.0 && Open[0] < ld_180 && Open[0] >= ld_32 + ld_72 * ld_48 && ld_172 > 0.0 && High[1] - Low[1] < 1.586 * ld_156)) {
      ld_ret_0 = 2;
      gd_352 = 10000.0 * l_istddev_112 + 10.0;
   }
   if (l_ima_120 - l_ima_136 > l_ima_128 - l_ima_136 + 0.0002 && ld_48 > 0.0 && ld_24 > 0.0 && Open[0] > ld_188 && Open[0] <= ld_32 + ld_72 * ld_48 && ld_172 < 0.0 &&
      High[1] - Low[1] > 1.586 * ld_156) {
      ld_ret_0 = 3;
      g_price_344 = 10000.0 * l_istddev_112 + 10.0;
   }
   if (l_ima_120 - l_ima_136 < l_ima_128 - l_ima_136 - 0.0002 && ld_48 < 0.0 && ld_24 < 0.0 && Open[0] < ld_180 && Open[0] >= ld_32 + ld_72 * ld_48 && ld_172 > 0.0 &&
      High[1] - Low[1] > 1.586 * ld_156) {
      ld_ret_0 = 4;
      g_price_344 = 10000.0 * l_istddev_112 + 10.0;
   }
   return (ld_ret_0);
}

int start() {
   int l_ticket_0;
   double l_price_4;
   bool li_12;
   bool li_16;
   bool li_20;
   bool li_24;
   bool li_28;
   bool li_32;
   bool li_36;
   bool li_40;
   bool li_44;
   bool li_48;
   bool li_52;
   bool li_56;
   int li_unused_60;
   double l_price_64;
   int l_hour_72 = TimeHour(TimeCurrent());
   int l_count_76 = 0;
   int l_count_80 = 0;
   double l_high_84 = High[iHighest(NULL, 0, MODE_HIGH, gi_388, 0)];
   double l_low_92 = Low[iLowest(NULL, 0, MODE_LOW, gi_388, 0)];
   double l_imacd_100 = iMACD(NULL, 0, 50, 50, 9, PRICE_CLOSE, MODE_MAIN, 0);
   double l_imacd_108 = iMACD(NULL, 0, 50, 50, 9, PRICE_CLOSE, MODE_MAIN, 1);
   double l_imacd_116 = iMACD(NULL, 0, 50, 50, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
   double l_imacd_124 = iMACD(NULL, 0, 50, 50, 9, PRICE_CLOSE, MODE_SIGNAL, 1);
   double l_ima_132 = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_HIGH, 0);
   double l_ima_140 = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_HIGH, 1);
   double l_ima_148 = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_LOW, 0);
   double l_ima_156 = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_LOW, 1);
   double l_ima_164 = iMA(NULL, 0, 18, 0, MODE_SMA, PRICE_CLOSE, 0);
   double l_ima_172 = iMA(NULL, 0, 18, 0, MODE_SMA, PRICE_CLOSE, 5);
   double l_ima_180 = iMA(NULL, 0, 18, 0, MODE_SMA, PRICE_CLOSE, 1);
   double l_ima_188 = iMA(NULL, 0, 36, 0, MODE_SMA, PRICE_CLOSE, 0);
   double l_ima_196 = iMA(NULL, 0, 36, 0, MODE_SMA, PRICE_CLOSE, 1);
   double l_ima_204 = iMA(NULL, 0, 36, 0, MODE_SMA, PRICE_CLOSE, 2);
   double l_ima_212 = iMA(NULL, 0, 36, 0, MODE_EMA, PRICE_CLOSE, 1);
   double l_ima_220 = iMA(NULL, 0, 36, 0, MODE_SMA, PRICE_CLOSE, 5);
   double l_ima_228 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, 0);
   double l_ima_236 = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, 1);
   int li_244 = Crossed(l_ima_236, l_ima_180);
   double l_ima_248 = iMA(NULL, 0, gi_388, 0, MODE_SMA, PRICE_CLOSE, 0);
   double l_istddev_256 = iStdDev(NULL, 0, gi_388, 0, MODE_SMA, PRICE_CLOSE, 0);
   double l_istddev_264 = iStdDev(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0);
   double l_istddev_272 = iStdDev(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, 1);
   double l_iwpr_280 = iWPR(NULL, 0, 26, 0);
   double l_iwpr_288 = iWPR(NULL, 0, 26, 1);
   double l_iwpr_296 = iWPR(NULL, 0, 26, 2);
   double l_iwpr_304 = iWPR(NULL, 0, 114, 0);
   double l_iwpr_312 = iWPR(NULL, 0, 114, 1);
   double l_idemarker_320 = iDeMarker(NULL, 0, 13, 0);
   double l_idemarker_328 = iDeMarker(NULL, 0, 13, 1);
   double l_idemarker_336 = iDeMarker(NULL, 0, 13, 2);
   double l_istochastic_344 = iStochastic(NULL, 0, 15, 6, 7, MODE_EMA, 0, MODE_MAIN, 0);
   double l_istochastic_352 = iStochastic(NULL, 0, 15, 6, 7, MODE_EMA, 0, MODE_MAIN, 1);
   double l_istochastic_360 = iStochastic(NULL, 0, 15, 6, 7, MODE_EMA, 0, MODE_SIGNAL, 0);
   double l_istochastic_368 = iStochastic(NULL, 0, 15, 6, 7, MODE_EMA, 0, MODE_SIGNAL, 1);
   if (l_istochastic_352 < l_istochastic_368 - 5.0 && l_istochastic_344 >= l_istochastic_360) li_20 = TRUE;
   if (l_istochastic_352 > l_istochastic_368 + 5.0 && l_istochastic_344 <= l_istochastic_360) li_24 = TRUE;
   if (l_istochastic_352 > l_istochastic_368 && l_istochastic_344 > l_istochastic_360) li_28 = TRUE;
   if (l_istochastic_352 < l_istochastic_368 && l_istochastic_344 < l_istochastic_360) li_32 = TRUE;
   double l_istochastic_376 = iStochastic(NULL, 0, 10, 5, 5, MODE_SMA, 0, MODE_MAIN, 0);
   double l_istochastic_384 = iStochastic(NULL, 0, 10, 5, 5, MODE_SMA, 0, MODE_MAIN, 1);
   double l_istochastic_392 = iStochastic(NULL, 0, 10, 5, 5, MODE_SMA, 0, MODE_SIGNAL, 0);
   double l_istochastic_400 = iStochastic(NULL, 0, 10, 5, 5, MODE_SMA, 0, MODE_SIGNAL, 1);
   if (l_istochastic_384 < l_istochastic_400 - 5.0 && l_istochastic_376 >= l_istochastic_392) li_36 = TRUE;
   if (l_istochastic_384 > l_istochastic_400 + 5.0 && l_istochastic_376 <= l_istochastic_392) li_40 = TRUE;
   if (l_istochastic_384 < l_istochastic_400 && l_istochastic_376 >= l_istochastic_392) li_44 = TRUE;
   if (l_istochastic_384 > l_istochastic_400 && l_istochastic_376 <= l_istochastic_392) li_48 = TRUE;
   if (l_istochastic_384 > l_istochastic_400 && l_istochastic_376 > l_istochastic_392) li_52 = TRUE;
   if (l_istochastic_384 < l_istochastic_400 && l_istochastic_376 < l_istochastic_392) li_56 = TRUE;
   double l_irsi_408 = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
   double l_irsi_416 = iRSI(NULL, 0, 14, PRICE_CLOSE, 1);
   double l_irsi_424 = iRSI(NULL, 0, 14, PRICE_CLOSE, 2);
   double ld_unused_432 = 0;
   if (l_irsi_408 < 30.0) ld_unused_432 = 1;
   if (l_irsi_408 > 70.0) ld_unused_432 = 2;
   double l_ibands_440 = iBands(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 1);
   double l_ibands_448 = iBands(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 2);
   double l_ibands_456 = iBands(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 1);
   double l_ibands_464 = iBands(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 2);
   double l_iadx_472 = iADX(NULL, 0, 14, PRICE_HIGH, MODE_MAIN, 0);
   double l_iadx_480 = iADX(NULL, 0, 14, PRICE_HIGH, MODE_PLUSDI, 0);
   double l_iadx_488 = iADX(NULL, 0, 14, PRICE_HIGH, MODE_PLUSDI, 1);
   double l_iadx_496 = iADX(NULL, 0, 14, PRICE_HIGH, MODE_MINUSDI, 0);
   double l_iadx_504 = iADX(NULL, 0, 14, PRICE_HIGH, MODE_MINUSDI, 1);
   if (l_iadx_480 > l_iadx_496) li_16 = TRUE;
   if (l_iadx_496 > l_iadx_480) li_12 = TRUE;
   if (l_iadx_472 < 30.0) {
      li_12 = FALSE;
      li_16 = FALSE;
   }
   gd_308 = MarketInfo(Symbol(), MODE_MAXLOT);
   g_minlot_316 = MarketInfo(Symbol(), MODE_MINLOT);
   g_lotstep_324 = MarketInfo(Symbol(), MODE_LOTSTEP);
   gd_332 = MarketInfo(Symbol(), MODE_MARGINREQUIRED) * g_lotstep_324;
   gi_340 = 3600 * gi_380 + 60 * gi_384;
   int l_stoplevel_512 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   if (Slippage > g_slippage_368) g_slippage_368 = Slippage;
   if (DayOfWeek() == 5 && gi_372 == FALSE && Use_Time_Mgmt) return (0);
   closeExpiredOrders();
   if (!isTradeTime()) return (0);
   if (Bars < 100) {
      Print("bars less than 100");
      return (0);
   }
   if (!IsConnected()) {
      Print("No Connection!!!");
      Sleep(5000);
      return (0);
   }
   double l_price_516 = StopLoss;
   if (l_price_516 <= 0.0) l_price_516 = 0;
   int li_524 = 0;
   int li_528 = 0;
   int l_ord_total_532 = OrdersTotal();
   if (l_ord_total_532 > 0) {
      for (int l_pos_536 = 0; l_pos_536 < l_ord_total_532; l_pos_536++) {
         OrderSelect(l_pos_536, SELECT_BY_POS);
         if (OrderMagicNumber() == g_magic_92) {
            if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) l_count_76++;
            else l_count_80++;
         }
      }
   }
   if (l_count_76 > 0)
      if (TimeCurrent() - OrderOpenTime() <= 60.0 * StopTime) return (0);
   if (l_count_76 < MaxOrder) {
      if (AccountFreeMargin() < 100.0 * LotsOptimized()) {
         Print("We have not enough money. Free Margin = ", AccountFreeMargin());
         return (0);
      }
      if (!IsTradeAllowed()) {
         Print("Trade context is busy! The expert cannot open position! Wait a moment...");
         Sleep(1000);
         return (0);
      }
      if (Predict() == 1.0 || Predict2() == 1.0 && Ask < (l_high_84 + l_low_92) / 2.0 - l_istddev_256 && li_28 && l_istochastic_344 < 45.0) li_524 = 3;
      if ((Predict() == 3.0 && ((l_iwpr_280 > l_iwpr_288 + 9.0 && li_52) || (l_iwpr_280 > l_iwpr_288 + 9.0 && li_28) && l_idemarker_320 > l_idemarker_328 + 0.05 && l_ima_196 < l_ima_180) ||
         (l_istochastic_344 < 40.0 && Open[1] < l_ima_156 && l_ima_164 > l_ima_220) || (l_istochastic_384 < 40.0 && l_ima_164 > l_ima_180 && l_ima_212 > l_ima_196) || (Open[2] > l_ima_196 &&
         Open[1] < Close[1] && Open[0] > Close[1] && li_28 && l_iwpr_280 > l_iwpr_288 + 7.0 && l_idemarker_320 > l_idemarker_328 + 0.05)) || (Predict() == 1.0 && ((l_iwpr_280 > l_iwpr_288 +
         9.0 && l_istochastic_376 < 60.0 && li_52) || (l_iwpr_280 > l_iwpr_288 + 18.0 && l_istochastic_344 < 70.0 && li_28) && l_iwpr_280 < -15.0 && l_idemarker_320 > l_idemarker_328 &&
         l_ima_196 > l_ima_180 && l_ima_164 > l_ima_180) || (l_istochastic_344 < 40.0 && Open[1] > l_ima_156 && l_ima_188 < l_ima_220) || (l_istochastic_384 < 40.0 && l_ima_164 > l_ima_180 && l_ima_212 > l_ima_196) ||
         (Open[2] > l_ima_196 && Open[1] < Close[1] && Open[0] > Close[1] && li_28 && l_iwpr_280 > l_iwpr_288 + 7.0 && l_idemarker_320 > l_idemarker_328 + 0.1)) || (Predict2() == 1.0 && (l_istochastic_344 < 50.0 && Open[1] > l_ima_156 && l_ima_188 < l_ima_220 && li_28 && Open[0] > Close[1] && Open[1] > Close[1])) ||
         (Predict2() == 1.0 && l_istochastic_344 < 50.0 && li_28 && l_iwpr_280 > l_iwpr_288 + 7.0 && Open[2] < Close[2] && Open[0] > Close[1] && Open[1] > Close[1]) || (Predict2() == 3.0 &&
         Open[0] > Close[1] && Open[1] < Close[1])) li_524 = 1;
      if ((l_ima_228 > l_ima_236 && l_ima_164 > l_ima_180 + 0.0002 && Open[0] < l_ima_164 + l_istddev_264 && (l_istochastic_376 > l_istochastic_384 && l_istochastic_392 > l_istochastic_400) ||
         (l_istochastic_344 > l_istochastic_352 && l_istochastic_360 > l_istochastic_368) && l_iwpr_280 < -15.0 && l_iwpr_280 > l_iwpr_288 + 3.0 && li_28 && l_ima_188 > l_ima_164 && Open[0] > l_ima_228) ||
         (l_iwpr_304 > l_iwpr_312 && l_iwpr_304 > -20.0 && l_iwpr_312 > -20.0 && l_iwpr_280 > l_iwpr_288 + 25.0 && l_iwpr_280 < -15.0 && l_iwpr_288 < l_iwpr_296 && l_istddev_264 > l_istddev_272 &&
         l_idemarker_320 > l_idemarker_328 && l_ima_164 > l_ima_172 && li_28 && l_iadx_472 > 20.0) || (Low[1] < l_ima_164 - 3.2 * l_istddev_272 && l_iwpr_280 > l_iwpr_288 + 7.0 && l_iwpr_280 < -75.0 && li_28 && (l_istochastic_344 >= 20.0 && l_istddev_264 > l_istddev_272) ||
         l_iwpr_288 < l_iwpr_296) || (l_ima_132 > l_ima_188 && l_ima_132 > l_ima_140 && l_ima_140 < l_ima_188 && l_ima_164 > l_ima_172 + 0.0002 && Open[1] < Close[1] && li_28 && l_iwpr_280 > l_iwpr_288 + 7.0 && l_idemarker_320 > l_idemarker_328 && l_iadx_480 > l_iadx_496) ||
         (li_20 && l_imacd_100 > l_imacd_108 && l_imacd_100 > l_imacd_116 && l_ima_212 > l_ima_196 && li_16 && l_iwpr_280 > l_iwpr_288 + 7.0 && l_istochastic_344 > l_istochastic_352 &&
         l_istochastic_360 > l_istochastic_368 + 1.0) || (l_imacd_100 > l_imacd_108 && l_imacd_100 < 0.0 && l_imacd_100 > l_imacd_116 && l_imacd_108 < l_imacd_124 && li_28 && l_iwpr_280 > l_iwpr_288 && li_16 && l_ima_212 > l_ima_196 && Close[1] < Open[0] && Close[1] > Open[1] && l_istddev_264 > l_istddev_272) ||
         (li_20 && l_imacd_100 > l_imacd_108 && l_imacd_100 > l_imacd_116 && l_ima_188 < l_ima_196 && l_iwpr_280 > l_iwpr_288 + 9.0 && li_16 && l_ima_212 > l_ima_196) || (l_iwpr_280 >= -75.0 &&
         l_iwpr_280 > l_iwpr_288 + 9.0 && l_iwpr_288 < l_iwpr_296 - 5.0 && Open[2] < Close[2] && Open[1] > Close[2] && Open[1] < Close[1] && li_28 && l_ima_188 > l_ima_196 +
         0.0005 && l_iadx_472 > 25.0 && l_iadx_480 > 25.0 && l_ima_212 > l_ima_196) || (li_244 == 1 && l_iadx_480 > 25.0 && l_iwpr_280 > l_iwpr_288 + 12.0 && l_iadx_472 > 25.0 && l_iadx_480 > l_iadx_488 ||
         l_ima_212 > l_ima_196 && l_ima_164 >= l_ima_180 && l_ima_236 < l_ima_220 && li_28) || (Close[4] < Close[3] && Close[3] > Close[2] && Close[2] > Close[1] && Open[0] > Close[1] && High[1] - Close[1] < Open[1] - Low[1] && l_ima_188 > l_ima_220 + 0.0005 && l_iwpr_280 > l_iwpr_288 + 9.0 && l_iadx_472 > 25.0 && l_iadx_480 > 25.0 && l_iwpr_288 > l_iwpr_296) ||
         (Open[1] < Close[1] && Close[2] < l_ima_164 && Close[1] > l_ima_164 && Open[1] > l_ima_228 && Open[0] > l_ima_132 && l_ima_164 > l_ima_172 + 0.0005 && l_iwpr_280 < -5.0 &&
         l_iwpr_280 > l_iwpr_288 + 7.0 && l_idemarker_320 > l_idemarker_328 && l_idemarker_328 > l_idemarker_336) || (l_irsi_416 < l_irsi_424 && l_irsi_408 > l_irsi_416 + 5.0 && l_irsi_416 < 30.0 && l_ima_212 > l_ima_196 && l_iadx_472 > 25.0 && l_iadx_480 > 25.0) ||
         (Close[1] > l_ima_196 && Open[1] < l_ima_196 && l_ima_212 > l_ima_196 && l_iadx_472 > 30.0 && l_iadx_480 > 25.0 && l_ima_164 > l_ima_172 + 0.0003 && li_28 && l_iwpr_280 > l_iwpr_288 +
         18.0 && l_iwpr_288 > l_iwpr_296 + 7.0) || (li_36 && Open[1] > l_ima_156 && Open[0] > l_ima_132 && Open[1] < Close[1] && l_ima_164 > l_ima_180 + 0.0002 && l_iadx_472 > 25.0 && l_iadx_480 > 25.0 && l_iwpr_280 > l_iwpr_288 + 9.0 && l_ima_212 > l_ima_196) ||
         (li_36 && l_imacd_100 > l_imacd_108 && l_imacd_100 < 0.0 && l_imacd_100 > l_imacd_116 && l_iadx_472 > 25.0 && l_iadx_480 > 25.0 && l_iwpr_280 > l_iwpr_288 + 7.0 &&
         l_istochastic_376 > l_istochastic_384 && l_istochastic_392 > l_istochastic_400 + 1.0) || (Close[2] < l_ibands_448 && Open[1] > l_ibands_440 && Open[0] > Close[1] && Open[1] < Close[1] && li_52 && l_iwpr_280 > l_iwpr_288 + 12.0 && l_istochastic_376 > l_istochastic_384 + 3.0 && l_istochastic_392 > l_istochastic_400 && l_ima_212 > l_ima_196 && l_ima_188 > l_ima_196) ||
         (l_iadx_480 > l_iadx_488 && l_iadx_488 < l_iadx_504 && l_iadx_480 >= l_iadx_496 && l_iadx_472 >= 35.0 && l_iadx_480 > 25.0 && l_iwpr_280 > l_iwpr_288 + 15.0 && li_28) ||
         (l_ima_228 > l_ima_236 && l_ima_188 > l_ima_196 && l_ima_164 > l_ima_180 && l_ima_164 > l_ima_172 + 0.0005 && l_ima_188 - l_ima_196 > l_ima_164 - l_ima_180 && l_ima_228 - l_ima_164 > l_ima_236 - l_ima_180 &&
         li_28 && l_iwpr_280 < -15.0 && l_iwpr_280 > l_iwpr_288 + 15.0 && l_ima_228 > l_ima_188 && l_ima_188 > l_ima_164 && Open[0] > l_ima_228) || ((li_44 && l_istochastic_384 < 25.0) ||
         (li_36 && l_istochastic_384 < 30.0) && l_ima_164 > l_ima_180 + 0.0002 && l_ima_212 > l_ima_196) || (li_20 && l_istochastic_344 < 30.0 && Open[1] > l_ima_156 && Close[1] > l_ima_220 && Open[0] > l_ima_132 && l_ima_188 < l_ima_220 && l_ima_188 < l_ima_196) ||
         (li_20 && Open[1] > l_ima_156 && Open[0] > l_ima_132 && Open[1] < Close[1] && l_iwpr_280 > l_iwpr_288 + 7.0 && l_idemarker_320 > l_idemarker_328 + 0.08 && l_istddev_264 > l_istddev_272) ||
         (Close[3] > l_ima_220 && Open[2] > l_ima_196 && Open[1] < Close[1] && Open[1] > Close[2] && Close[1] > l_ima_164 + 2.2 * l_istddev_272 && Open[0] > Close[1] && l_istddev_264 > l_istddev_272 &&
         li_28 && l_iwpr_280 > l_iwpr_288 + 7.0 && l_iwpr_280 < -10.0) || (l_ima_196 < l_ima_204 - 0.0001 && l_ima_188 > l_ima_196 + 0.0002 && l_ima_188 > l_ima_204 + 0.0001 && l_ima_196 < l_ima_180 && li_28 ||
         li_52 && Open[0] > Close[1]) || (l_ima_180 - l_ima_248 < l_ima_164 - l_ima_248 && l_ima_248 < (l_high_84 + l_low_92) / 2.0 - 2.0 * l_istddev_256 && l_ima_164 - l_ima_248 > l_istddev_256 && Open[0] > Close[1] && li_28) ||
         (iSAR(NULL, 0, 0.02, 0.2, 1) > Close[1] && iSAR(NULL, 0, 0.02, 0.2, 0) < Open[0] && iSAR(NULL, PERIOD_M15, 0.02, 0.2, 1) > iClose(NULL, PERIOD_M15, 1) && iSAR(NULL, PERIOD_M15, 0.02, 0.2, 0) < iOpen(NULL, PERIOD_M15, 0) &&
         iSAR(NULL, PERIOD_M30, 0.02, 0.2, 1) > iClose(NULL, PERIOD_M30, 1) && iSAR(NULL, PERIOD_M30, 0.02, 0.2, 0) < iOpen(NULL, PERIOD_M30, 0) && (Open[0] < Close[0] && Open[0] > Close[1] &&
         Ask > l_ima_164) || (l_ima_228 > l_ima_236 && l_imacd_100 > l_imacd_108 && l_imacd_100 < 0.0))) li_524 = 2;
      if (li_524 == 1 || li_524 == 2 || li_524 == 3) {
         if (l_price_516 > 0.0) l_price_516 = Ask - StopLoss * g_point_360;
         if (li_524 == 1) g_price_344 = Ask + gd_352 * g_point_360;
         if (li_524 == 2) g_price_344 = Ask + TakeProfit * g_point_360;
         if (li_524 == 3) g_price_344 = Ask + gd_352 * g_point_360;
         l_ticket_0 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, g_slippage_368, 0, 0, "", g_magic_92, 0, Green);
         if (l_ticket_0 > 0) {
            if (OrderSelect(l_ticket_0, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ", OrderOpenPrice());
            OrderModify(OrderTicket(), OrderOpenPrice(), l_price_516, g_price_344, 0, CLR_NONE);
         } else Print("Error opening BUY order : ", GetLastError());
         return (0);
      }
      if ((Predict() == 4.0 && ((l_iwpr_280 < l_iwpr_288 - 9.0 && li_56) || (l_iwpr_280 < l_iwpr_288 - 9.0 && li_32) && l_idemarker_320 < l_idemarker_328 - 0.05 && l_ima_196 > l_ima_180) ||
         (l_istochastic_344 > 60.0 && Open[1] > l_ima_140 && l_ima_164 < l_ima_220) || (l_istochastic_384 > 60.0 && l_ima_164 < l_ima_180 && l_ima_212 < l_ima_196) || (Open[2] < l_ima_196 &&
         Open[1] > Close[1] && Open[0] < Close[1] && li_32 && l_iwpr_280 < l_iwpr_288 - 7.0 && l_idemarker_320 < l_idemarker_328 - 0.05)) || (Predict() == 2.0 && ((l_iwpr_280 < l_iwpr_288 - 9.0 &&
         l_istochastic_376 > 40.0 && li_56) || (l_iwpr_280 < l_iwpr_288 - 18.0 && l_istochastic_344 > 30.0 && li_32) && l_iwpr_280 > -85.0 && l_idemarker_320 < l_idemarker_328 &&
         l_ima_196 < l_ima_180 && l_ima_164 < l_ima_180) || (l_istochastic_344 > 60.0 && Open[1] < l_ima_140 && l_ima_188 > l_ima_220) || (l_istochastic_384 > 60.0 && l_ima_164 < l_ima_180 && l_ima_212 < l_ima_196) ||
         (Open[2] < l_ima_196 && Open[1] > Close[1] && Open[0] < Close[1] && li_32 && l_iwpr_280 < l_iwpr_288 - 7.0 && l_idemarker_320 < l_idemarker_328 - 0.1)) || (Predict2() == 2.0 && (l_istochastic_344 > 50.0 && Open[1] < l_ima_140 && l_ima_188 > l_ima_220 && li_32 && Open[0] < Close[1] && Open[1] < Close[1])) ||
         (Predict2() == 2.0 && li_32 && l_istochastic_344 > 50.0 && l_iwpr_280 < l_iwpr_288 - 7.0 && Open[2] > Close[2] && Open[0] < Close[1] && Open[1] < Close[1]) || (Predict2() == 4.0 &&
         Open[0] < Close[1] && Open[1] > Close[1])) li_528 = 1;
      if ((l_ima_228 < l_ima_236 && l_ima_164 < l_ima_180 - 0.0002 && Open[0] >= l_ima_164 - l_istddev_264 && (l_istochastic_376 < l_istochastic_384 && l_istochastic_392 < l_istochastic_400) ||
         (l_istochastic_344 < l_istochastic_352 && l_istochastic_360 < l_istochastic_368) && l_iwpr_280 > -85.0 && l_iwpr_280 < l_iwpr_288 - 3.0 && li_32 && l_ima_188 < l_ima_164 && Open[0] < l_ima_228) ||
         (l_iwpr_304 < l_iwpr_312 && l_iwpr_304 < -80.0 && l_iwpr_312 < -80.0 && l_iwpr_280 < l_iwpr_288 - 25.0 && l_iwpr_280 > -85.0 && l_iwpr_288 > l_iwpr_296 && l_istddev_264 > l_istddev_272 &&
         l_idemarker_320 < l_idemarker_328 && l_ima_164 < l_ima_172 && li_32 && l_iadx_472 > 20.0) || (High[1] > l_ima_164 + 3.2 * l_istddev_272 && l_iwpr_280 < l_iwpr_288 - 7.0 && l_iwpr_280 > -25.0 && li_32 && (l_istochastic_344 <= 80.0 && l_istddev_264 > l_istddev_272) ||
         l_iwpr_288 > l_iwpr_296) || (l_ima_148 < l_ima_188 && l_ima_148 < l_ima_156 && l_ima_156 > l_ima_188 && l_ima_164 < l_ima_172 - 0.0002 && Open[1] > Close[1] && li_32 && l_iwpr_280 < l_iwpr_288 - 7.0 && l_idemarker_320 < l_idemarker_328 && l_iadx_496 > l_iadx_480) ||
         (li_24 && l_imacd_100 < l_imacd_108 && l_imacd_100 < l_imacd_116 && l_ima_212 < l_ima_196 && li_12 && l_iwpr_280 < l_iwpr_288 - 7.0 && l_istochastic_344 < l_istochastic_352 &&
         l_istochastic_360 < l_istochastic_368 - 1.0) || (l_imacd_100 < l_imacd_108 && l_imacd_100 > 0.0 && l_imacd_100 < l_imacd_116 && l_imacd_108 > l_imacd_124 && li_32 && l_iwpr_280 < l_iwpr_288 && li_12 && l_ima_212 < l_ima_196 && Close[1] > Open[0] && Close[1] < Open[1] && l_istddev_264 > l_istddev_272) ||
         (li_24 && l_imacd_100 < l_imacd_108 && l_imacd_100 < l_imacd_116 && l_ima_188 > l_ima_196 && l_iwpr_280 < l_iwpr_288 - 9.0 && li_12 && l_ima_212 < l_ima_196) || (l_iwpr_280 <= -25.0 &&
         l_iwpr_280 < l_iwpr_288 - 9.0 && l_iwpr_288 > l_iwpr_296 + 5.0 && Open[2] > Close[2] && Open[1] < Close[2] && Open[1] > Close[1] && li_32 && l_ima_188 < l_ima_196 - 0.0005 &&
         l_iadx_472 > 25.0 && l_iadx_496 > 25.0 && l_ima_212 < l_ima_196) || (li_244 == 2 && l_iadx_496 > 25.0 && l_iwpr_280 < l_iwpr_288 - 12.0 && l_iadx_472 > 25.0 && l_iadx_496 > l_iadx_504 ||
         l_ima_212 < l_ima_196 && l_ima_164 <= l_ima_180 && l_ima_236 > l_ima_220 && li_32) || (Close[4] > Close[3] && Close[3] < Close[2] && Close[2] < Close[1] && Open[0] > Close[1] && Close[1] - Low[1] < High[1] - Open[1] && l_ima_188 < l_ima_220 - 0.0005 && l_iwpr_280 < l_iwpr_288 - 9.0 && l_iadx_472 > 25.0 && l_iadx_496 > 25.0 && l_iwpr_288 < l_iwpr_296) ||
         (Open[1] > Close[1] && Close[2] > l_ima_164 && Close[1] < l_ima_164 && Open[1] < l_ima_228 && Open[0] < l_ima_148 && l_ima_164 < l_ima_172 - 0.0005 && l_iwpr_280 > -95.0 &&
         l_iwpr_280 < l_iwpr_288 - 7.0 && l_idemarker_320 < l_idemarker_328 && l_idemarker_328 < l_idemarker_336) || (l_irsi_416 > l_irsi_424 && l_irsi_408 < l_irsi_416 - 5.0 && l_irsi_416 > 70.0 && l_ima_212 < l_ima_196 && l_iadx_472 > 25.0 && l_iadx_496 > 25.0) ||
         (Close[1] < l_ima_196 && Open[1] > l_ima_196 && l_ima_212 < l_ima_196 && l_iadx_472 > 30.0 && l_iadx_496 > 25.0 && l_ima_164 < l_ima_172 - 0.0003 && li_32 && l_iwpr_280 < l_iwpr_288 - 18.0 &&
         l_iwpr_288 < l_iwpr_296 - 7.0) || (li_40 && Open[1] < l_ima_140 && Open[0] < l_ima_148 && Open[1] > Close[1] && l_ima_164 < l_ima_180 - 0.0002 && l_iadx_472 > 25.0 && l_iadx_496 > 25.0 && l_iwpr_280 < l_iwpr_288 - 9.0 && l_ima_212 < l_ima_196) ||
         (li_40 && l_imacd_100 < l_imacd_108 && l_imacd_100 > 0.0 && l_imacd_100 < l_imacd_116 && l_iadx_472 > 25.0 && l_iadx_496 > 25.0 && l_iwpr_280 < l_iwpr_288 - 7.0 &&
         l_istochastic_376 < l_istochastic_384 && l_istochastic_392 < l_istochastic_400 - 1.0) || (Close[2] > l_ibands_464 && Open[1] < l_ibands_456 && Open[0] < Close[1] && Open[1] > Close[1] && li_56 && l_iwpr_280 < l_iwpr_288 - 12.0 && l_istochastic_376 < l_istochastic_384 - 3.0 && l_istochastic_392 < l_istochastic_400 && l_ima_212 < l_ima_196 && l_ima_188 < l_ima_196) ||
         (l_iadx_496 > l_iadx_504 && l_iadx_488 > l_iadx_504 && l_iadx_480 <= l_iadx_496 && l_iadx_472 >= 35.0 && l_iadx_496 > 25.0 && l_iwpr_280 < l_iwpr_288 - 15.0 && li_32) ||
         (l_ima_228 < l_ima_236 && l_ima_188 < l_ima_196 && l_ima_164 < l_ima_180 && l_ima_164 < l_ima_172 - 0.0005 && l_ima_196 - l_ima_188 > l_ima_180 - l_ima_164 && l_ima_164 - l_ima_228 > l_ima_180 - l_ima_236 &&
         li_32 && l_iwpr_280 > -85.0 && l_iwpr_280 < l_iwpr_288 - 15.0 && l_ima_228 < l_ima_188 && l_ima_188 < l_ima_164 && Open[0] < l_ima_228) || ((li_48 && l_istochastic_384 > 75.0) ||
         (li_40 && l_istochastic_384 > 705.0) && l_ima_164 < l_ima_180 - 0.0002 && l_ima_212 < l_ima_196) || (li_24 && l_istochastic_344 > 70.0 && Open[1] < l_ima_140 && Close[1] < l_ima_220 && Open[0] < l_ima_148 && l_ima_188 > l_ima_220 && l_ima_188 > l_ima_196) ||
         (li_24 && Open[1] < l_ima_140 && Open[0] < l_ima_148 && Open[1] > Close[1] && l_iwpr_280 < l_iwpr_288 - 7.0 && l_idemarker_320 < l_idemarker_328 - 0.08 && l_istddev_264 > l_istddev_272) ||
         (Close[3] < l_ima_220 && Open[2] < l_ima_196 && Open[1] > Close[1] && Open[1] < Close[2] && Close[1] < l_ima_164 - 2.2 * l_istddev_272 && Open[0] < Close[1] && l_istddev_264 > l_istddev_272 &&
         li_32 && l_iwpr_280 < l_iwpr_288 - 7.0 && l_iwpr_280 > -90.0) || (l_ima_196 > l_ima_204 + 0.0001 && l_ima_188 < l_ima_196 - 0.0002 && l_ima_188 < l_ima_204 - 0.0001 && l_ima_196 > l_ima_180 && li_32 ||
         li_56 && Open[0] < Close[1]) || (l_ima_180 - l_ima_248 > l_ima_164 - l_ima_248 && l_ima_248 > (l_high_84 + l_low_92) / 2.0 + 2.0 * l_istddev_256 && l_ima_248 - l_ima_164 > l_istddev_256 && Open[0] < Close[1] && li_32) ||
         (iSAR(NULL, 0, 0.02, 0.2, 1) < Close[1] && iSAR(NULL, 0, 0.02, 0.2, 0) > Open[0] && iSAR(NULL, PERIOD_M15, 0.02, 0.2, 1) < iClose(NULL, PERIOD_M15, 1) && iSAR(NULL, PERIOD_M15, 0.02, 0.2, 0) > iOpen(NULL, PERIOD_M15, 0) &&
         iSAR(NULL, PERIOD_M30, 0.02, 0.2, 1) < iClose(NULL, PERIOD_M30, 1) && iSAR(NULL, PERIOD_M30, 0.02, 0.2, 0) > iOpen(NULL, PERIOD_M30, 0) && (Open[0] > Close[0] && Open[0] < Close[1] &&
         Bid < l_ima_164) || (l_ima_228 < l_ima_236 && l_imacd_100 < l_imacd_108 && l_imacd_100 > 0.0))) li_528 = 2;
      if (Predict() == 2.0 || Predict2() == 2.0 && Bid > (l_high_84 + l_low_92) / 2.0 && li_32 && l_istochastic_344 > 55.0) li_528 = 3;
      if (li_528 == 1 || li_528 == 2 || li_528 == 3) {
         if (l_price_516 > 0.0) l_price_516 = Bid + StopLoss * g_point_360;
         if (li_528 == 1) g_price_344 = Bid - gd_352 * g_point_360;
         if (li_528 == 2) g_price_344 = Bid - TakeProfit * g_point_360;
         if (li_528 == 3) g_price_344 = Bid - gd_352 * g_point_360;
         l_ticket_0 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, g_slippage_368, 0, 0, "", g_magic_92, 0, Red);
         if (l_ticket_0 > 0) {
            if (OrderSelect(l_ticket_0, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice());
            OrderModify(OrderTicket(), OrderOpenPrice(), l_price_516, g_price_344, 0, CLR_NONE);
         } else Print("Error opening SELL order : ", GetLastError());
         return (0);
      }
      return (0);
   }
   if (Profit_Protection && AccountEquity() > AccountBalance() * (Percent_Over_Balance / 100.0 + 1.0)) Close_All();
   for (int l_pos_540 = 0; l_pos_540 < l_count_76; l_pos_540++) {
      li_unused_60 = 0;
      OrderSelect(l_pos_540, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_92) {
         l_price_64 = OrderStopLoss();
         if (OrderType() == OP_BUY) {
            if (AccountFreeMargin() <= 0.0 || (Balance_Protection && AccountEquity() + AccountMargin() < AccountBalance() * (1 - RiskPercent / 100.0))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_368, Violet);
               return (0);
            }
            if (TrailingStop <= 0.0) continue;
            if (TrailingStop < l_stoplevel_512) TrailingStop = l_stoplevel_512;
            if (Bid - OrderOpenPrice() <= g_point_360 * TrailingStop) continue;
            if (NormalizeDouble(l_price_64, Digits) >= NormalizeDouble(Bid - g_point_360 * TrailingStop, Digits)) continue;
            l_price_64 = Bid - g_point_360 * TrailingStop;
            l_price_4 = OrderTakeProfit();
            if (TrailingProfit && li_28 && l_istochastic_344 < 70.0) l_price_4 = OrderTakeProfit() + TrailingPips * g_point_360;
            OrderModify(OrderTicket(), OrderOpenPrice(), l_price_64, l_price_4, 0, Blue);
            return (0);
         }
         if (AccountFreeMargin() <= 0.0 || (Balance_Protection && AccountEquity() + AccountMargin() < AccountBalance() * (1 - RiskPercent / 100.0))) {
            OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_368, Violet);
            return (0);
         }
         if (TrailingStop > 0.0) {
            if (TrailingStop < l_stoplevel_512) TrailingStop = l_stoplevel_512;
            if (OrderOpenPrice() - Ask > g_point_360 * TrailingStop) {
               if (NormalizeDouble(l_price_64, Digits) > NormalizeDouble(Ask + g_point_360 * TrailingStop, Digits) || NormalizeDouble(l_price_64, Digits) == 0.0) {
                  l_price_64 = Ask + g_point_360 * TrailingStop;
                  l_price_4 = OrderTakeProfit();
                  if (TrailingProfit && li_32 && l_istochastic_344 > 30.0) l_price_4 = OrderTakeProfit() - TrailingPips * g_point_360;
                  OrderModify(OrderTicket(), OrderOpenPrice(), l_price_64, l_price_4, 0, Red);
                  return (0);
               }
            }
         }
      }
   }
   return (0);
}

double LotsOptimized() {
   if (!MM) return (LotSize);
   if (Max_Lot_Size > 0.0) gd_308 = Max_Lot_Size;
   double ld_ret_0 = AccountFreeMargin() * RiskPercent / 400.0;
   ld_ret_0 = NormalizeDouble(MathFloor(ld_ret_0 / gd_332) * g_lotstep_324, 2);
   if (ld_ret_0 < g_minlot_316) ld_ret_0 = g_minlot_316;
   if (ld_ret_0 > gd_308) ld_ret_0 = gd_308;
   return (ld_ret_0);
}

void Close_All() {
   int l_cmd_0;
   bool l_ord_close_4;
   for (int li_8 = OrdersTotal() - 1; li_8 >= 0; li_8--) {
      l_cmd_0 = OrderType();
      l_ord_close_4 = FALSE;
      if (OrderMagicNumber() == g_magic_92 || (OrderMagicNumber() != g_magic_92 && ProtectAll)) {
         switch (l_cmd_0) {
         case OP_BUY:
            l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), g_slippage_368, Pink);
            break;
         case OP_SELL:
            l_ord_close_4 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), g_slippage_368, Pink);
         }
         if (l_ord_close_4 == 0) Sleep(1000);
      }
   }
   Print("Account Profit Reached. All Open Trades Have Been Closed");
}

bool isTradeTime() {
   int l_str2time_0;
   int l_str2time_4;
   int l_datetime_8 = TimeCurrent();
   if (Use_Time_Mgmt) {
      l_str2time_0 = StrToTime(TradeStartHour + ":" + TradeStartMinutes);
      l_str2time_4 = StrToTime(TradeEndHour + ":" + TradeEndMinutes);
      if (l_str2time_0 < l_str2time_4 && l_datetime_8 < l_str2time_0 || l_datetime_8 >= l_str2time_4) return (FALSE);
      if (l_str2time_0 > l_str2time_4 && (l_datetime_8 < l_str2time_0 && l_datetime_8 >= l_str2time_4)) return (FALSE);
   }
   return (TRUE);
}

void closeExpiredOrders() {
   int l_datetime_0;
   int l_ord_total_4;
   if (gi_376) {
      if (Use_Time_Mgmt) {
         l_datetime_0 = TimeCurrent();
         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, MODE_TRADES) || OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_92 || OrderType() > OP_SELL) continue;
            if (l_datetime_0 - OrderOpenTime() > gi_340) OrderClose(OrderTicket(), OrderLots(), d_if(OrderType() == OP_BUY, Bid, Ask), g_slippage_368);
         }
      }
   }
}

double d_if(bool ai_0, double ad_4, double ad_12) {
   if (ai_0) return (ad_4);
   return (ad_12);
}

Recommend