Navigation:Home > Content >

SFXWPRV15~.mq4

Time: 2018-03-12 | Download file:SFXWPRV15~.mq4

#property copyright "Copyright © 2011, www.superfx.asia"
#property link      "http://www.superfx.asia"

//#include 
#import "stdlib.ex4"
   string ErrorDescription(int a0); // DA69CBAFF4D38B87377667EEC549DE5A
#import

extern int magic = 210612;
extern string www.superfx.asia = "superfx.asia-WPR";
extern string CommonSettings = "---------------------------------------------";
extern int user_slippage = 2;
extern int grid_size = 40;
extern double profit_lock = 0.9;
extern string MoneyManagementSettings = "---------------------------------------------";
extern double min_lots = 0.1;
extern double min_lots_increment = 0.1;
extern double account_risk = 100.0;
extern string IndicatorSettings = "---------------------------------------------";
extern int wpr_period = 14;
extern int shift = 1;
string gs_160 = "wprgrid15";
int gia_168[50];
int gia_172[50];
double gda_176[50];
double gda_180[50];
double gda_184[50];
double gda_188[50];
double gda_192[50];
double gda_196[50];
double g_iwpr_200 = 0.0;
double g_iwpr_208 = 0.0;
int gi_216 = 0;
int gi_220 = 0;
double gd_224 = 0.0;
double gd_232 = 0.0;
double gd_240 = 0.0;
double gd_248 = 0.0;
double gd_256 = 0.0;
double gd_264 = 0.0;
double gd_272 = 0.0;
double gd_280 = 0.0;
int gi_304 = 0;
int gi_308 = 10;
double gd_312 = 4.0;
double gd_320 = 25.0;
string gs_328 = "OrderReliable fname unset";
int g_error_336 = 0/* NO_ERROR */;
string gs_340 = "V1_1_1";

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double point_0 = MarketInfo(Symbol(), MODE_POINT);
   double ld_unused_8 = 0;
   if (MarketInfo(Symbol(), MODE_DIGITS) == 4.0 || MarketInfo(Symbol(), MODE_DIGITS) == 2.0) gi_304 = user_slippage;
   else
      if (MarketInfo(Symbol(), MODE_DIGITS) == 5.0 || MarketInfo(Symbol(), MODE_DIGITS) == 3.0) gi_304 = 10 * user_slippage;
   if (IsTradeAllowed() == FALSE) {
      Comment("Copyright © 2011, www.superfx.asia\nTrade not allowed.");
      return;
   }
   f0_10();
   f0_17();
   f0_11();
   f0_16();
   f0_21();
   f0_7();
   return (0);
}

// 72AB758D11C2D92CDF036A18DDE842B5
void f0_10() {
   gi_216 = 0;
   gi_220 = 0;
   for (int index_0 = 0; index_0 < 50; index_0++) {
      gia_168[index_0] = 0;
      gda_176[index_0] = 0;
      gda_184[index_0] = 0;
      gda_192[index_0] = 0;
      gia_172[index_0] = 0;
      gda_180[index_0] = 0;
      gda_188[index_0] = 0;
      gda_196[index_0] = 0;
   }
}

// DBFEE3EB37F90B3D848B0740DD3CE5E0
void f0_18() {
   gd_256 = 0;
   gd_264 = 0;
   ObjectDelete("line_buy");
   ObjectDelete("line_buy_ts");
}

// 23A8A411C8CC96B481AA426CA9EF7C65
void f0_2() {
   gd_272 = 0;
   gd_280 = 0;
   ObjectDelete("line_sell");
   ObjectDelete("line_sell_ts");
}

// C95E7A31339E23521630B0A2F23DD826
void f0_17() {
   int index_0 = 0;
   int index_4 = 0;
   double ld_8 = 0;
   double ld_16 = 0;
   double ld_24 = 0;
   double ld_32 = 0;
   for (int pos_40 = 0; pos_40 < OrdersTotal(); pos_40++) {
      if (OrderSelect(pos_40, SELECT_BY_POS, MODE_TRADES) == TRUE) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY) {
            gia_168[index_0] = OrderTicket();
            gda_176[index_0] = OrderLots();
            gda_184[index_0] = OrderProfit() + OrderCommission() + OrderSwap();
            gda_192[index_0] = OrderOpenPrice();
            ld_8 += gda_184[index_0];
            ld_24 += OrderLots();
            index_0++;
         }
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL) {
            gia_172[index_4] = OrderTicket();
            gda_180[index_4] = OrderLots();
            gda_188[index_4] = OrderProfit() + OrderCommission() + OrderSwap();
            gda_196[index_4] = OrderOpenPrice();
            ld_16 += gda_188[index_4];
            ld_32 += OrderLots();
            index_4++;
         }
      }
   }
   gi_216 = index_0;
   gi_220 = index_4;
   gd_224 = ld_8;
   gd_232 = ld_16;
   gd_240 = ld_24;
   gd_248 = ld_32;
}

// 85A868D4042C3C6F081B66174F7835FA
void f0_11() {
   int li_0;
   double ld_4;
   double ld_12;
   double ld_20;
   for (int index_28 = 0; index_28 < gi_216 - 1; index_28++) {
      for (int li_32 = index_28 + 1; li_32 < gi_216; li_32++) {
         if (gda_176[index_28] > 0.0 && gda_176[li_32] > 0.0) {
            if (gda_176[li_32] < gda_176[index_28]) {
               ld_4 = gda_176[index_28];
               gda_176[index_28] = gda_176[li_32];
               gda_176[li_32] = ld_4;
               li_0 = gia_168[index_28];
               gia_168[index_28] = gia_168[li_32];
               gia_168[li_32] = li_0;
               ld_12 = gda_184[index_28];
               gda_184[index_28] = gda_184[li_32];
               gda_184[li_32] = ld_12;
               ld_20 = gda_192[index_28];
               gda_192[index_28] = gda_192[li_32];
               gda_192[li_32] = ld_20;
            }
         }
      }
   }
   for (index_28 = 0; index_28 < gi_220 - 1; index_28++) {
      for (li_32 = index_28 + 1; li_32 < gi_220; li_32++) {
         if (gda_180[index_28] > 0.0 && gda_180[li_32] > 0.0) {
            if (gda_180[li_32] < gda_180[index_28]) {
               ld_4 = gda_180[index_28];
               gda_180[index_28] = gda_180[li_32];
               gda_180[li_32] = ld_4;
               li_0 = gia_172[index_28];
               gia_172[index_28] = gia_172[li_32];
               gia_172[li_32] = li_0;
               ld_12 = gda_188[index_28];
               gda_188[index_28] = gda_188[li_32];
               gda_188[li_32] = ld_12;
               ld_20 = gda_196[index_28];
               gda_196[index_28] = gda_196[li_32];
               gda_196[li_32] = ld_20;
            }
         }
      }
   }
}

// F126818C511C5C61572C35AC4CAEA0A2
void f0_21() {
   double lda_84[50];
   double lda_88[50];
   double ld_0 = 0;
   double ld_8 = 0;
   int li_unused_16 = 1;
   double ld_20 = 0;
   double ld_28 = 0;
   double ld_36 = 0;
   double ld_44 = 0;
   double ld_52 = 0;
   double ld_60 = 0;
   double ld_68 = 0;
   double ld_76 = 0;
   double ld_92 = MarketInfo(Symbol(), MODE_POINT);
   if (gi_304 > user_slippage) ld_92 = 10.0 * ld_92;
   if (gi_216 >= 1) ld_0 = f0_9(gda_176[0]);
   if (gi_220 >= 1) ld_8 = f0_9(gda_180[0]);
   if (gi_216 >= 1) {
      ld_68 = f0_14(gda_176[0]);
      for (int index_100 = 0; index_100 < 50; index_100++) lda_84[index_100] = 0;
      for (index_100 = 0; index_100 < gi_216; index_100++) lda_84[index_100] = MathRound(gda_176[index_100] / gda_176[0]);
      for (index_100 = 0; index_100 < gi_216; index_100++) {
         ld_36 += lda_84[index_100];
         ld_52 += gda_192[index_100] * lda_84[index_100];
      }
      ld_20 = ld_0 / (ld_68 / ld_92);
      ld_20 += ld_52;
      ld_20 /= ld_36;
      f0_20(ld_20, "line_buy", DodgerBlue, STYLE_SOLID, 2);
      if (gd_264 > 0.0) {
         ld_20 = gd_264 / (ld_68 / ld_92);
         ld_20 += ld_52;
         ld_20 /= ld_36;
         f0_20(ld_20, "line_buy_ts", DodgerBlue, STYLE_DASH, 1);
      }
   }
   if (gi_220 >= 1) {
      ld_76 = f0_14(gda_180[0]);
      for (index_100 = 0; index_100 < 50; index_100++) lda_88[index_100] = 0;
      for (index_100 = 0; index_100 < gi_220; index_100++) lda_88[index_100] = MathRound(gda_180[index_100] / gda_180[0]);
      for (index_100 = 0; index_100 < gi_220; index_100++) {
         ld_44 += lda_88[index_100];
         ld_60 += gda_196[index_100] * lda_88[index_100];
      }
      ld_28 = -1.0 * (ld_8 / (ld_76 / ld_92));
      ld_28 += ld_60;
      ld_28 /= ld_44;
      f0_20(ld_28, "line_sell", Tomato, STYLE_SOLID, 2);
      if (gd_280 > 0.0) {
         ld_28 = -1.0 * (gd_280 / (ld_76 / ld_92));
         ld_28 += ld_60;
         ld_28 /= ld_44;
         f0_20(ld_28, "line_sell_ts", Tomato, STYLE_DASH, 1);
      }
   }
}

// BD787A2F340C4AC21BA083035209F751
void f0_16() {
   double ld_8 = 0;
   double ld_16 = 0;
   if (gi_216 >= 1) ld_8 = f0_9(gda_176[0]);
   if (gi_220 >= 1) ld_16 = f0_9(gda_180[0]);
   string ls_0 = "\nCopyright © 2011, www.superfx.asia" 
      + "\nwprgrid15 is running." 
      + "\n" 
      + "\nSETTINGS: " 
      + "\nGrid size: " + grid_size 
      + "\nProfit locked: " + DoubleToStr(100.0 * profit_lock, 2) + "%" 
      + "\nMinimum lots: " + DoubleToStr(min_lots, 2) 
      + "\nAccount risk: " + DoubleToStr(account_risk, 0) + "%" 
      + "\nWPR Period: " + DoubleToStr(wpr_period, 0) 
      + "\nWPR shift: " + DoubleToStr(shift, 0) 
      + "\n" 
      + "\nBUY ORDERS" 
      + "\nNumber of orders: " + gi_216 
      + "\nTotal lots: " + DoubleToStr(gd_240, 2) 
      + "\nCurrent profit: " + DoubleToStr(gd_224, 2) 
      + "\nProfit goal: $" + DoubleToStr(ld_8, 2) 
      + "\nMaximum profit reached: $" + DoubleToStr(gd_256, 2) 
      + "\nProfit locked: $" + DoubleToStr(gd_264, 2) 
      + "\n" 
      + "\nSELL ORDERS" 
      + "\nNumber of orders: " + gi_220 
      + "\nTotal lots: " + DoubleToStr(gd_248, 2) 
      + "\nCurrent profit: " + DoubleToStr(gd_232, 2) 
      + "\nProfit goal: $" + DoubleToStr(ld_16, 2) 
      + "\nMaximum profit reached: $" + DoubleToStr(gd_272, 2) 
   + "\nProfit locked: $" + DoubleToStr(gd_280, 2);
   Comment(ls_0);
}

// ED4F1D667416C1A8B3393107C004A3DC
void f0_20(double a_price_0, string a_name_8, color a_color_16, int a_style_20, int a_width_24) {
   if (ObjectFind(a_name_8) == -1) {
      ObjectCreate(a_name_8, OBJ_HLINE, 0, Time[0], a_price_0);
      ObjectSet(a_name_8, OBJPROP_STYLE, a_style_20);
      ObjectSet(a_name_8, OBJPROP_COLOR, a_color_16);
      ObjectSet(a_name_8, OBJPROP_WIDTH, a_width_24);
      return;
   }
   ObjectSet(a_name_8, OBJPROP_PRICE1, a_price_0);
   ObjectSet(a_name_8, OBJPROP_STYLE, a_style_20);
   ObjectSet(a_name_8, OBJPROP_COLOR, a_color_16);
   ObjectSet(a_name_8, OBJPROP_WIDTH, a_width_24);
}

// 8E8C42B33CBEDA01A1F9BE92C9C8A47F
double f0_13() {
   double ld_ret_0 = min_lots;
   if (ld_ret_0 > MarketInfo(Symbol(), MODE_MAXLOT)) ld_ret_0 = MarketInfo(Symbol(), MODE_MAXLOT);
   if (ld_ret_0 < MarketInfo(Symbol(), MODE_MINLOT)) ld_ret_0 = MarketInfo(Symbol(), MODE_MINLOT);
   return (ld_ret_0);
}

// B4F212E511D2E70332D9FCA974C4DA8C
double f0_15(double ad_0) {
   int count_16;
   if (min_lots_increment >= 1.0) count_16 = 0;
   else {
      count_16 = 0;
      for (double ld_8 = ad_0; ld_8 < 1.0; ld_8 = 10.0 * ld_8) count_16++;
   }
   return (count_16);
}

// E8AA14254F7633D8F03F032FC36FBC23
double f0_19(double ad_0) {
   double ld_16 = f0_9(min_lots);
   double ld_24 = MathFloor(MathAbs(ad_0 / ld_16));
   double ld_ret_8 = NormalizeDouble(ld_24 * min_lots_increment, f0_15(min_lots_increment));
   if (ld_ret_8 < min_lots) ld_ret_8 = min_lots;
   if (ld_ret_8 > MarketInfo(Symbol(), MODE_MAXLOT)) ld_ret_8 = MarketInfo(Symbol(), MODE_MAXLOT);
   if (ld_ret_8 < MarketInfo(Symbol(), MODE_MINLOT)) ld_ret_8 = MarketInfo(Symbol(), MODE_MINLOT);
   return (ld_ret_8);
}

// A8C4252F1711418AF22CC90416295B51
double f0_14(double ad_0) {
   double ld_36;
   double ld_ret_8 = 0;
   double ld_16 = MarketInfo(Symbol(), MODE_TICKVALUE);
   double ticksize_24 = MarketInfo(Symbol(), MODE_TICKSIZE);
   int digits_32 = MarketInfo(Symbol(), MODE_DIGITS);
   if (ad_0 != 0.0) {
      ld_36 = 1 / ad_0;
      if (digits_32 == 5 || digits_32 == 3) ld_ret_8 = 10.0 * ld_16;
      else
         if (digits_32 == 4 || digits_32 == 2) ld_ret_8 = ld_16;
      ld_ret_8 /= ld_36;
   }
   return (ld_ret_8);
}

// 64DAE4B26B1ADE6B63355255DDF8ADAD
double f0_9(double ad_0) {
   int li_ret_8 = grid_size * f0_14(ad_0);
   return (li_ret_8);
}

// 299F62AF68464BA1BBCB6FEEFD4DB011
double f0_3(double ad_0) {
   int li_ret_8 = (-1 * grid_size) * f0_14(ad_0);
   return (li_ret_8);
}

// 5D1ECA158C00250D9C4C32D947B7C433
void f0_7() {
   int li_0 = -1;
   bool li_8 = FALSE;
   g_iwpr_200 = iWPR(Symbol(), 0, wpr_period, shift);
   g_iwpr_208 = iWPR(Symbol(), 0, wpr_period, shift + 1);
   if ((100 - account_risk) / 100.0 * AccountBalance() > AccountEquity()) {
      for (int index_4 = 0; index_4 <= gi_216 - 1; index_4++) li_8 = f0_1(gia_168[index_4], gda_176[index_4], MarketInfo(Symbol(), MODE_BID), gi_304, Blue);
      for (index_4 = 0; index_4 <= gi_220 - 1; index_4++) li_8 = f0_1(gia_172[index_4], gda_180[index_4], MarketInfo(Symbol(), MODE_ASK), gi_304, Red);
      f0_18();
      f0_2();
   }
   if (gi_216 == 0)
      if (g_iwpr_208 < -80.0 && g_iwpr_200 > -80.0) li_0 = f0_8(Symbol(), OP_BUY, f0_13(), MarketInfo(Symbol(), MODE_ASK), gi_304, 0, 0, gs_160, magic, 0, Blue);
   if (gi_216 >= 1) {
      if (gd_224 < f0_3(gd_240))
         if (gi_216 < 50 && g_iwpr_208 < -80.0 && g_iwpr_200 > -80.0) li_0 = f0_8(Symbol(), OP_BUY, f0_19(gd_224), MarketInfo(Symbol(), MODE_ASK), gi_304, 0, 0, gs_160, magic, 0, Blue);
      if (gd_256 == 0.0 && gd_224 > f0_9(gda_176[0])) {
         gd_256 = gd_224;
         gd_264 = profit_lock * gd_256;
      }
      if (gd_256 > 0.0) {
         if (gd_224 > gd_256) {
            gd_256 = gd_224;
            gd_264 = profit_lock * gd_224;
         }
      }
      if (gd_256 > 0.0 && gd_264 > 0.0 && gd_256 > gd_264 && gd_224 < gd_264) {
         for (index_4 = 0; index_4 <= gi_216 - 1; index_4++) li_8 = f0_1(gia_168[index_4], gda_176[index_4], MarketInfo(Symbol(), MODE_BID), gi_304, Blue);
         f0_18();
      }
   }
   if (gi_220 == 0)
      if (g_iwpr_208 > -20.0 && g_iwpr_200 < -20.0) li_0 = f0_8(Symbol(), OP_SELL, f0_13(), MarketInfo(Symbol(), MODE_BID), gi_304, 0, 0, gs_160, magic, 0, Red);
   if (gi_220 >= 1) {
      if (gd_232 < f0_3(gd_248))
         if (gi_220 < 50 && g_iwpr_208 > -20.0 && g_iwpr_200 < -20.0) li_0 = f0_8(Symbol(), OP_SELL, f0_19(gd_232), MarketInfo(Symbol(), MODE_BID), gi_304, 0, 0, gs_160, magic, 0, Red);
      if (gd_272 == 0.0 && gd_232 > f0_9(gda_180[0])) {
         gd_272 = gd_232;
         gd_280 = profit_lock * gd_272;
      }
      if (gd_272 > 0.0) {
         if (gd_232 > gd_272) {
            gd_272 = gd_232;
            gd_280 = profit_lock * gd_272;
         }
      }
      if (gd_272 > 0.0 && gd_280 > 0.0 && gd_272 > gd_280 && gd_232 < gd_280) {
         for (index_4 = 0; index_4 <= gi_220 - 1; index_4++) li_8 = f0_1(gia_172[index_4], gda_180[index_4], MarketInfo(Symbol(), MODE_ASK), gi_304, Red);
         f0_2();
      }
   }
}

// 63F809ED5E900872F8FA2BC6E67A5CF3
int f0_8(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, int a_slippage_28, double a_price_32, double a_price_40, string a_comment_48, int a_magic_56, int a_datetime_60 = 0, color a_color_64 = -1) {
   double ld_96;
   gs_328 = "OrderSendReliable";
   f0_4(" attempted " + f0_6(a_cmd_8) + " " + a_lots_12 + " lots @" + a_price_20 + " sl:" + a_price_32 + " tp:" + a_price_40);
   if (IsStopped()) {
      f0_4("error: IsStopped() == true");
      g_error_336 = 2;
      return (-1);
   }
   for (int count_68 = 0; !IsTradeAllowed() && count_68 < gi_308; count_68++) f0_0(gd_312, gd_320);
   if (!IsTradeAllowed()) {
      f0_4("error: no operation possible because IsTradeAllowed()==false, even after retries.");
      g_error_336 = 146;
      return (-1);
   }
   int digits_72 = MarketInfo(a_symbol_0, MODE_DIGITS);
   if (digits_72 > 0) {
      a_price_20 = NormalizeDouble(a_price_20, digits_72);
      a_price_32 = NormalizeDouble(a_price_32, digits_72);
      a_price_40 = NormalizeDouble(a_price_40, digits_72);
   }
   if (a_price_32 != 0.0) f0_12(a_symbol_0, a_price_20, a_price_32);
   int error_76 = GetLastError();
   error_76 = 0;
   g_error_336 = 0;
   bool li_80 = FALSE;
   bool li_84 = FALSE;
   int ticket_88 = -1;
   if (a_cmd_8 == OP_BUYSTOP || a_cmd_8 == OP_SELLSTOP || a_cmd_8 == OP_BUYLIMIT || a_cmd_8 == OP_SELLLIMIT) {
      count_68 = 0;
      while (!li_80) {
         if (IsTradeAllowed()) {
            ticket_88 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, a_slippage_28, a_price_32, a_price_40, a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            error_76 = GetLastError();
            g_error_336 = error_76;
         } else count_68++;
         switch (error_76) {
         case 0/* NO_ERROR */:
            li_80 = TRUE;
            break;
         case 4/* SERVER_BUSY */:
         case 6/* NO_CONNECTION */:
         case 129/* INVALID_PRICE */:
         case 136/* OFF_QUOTES */:
         case 137/* BROKER_BUSY */:
         case 146/* TRADE_CONTEXT_BUSY */:
            count_68++;
            break;
         case 135/* PRICE_CHANGED */:
         case 138/* REQUOTE */:
            RefreshRates();
            continue;
            break;
         case 130/* INVALID_STOPS */:
            ld_96 = MarketInfo(a_symbol_0, MODE_STOPLEVEL) * MarketInfo(a_symbol_0, MODE_POINT);
            if (a_cmd_8 == OP_BUYSTOP) {
               if (MathAbs(MarketInfo(a_symbol_0, MODE_ASK) - a_price_20) <= ld_96) li_84 = TRUE;
            } else {
               if (a_cmd_8 == OP_SELLSTOP)
                  if (MathAbs(MarketInfo(a_symbol_0, MODE_BID) - a_price_20) <= ld_96) li_84 = TRUE;
            }
            li_80 = TRUE;
            break;
         default:
            li_80 = TRUE;
            if (count_68 > gi_308) li_80 = TRUE;
            if (li_80) {
               if (error_76 != 0/* NO_ERROR */) f0_4("non-retryable error: " + f0_5(error_76));
               if (count_68 > gi_308) f0_4("retry attempts maxed at " + gi_308);
            }
            if (!(!li_80)) continue;
            f0_4("retryable error (" + count_68 + "/" + gi_308 + "): " + f0_5(error_76));
            f0_0(gd_312, gd_320);
            RefreshRates();
         }
      }
      if (error_76 == 0/* NO_ERROR */) {
         f0_4("apparently successful OP_BUYSTOP or OP_SELLSTOP order placed, details follow.");
         OrderSelect(ticket_88, SELECT_BY_TICKET, MODE_TRADES);
         OrderPrint();
         return (ticket_88);
      }
      if (!li_84) {
         f0_4("failed to execute stop or limit order after " + count_68 + " retries");
         f0_4("failed trade: " + f0_6(a_cmd_8) + " " + a_symbol_0 + "@" + a_price_20 + " [email protected]" + a_price_40 + " [email protected]" + a_price_32);
         f0_4("last error: " + f0_5(error_76));
         return (-1);
      }
   }
   if (li_84) {
      f0_4("going from limit order to market order because market is too close.");
      if (a_cmd_8 == OP_BUYSTOP || a_cmd_8 == OP_BUYLIMIT) {
         a_cmd_8 = 0;
         a_price_20 = MarketInfo(a_symbol_0, MODE_ASK);
      } else {
         if (a_cmd_8 == OP_SELLSTOP || a_cmd_8 == OP_SELLLIMIT) {
            a_cmd_8 = 1;
            a_price_20 = MarketInfo(a_symbol_0, MODE_BID);
         }
      }
   }
   error_76 = GetLastError();
   error_76 = 0;
   g_error_336 = 0;
   ticket_88 = -1;
   if (a_cmd_8 == OP_BUY || a_cmd_8 == OP_SELL) {
      count_68 = 0;
      while (!li_80) {
         if (IsTradeAllowed()) {
            ticket_88 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, a_slippage_28, a_price_32, a_price_40, a_comment_48, a_magic_56, a_datetime_60, a_color_64);
            error_76 = GetLastError();
            g_error_336 = error_76;
         } else count_68++;
         switch (error_76) {
         case 0/* NO_ERROR */:
            li_80 = TRUE;
            break;
         case 4/* SERVER_BUSY */:
         case 6/* NO_CONNECTION */:
         case 129/* INVALID_PRICE */:
         case 136/* OFF_QUOTES */:
         case 137/* BROKER_BUSY */:
         case 146/* TRADE_CONTEXT_BUSY */:
            count_68++;
            break;
         case 135/* PRICE_CHANGED */:
         case 138/* REQUOTE */:
            RefreshRates();
            continue;
            break;
         default:
            li_80 = TRUE;
            if (count_68 > gi_308) li_80 = TRUE;
            if (!li_80) {
               f0_4("retryable error (" + count_68 + "/" + gi_308 + "): " + f0_5(error_76));
               f0_0(gd_312, gd_320);
               RefreshRates();
            }
            if (!(li_80)) continue;
            if (error_76 != 0/* NO_ERROR */) f0_4("non-retryable error: " + f0_5(error_76));
            if (count_68 <= gi_308) continue;
            f0_4("retry attempts maxed at " + gi_308);
         }
      }
      if (error_76 == 0/* NO_ERROR */) {
         f0_4("apparently successful OP_BUY or OP_SELL order placed, details follow.");
         OrderSelect(ticket_88, SELECT_BY_TICKET, MODE_TRADES);
         OrderPrint();
         return (ticket_88);
      }
      f0_4("failed to execute OP_BUY/OP_SELL, after " + count_68 + " retries");
      f0_4("failed trade: " + f0_6(a_cmd_8) + " " + a_symbol_0 + "@" + a_price_20 + " [email protected]" + a_price_40 + " [email protected]" + a_price_32);
      f0_4("last error: " + f0_5(error_76));
      return (-1);
   }
   return (0);
}

// 207CA77B652B96112F2962B17C7FC706
int f0_1(int a_ticket_0, double a_lots_4, double a_price_12, int a_slippage_20, color a_color_24 = -1) {
   gs_328 = "OrderCloseReliable";
   f0_4(" attempted close of #" + a_ticket_0 + " price:" + a_price_12 + " lots:" + a_lots_4 + " slippage:" + a_slippage_20);
   if (!OrderSelect(a_ticket_0, SELECT_BY_TICKET)) {
      g_error_336 = GetLastError();
      f0_4("error: " + ErrorDescription(g_error_336));
      return (0);
   }
   int cmd_28 = OrderType();
   string symbol_32 = OrderSymbol();
   if (cmd_28 != OP_BUY && cmd_28 != OP_SELL) {
      g_error_336 = 4108;
      f0_4("error: trying to close ticket #" + a_ticket_0 + ", which is " + f0_6(cmd_28) + ", not OP_BUY or OP_SELL");
      return (0);
   }
   if (IsStopped()) {
      f0_4("error: IsStopped() == true");
      return (0);
   }
   int count_40 = 0;
   int error_44 = GetLastError();
   error_44 = 0;
   g_error_336 = 0;
   bool li_48 = FALSE;
   count_40 = 0;
   bool is_closed_52 = FALSE;
   while (!li_48) {
      if (IsTradeAllowed()) {
         is_closed_52 = OrderClose(a_ticket_0, a_lots_4, a_price_12, a_slippage_20, a_color_24);
         error_44 = GetLastError();
         g_error_336 = error_44;
      } else count_40++;
      if (is_closed_52 == 1) li_48 = TRUE;
      switch (error_44) {
      case 135/* PRICE_CHANGED */: continue;
      case 138/* REQUOTE */: continue;
      case 0/* NO_ERROR */:
         li_48 = TRUE;
         break;
      case 4/* SERVER_BUSY */:
      case 6/* NO_CONNECTION */:
      case 129/* INVALID_PRICE */:
      case 136/* OFF_QUOTES */:
      case 137/* BROKER_BUSY */:
      case 146/* TRADE_CONTEXT_BUSY */:
      case 128/* TRADE_TIMEOUT */:
         count_40++;
         break;
      default:
         li_48 = TRUE;
      }
      if (count_40 > gi_308) li_48 = TRUE;
      if (!li_48) {
         f0_4("retryable error (" + count_40 + "/" + gi_308 + "): " + f0_5(error_44));
         f0_0(gd_312, gd_320);
         if (cmd_28 == OP_BUY) a_price_12 = NormalizeDouble(MarketInfo(symbol_32, MODE_BID), MarketInfo(symbol_32, MODE_DIGITS));
         if (cmd_28 == OP_SELL) a_price_12 = NormalizeDouble(MarketInfo(symbol_32, MODE_ASK), MarketInfo(symbol_32, MODE_DIGITS));
      }
      if (li_48) {
         if (error_44 != 0/* NO_ERROR */ && error_44 != 1/* NO_RESULT */) f0_4("non-retryable error: " + f0_5(error_44));
         if (count_40 > gi_308) f0_4("retry attempts maxed at " + gi_308);
      }
   }
   if (is_closed_52 == 1 || error_44 == 0/* NO_ERROR */) {
      f0_4("apparently successful close order, updated trade details follow.");
      OrderSelect(a_ticket_0, SELECT_BY_TICKET, MODE_TRADES);
      OrderPrint();
      return (1);
   }
   f0_4("failed to execute close after " + count_40 + " retries");
   f0_4("failed close: Ticket #" + a_ticket_0 + ", Price: " + a_price_12 + ", Slippage: " + a_slippage_20);
   f0_4("last error: " + f0_5(error_44));
   return (0);
}

// 5149AAE98DBC653E2BE4FD3425E2DF9F
string f0_5(int ai_0) {
   return ("" + ai_0 + ":" + ErrorDescription(ai_0));
}

// 31D7DFA8442FDF5E8A38123047829292
void f0_4(string as_0) {
   if (!(IsTesting() || IsOptimization())) Print(gs_328 + " " + gs_340 + ":" + as_0);
}

// 550DB68CC3F51F6BFA0BAE3A70286DC3
string f0_6(int ai_0) {
   if (ai_0 == 0) return ("OP_BUY");
   if (ai_0 == 1) return ("OP_SELL");
   if (ai_0 == 4) return ("OP_BUYSTOP");
   if (ai_0 == 5) return ("OP_SELLSTOP");
   if (ai_0 == 2) return ("OP_BUYLIMIT");
   if (ai_0 == 3) return ("OP_SELLLIMIT");
   return ("(CMD==" + ai_0 + ")");
}

// 865F439BFDE48E26BCAABDADB2D94DE5
void f0_12(string a_symbol_0, double ad_8, double &ad_16) {
   double ld_24;
   if (ad_16 != 0.0) {
      ld_24 = MarketInfo(a_symbol_0, MODE_STOPLEVEL) * MarketInfo(a_symbol_0, MODE_POINT);
      if (MathAbs(ad_8 - ad_16) <= ld_24) {
         if (ad_8 > ad_16) ad_16 = ad_8 - ld_24;
         else {
            if (ad_8 < ad_16) ad_16 = ad_8 + ld_24;
            else f0_4("EnsureValidStop: error, passed in price == sl, cannot adjust");
         }
         ad_16 = NormalizeDouble(ad_16, MarketInfo(a_symbol_0, MODE_DIGITS));
      }
   }
}

// 081406D171CBF6523BDAC6124BC069E0
void f0_0(double ad_0, double ad_8) {
   double ld_16;
   int li_24;
   double ld_28;
   if (IsTesting() == FALSE) {
      ld_16 = MathCeil(ad_0 / 0.1);
      if (ld_16 > 0.0) {
         li_24 = MathRound(ad_8 / 0.1);
         ld_28 = 1.0 - 1.0 / ld_16;
         Sleep(100);
         for (int count_36 = 0; count_36 < li_24; count_36++) {
            if (MathRand() > 32768.0 * ld_28) break;
            Sleep(100);
         }
      }
   }
}

Recommend