Navigation:Home > Content >

MGT~.mq4

Time: 2017-06-27 | Download file:MGT~.mq4

#property copyright "©"
#property link      "http://www.tradingsystemforex.com/"

extern string comment = "EA";
extern int magic = 1234;
bool gi_88 = FALSE;
bool gi_92 = FALSE;
bool gi_96 = FALSE;
bool gi_100 = FALSE;
extern string moneymanagement = "Money Management";
extern double lots = 0.1;
extern bool mm = FALSE;
extern double risk = 1.0;
extern double minlot = 0.01;
extern double maxlot = 100.0;
extern int lotdigits = 2;
bool gi_152 = FALSE;
int gi_156 = 0;
double gd_160 = 2.0;
double gd_168 = 50.0;
bool gi_176 = FALSE;
int gi_180 = 0;
double gd_184 = 20.0;
double gd_192 = 1.0;
string gs_unused_200 = "Profit Management";
bool gi_208 = FALSE;
double gd_212 = 0.1;
double gd_220 = 100.0;
bool gi_228 = FALSE;
double gd_232 = 10.0;
double gd_240 = 10000.0;
bool gi_248 = FALSE;
double gd_252 = 5.0;
extern string ordersmanagement = "Order Management";
extern bool ecn = TRUE;
extern bool instantorders = TRUE;
extern bool stoporders = FALSE;
extern bool limitorders = FALSE;
extern bool onecancelother = FALSE;
extern int gap = 20;
extern bool oppositedelete = TRUE;
extern bool oppositeclose = TRUE;
int gi_300 = 0;
bool gi_304 = FALSE;
bool gi_308 = FALSE;
extern bool reversesignals = FALSE;
extern int maxtrades = 100;
extern int tradesperbar = 1;
extern bool hidesl = FALSE;
extern bool hidetp = FALSE;
extern double stoploss = 6.0;
extern double takeprofit = 0.0;
double gd_348 = 5.0;
double gd_unused_356 = 0.25;
double gd_364 = 20.0;
double gd_372 = 0.5;
extern double trailingstart = 6.0;
extern double trailingstop = 6.0;
double gd_396 = 0.0;
extern double trailingstep = 1.0;
extern double breakevengain = 0.0;
extern double breakeven = 0.0;
extern int expiration = 1440;
double gd_432 = 0.0;
extern double maxspread = 0.0;
extern string adordersmanagement = "Advanced Order Management";
bool gi_456 = FALSE;
bool gi_460 = FALSE;
extern bool enteronopenbar = FALSE;
bool gi_468 = TRUE;
extern bool onetimecalculation = FALSE;
extern double stop = 0.0;
extern double trailing = 0.0;
bool gi_492 = FALSE;
bool gi_496 = TRUE;
int gi_500 = 0;
int gi_504 = 0;
bool gi_508 = FALSE;
int gi_512 = 4;
int gi_516 = 60;
double gd_520 = 0.0;
int gi_528 = 0;
double gd_532 = 0.0;
int gi_540 = 15;
bool gi_544 = FALSE;
int g_timeframe_548 = PERIOD_H1;
int g_period_552 = 14;
double gd_556 = 0.0;
double gd_564 = 0.0;
double gd_572 = 0.0;
double gd_580 = 0.0;
double gd_588 = 0.0;
double gd_596 = 0.0;
bool gi_604 = FALSE;
int g_timeframe_608 = 0;
int gi_612 = 7;
bool gi_616 = FALSE;
int g_timeframe_620 = 0;
int gi_624 = 15;
int gi_628 = 3;
int gi_632 = 0;
extern string entrylogics = "Entry Logics";
extern double brokermode = 0.0;
extern double distance = 1.0;
extern bool long = TRUE;
extern int movements1 = 5;
extern double seconds1 = 3.0;
extern bool short = TRUE;
extern int movements2 = 5;
extern double seconds2 = 3.0;
int gi_692 = 1;
string gs_unused_696 = "Time Filter";
//bool gi_704 = FALSE;
int gi_708 = 2;
int gi_712 = 1;
bool gi_716 = FALSE;
int gi_720 = 12;
int gi_724 = 0;
bool gi_728 = FALSE;
int gi_732 = 7;
int gi_736 = 0;
int gi_740 = 21;
int gi_744 = 0;
bool gi_748 = TRUE;
bool gi_752 = FALSE;
int gi_756 = 12;
int gi_760 = 0;
bool gi_764 = FALSE;
int gi_768 = 120;
int gi_772 = 14;
int gi_776 = 30;
int gi_780 = 120;
string gs_unused_784 = "Time Outs and Targets";
bool gi_792 = FALSE;
int gi_796 = 30;
int gi_800 = 7;
int gi_804 = 70;
int gi_808 = 5;
int gi_812 = 95;
int gi_816 = 4;
int gi_820 = 120;
int gi_824 = 2;
int gi_828 = 150;
int gi_832 = -5;
int gi_836 = 180;
int gi_840 = -8;
int gi_844 = 210;
int gi_848 = -15;
int g_str2time_852;
int g_str2time_856;
int g_str2time_860;
int g_str2time_864;
int g_datetime_868;
int g_str2time_872;
int g_datetime_876;
int gi_880;
int gi_884;
int gi_888;
int gi_892;
int gi_896;
int gi_900;
int gi_904;
int g_datetime_908;
int gi_912;
int gi_916;
int g_pos_920;
int g_bars_924 = -1;
int g_count_928;
int g_count_932;
int g_count_936;
int gi_940 = 100;
int gi_948;
int gi_952;
int gi_956;
int g_count_960;
bool gi_964;
int gi_968 = 0;
bool gi_972;
int gi_976;
int gi_980;
int gi_984;
int gi_988;
int gi_992;
int g_count_996;
int gi_1000;
int gi_1004;
int gi_1008;
int gi_1012;
int gi_1016;
int gi_1020;
int gi_1024;
int gi_1028;
int gi_1032;
int gi_1036;
int gi_1040;
string gs_1044;
string gs_1052;
string gs_1060;
string gs_1068;
string gs_1076;
string gs_1084;
string gs_1092;
string gs_1100;
string gs_1108;
string gs_1116;
double g_price_1132;
double g_price_1140;
double gd_1148;
double gd_1156;
double g_order_lots_1180;
double g_order_profit_1188;
double gd_1196;
double gda_1204[14];
double gda_1208[14];
double gd_1212;
double gd_1220;
double gd_1228;
double gd_1236;
double g_order_open_price_1244;
double g_order_open_price_1252;
double gd_1276;
double gd_1284;
double gd_1292;
double gd_1300 = 0.0;
double gd_1308;
bool gi_1316 = FALSE;
bool gi_1320 = TRUE;
bool gi_1324 = TRUE;
double gd_1328;
double gd_1336;
double gd_1344;
double gd_1352;
int g_count_1360;
int g_count_1364;
int g_datetime_1368;
int g_datetime_1372;
bool gi_1376;
bool gi_1380;
double gd_1388;
double gd_1396;

int init() {
   /*if (gi_704) {
      gda_1208[13] = D'28.03.2012 05:00';
      gda_1204[13] = D'31.10.2012 06:00';
      gda_1208[12] = D'29.03.2011 05:00';
      gda_1204[12] = D'25.10.2011 06:00';
      gda_1208[11] = D'30.03.2010 05:00';
      gda_1204[11] = D'26.10.2010 06:00';
      gda_1208[10] = D'29.03.2009 05:00';
      gda_1204[10] = D'25.10.2009 06:00';
      gda_1208[9] = D'30.03.2008 05:00';
      gda_1204[9] = D'26.10.2008 06:00';
      gda_1208[8] = D'25.03.2007 05:00';
      gda_1204[8] = D'28.10.2007 06:00';
      gda_1208[7] = D'26.03.2006 04:00';
      gda_1204[7] = D'29.10.2006 05:00';
      gda_1208[6] = D'27.03.2005 04:00';
      gda_1204[6] = D'30.10.2005 05:00';
      gda_1208[5] = D'28.03.2004 04:00';
      gda_1204[5] = D'31.10.2004 05:00';
      gda_1208[4] = D'30.03.2003 04:00';
      gda_1204[4] = D'26.10.2003 05:00';
      gda_1208[3] = D'31.03.2002 04:00';
      gda_1204[3] = D'27.10.2002 05:00';
      gda_1208[2] = D'25.03.2001 04:00';
      gda_1204[2] = D'28.10.2001 05:00';
      gda_1208[1] = D'26.03.2000 04:00';
      gda_1204[1] = D'29.10.2000 05:00';
      gda_1208[0] = 922586400;
      gda_1204[0] = 941338800;
   }*/
   if (gi_208) {
      gd_1228 = AccountBalance() * gd_212 / 100.0;
      gd_1236 = (-1.0 * AccountBalance()) * gd_220 / 100.0;
   }
   if (Digits == 3 || Digits == 5) {
      gd_1328 = 10.0 * Point;
      gd_1344 = 10;
      if (brokermode == 0.0) {
         gd_1352 = Digits - 1;
         gd_1336 = gd_1328;
      }
      if (brokermode == 1.0) {
         gd_1352 = Digits;
         gd_1336 = Point;
      }
   } else {
      gd_1328 = Point;
      gd_1344 = 1;
      if (brokermode == 0.0 || brokermode == 1.0) {
         gd_1352 = Digits;
         gd_1336 = gd_1328;
      }
   }
   if (stop > 0.0) {
      stoploss = stop;
      takeprofit = stop;
   }
   if (mm) {
      if (minlot >= 1.0) gi_956 = 100000;
      if (minlot < 1.0) gi_956 = 10000;
      if (minlot < 0.1) gi_956 = 1000;
   }
   return (0);
}

int start() {
   double iatr_8;
   double ihigh_16;
   double ilow_24;
   int pos_32;
   int pos_36;
   int li_40;
   bool li_0 = TRUE;
   if (onetimecalculation)
      if (gi_880 == Time[0]) li_0 = FALSE;
   gi_1020 = count(OP_BUY);
   gi_1024 = count(OP_SELL);
   gi_1016 = gi_1020 + gi_1024;
   if (gi_1316) {
      gi_1028 = count(OP_BUYSTOP);
      gi_1032 = count(OP_SELLSTOP);
      gi_1036 = count(OP_BUYLIMIT);
      gi_1040 = count(OP_SELLLIMIT);
   }
   if (gi_1316) {
      if (gi_1016 + gi_1028 + gi_1032 + gi_1036 + gi_1040 > 0) {
         close(3);
         delete(6);
      }
   }
   if (gi_1316)
      if (gi_1016 + gi_1028 + gi_1032 + gi_1036 + gi_1040 == 0) gi_1316 = FALSE;
   if (gi_1316) return (0);
   if (breakevengain > 0.0 && li_0) movebreakeven(breakevengain, breakeven);
   if (trailingstop > 0.0 && li_0) movetrailingstop(trailingstart, trailingstop);
   if (trailing > 0.0 && li_0) movetrailingstop(trailing, trailing);
   if (gd_396 > 0.0 && li_0) movetrailingprofit(trailingstart, gd_396);
   if (gi_208 || gi_248 || gi_968 == TRUE) {
      gi_948 = 0;
      gi_952 = 0;
   }
   if (gi_228) {
      gd_1284 = 0;
      gd_1292 = 0;
   }
   g_order_open_price_1244 = 0;
   g_order_open_price_1252 = 0;
   if (OrdersTotal() > 0) {
      for (g_pos_920 = 0; g_pos_920 <= OrdersTotal(); g_pos_920++) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderCloseTime() == 0) {
            if (OrderType() == OP_BUY) {
               g_datetime_868 = OrderOpenTime();
               if (gi_176) g_order_open_price_1244 = OrderOpenPrice();
               if (gi_208 || gi_248 || gi_968 == TRUE) gi_948 = gi_948 + OrderProfit();
               if (gi_228) gd_1284 = gd_1284 + (OrderClosePrice() - OrderOpenPrice()) / gd_1328 - MarketInfo(Symbol(), MODE_SPREAD);
            }
            if (OrderType() == OP_SELL) {
               g_datetime_876 = OrderOpenTime();
               if (gi_176) g_order_open_price_1252 = OrderOpenPrice();
               if (gi_208 || gi_248 || gi_968 == TRUE) gi_952 = gi_952 + OrderProfit();
               if (gi_228) gd_1292 = gd_1292 + (OrderOpenPrice() - OrderClosePrice()) / gd_1328 - MarketInfo(Symbol(), MODE_SPREAD);
            }
         }
      }
   }
   if (gi_208 || gi_248 || gi_968 == TRUE) gd_1220 = gi_948 + gi_952;
   if (gi_228) gd_1212 = gd_1284 + gd_1292;
   if (gi_208) {
      if ((mm && gd_1220 >= AccountBalance() * gd_212 / 100.0) || (mm == FALSE && gd_1220 >= gd_1228) || (mm && gd_1220 <= (-1.0 * AccountBalance()) * gd_220 / 100.0) ||
         (mm == FALSE && gd_1220 <= gd_1236)) gi_1316 = TRUE;
   }
   if (gi_228)
      if (gd_1212 >= gd_232 || gd_1212 <= (-1.0 * gd_240)) gi_1316 = TRUE;
   if (gi_248)
      if (gd_1220 >= gd_252) gi_1316 = TRUE;
   if (gi_1316) return (0);
   bool li_4 = TRUE;
   if (gi_508 && OrdersHistoryTotal() > 0) {
      g_count_960 = 0;
      gi_964 = FALSE;
      for (g_pos_920 = OrdersHistoryTotal() - 1; g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_HISTORY);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
            if (OrderProfit() >= 0.0) gi_964 = TRUE;
            if (OrderProfit() < 0.0 && gi_964 == FALSE) g_count_960++;
         }
      }
      for (g_pos_920 = 0; g_pos_920 < OrdersHistoryTotal(); g_pos_920++) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_HISTORY);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
            if (g_count_960 >= gi_512) g_datetime_908 = OrderCloseTime();
      }
      if (TimeCurrent() - g_datetime_908 < 60 * gi_516) li_4 = FALSE;
   }
   if (tradesperbar == 1) {
      if (g_datetime_868 < Time[0]) g_count_932 = 0;
      else g_count_932 = 1;
      if (g_datetime_876 < Time[0]) g_count_936 = 0;
      else g_count_936 = 1;
   }
   if (tradesperbar != 1 && g_bars_924 != Bars) {
      g_count_932 = 0;
      g_count_936 = 0;
      g_bars_924 = Bars;
   }
   if (li_0 || gi_692 == 0) {
      if (gi_544) iatr_8 = iATR(NULL, g_timeframe_548, g_period_552, gi_692);
      if (gi_604) {
         ihigh_16 = iHigh(NULL, g_timeframe_608, iHighest(NULL, 0, MODE_HIGH, gi_612, 1));
         ilow_24 = iLow(NULL, g_timeframe_608, iLowest(NULL, 0, MODE_LOW, gi_612, 1));
      }
      if (gi_616) {
         pos_32 = 0;
         for (g_pos_920 = 0; g_pos_920 <= 100; g_pos_920++) {
            if (pos_32 == 0) {
               if (iCustom(NULL, g_timeframe_620, "Slope Direction Line", gi_624, gi_628, gi_632, 2, g_pos_920) > iCustom(NULL, g_timeframe_620, "Slope Direction Line", gi_624,
                  gi_628, gi_632, 2, g_pos_920 + 1) && iCustom(NULL, g_timeframe_620, "Slope Direction Line", gi_624, gi_628, gi_632, 2, g_pos_920 + 1) < iCustom(NULL, g_timeframe_620,
                  "Slope Direction Line", gi_624, gi_628, gi_632, 2, g_pos_920 + 2)) pos_32 = g_pos_920;
            }
         }
         pos_36 = 0;
         for (g_pos_920 = 0; g_pos_920 <= 100; g_pos_920++) {
            if (pos_36 == 0) {
               if (iCustom(NULL, g_timeframe_620, "Slope Direction Line", gi_624, gi_628, gi_632, 2, g_pos_920) < iCustom(NULL, g_timeframe_620, "Slope Direction Line", gi_624,
                  gi_628, gi_632, 2, g_pos_920 + 1) && iCustom(NULL, g_timeframe_620, "Slope Direction Line", gi_624, gi_628, gi_632, 2, g_pos_920 + 1) > iCustom(NULL, g_timeframe_620,
                  "Slope Direction Line", gi_624, gi_628, gi_632, 2, g_pos_920 + 2)) pos_36 = g_pos_920;
            }
         }
      }
      if (gi_1016 == 0) {
         if (gd_1388 <= NormalizeDouble(Ask, gd_1352) - distance * gd_1336) {
            g_count_1360++;
            gd_1388 = NormalizeDouble(Ask, gd_1352);
            if (gi_1376 == FALSE) {
               g_datetime_1368 = TimeCurrent();
               gi_1376 = TRUE;
            }
         } else {
            gd_1388 = 0;
            g_count_1360 = 0;
            gi_1376 = FALSE;
            g_datetime_1368 = 0;
         }
         if (gd_1396 >= NormalizeDouble(Ask, gd_1352) + distance * gd_1336) {
            g_count_1364++;
            gd_1396 = NormalizeDouble(Ask, gd_1352);
            if (gi_1380 == FALSE) {
               g_datetime_1372 = TimeCurrent();
               gi_1380 = TRUE;
            }
         } else {
            gd_1396 = 0;
            g_count_1364 = 0;
            gi_1380 = FALSE;
            g_datetime_1372 = 0;
         }
         if (gd_1388 == 0.0) gd_1388 = NormalizeDouble(Ask, gd_1352);
         if (gd_1396 == 0.0) gd_1396 = NormalizeDouble(Ask, gd_1352);
      }
      li_40 = 0;
      if (long && g_count_1360 == movements1 || g_count_1364 == movements2 && g_count_1360 >= g_count_1364 && TimeCurrent() - g_datetime_1368 <= seconds1) li_40 = 1;
      if (short && g_count_1360 == movements1 || g_count_1364 == movements2 && g_count_1360 < g_count_1364 && TimeCurrent() - g_datetime_1372 <= seconds2) li_40 = 2;
      if (li_40 != 0) {
         gd_1388 = 0;
         gd_1396 = 0;
         g_count_1360 = 0;
         g_count_1364 = 0;
         gi_1376 = FALSE;
         gi_1380 = FALSE;
         g_datetime_1368 = 0;
         g_datetime_1372 = 0;
      }
      if (gi_544) {
         if (li_40 != 0 && gd_520 != 0.0) stoploss = iatr_8 / gd_1328 * gd_520 + gi_528;
         if (li_40 != 0 && gd_532 != 0.0) takeprofit = iatr_8 / gd_1328 * gd_532 + gi_528;
         if (li_40 != 0 && gd_556 != 0.0) trailingstart = iatr_8 / gd_1328 * gd_556;
         if (li_40 != 0 && gd_564 != 0.0) trailingstop = iatr_8 / gd_1328 * gd_564;
         if (li_40 != 0 && gd_572 != 0.0) breakevengain = iatr_8 / gd_1328 * gd_572;
         if (li_40 != 0 && gd_580 != 0.0) breakeven = iatr_8 / gd_1328 * gd_580;
         if (li_40 != 0 && gd_588 != 0.0) gd_184 = iatr_8 / gd_1328 * gd_588;
         if (li_40 != 0 && gd_596 != 0.0) gap = iatr_8 / gd_1328 * gd_596;
      }
      if (gi_604) {
         if (li_40 == 1 && gd_520 != 0.0) stoploss = (Ask - ilow_24) / gd_1328 * gd_520 + gi_528;
         if (li_40 == 1 && gd_532 != 0.0) takeprofit = (ihigh_16 - Bid) / gd_1328 * gd_532;
         if (li_40 == 2 && gd_520 != 0.0) stoploss = (ihigh_16 - Bid) / gd_1328 * gd_520 + gi_528;
         if (li_40 == 2 && gd_532 != 0.0) takeprofit = (Ask - ilow_24) / gd_1328 * gd_532;
      }
      if (gi_616) {
         if (li_40 == 1 && gd_520 != 0.0) stoploss = (Ask - Low[pos_32]) / gd_1328 * gd_520 + gi_528;
         if (li_40 == 1 && gd_532 != 0.0) takeprofit = (High[pos_36] - Bid) / gd_1328 * gd_532;
         if (li_40 == 2 && gd_520 != 0.0) stoploss = (High[pos_36] - Bid) / gd_1328 * gd_520 + gi_528;
         if (li_40 == 2 && gd_532 != 0.0) takeprofit = (Ask - Low[pos_32]) / gd_1328 * gd_532;
      }
      if (gi_544 || gi_604 || gi_616) {
         if (stoploss < gi_540) stoploss = gi_540;
         if (takeprofit < gi_540) takeprofit = gi_540;
      }
   }
   bool li_44 = TRUE;
   //if (gi_704)
     // if (checktime()==true) li_44 = FALSE;
   bool li_48 = FALSE;
   bool li_52 = FALSE;
   bool li_56 = TRUE;
   if (enteronopenbar)
      if (iVolume(NULL, 0, 0) > 1.0) li_56 = FALSE;
   bool li_60 = TRUE;
   bool li_64 = TRUE;
   if (gi_176) {
      if (gi_1020 > 0) li_60 = FALSE;
      if (gi_1024 > 0) li_64 = FALSE;
      if (gi_1020 > 0) {
         if ((gi_180 == 0 && Ask <= g_order_open_price_1244 - gd_184 * gd_1328 * MathPow(gd_192, gi_1020)) || (gi_180 == 1 && Ask >= g_order_open_price_1244 + gd_184 * gd_1328 * MathPow(gd_192,
            gi_1020)) && gi_468 || (gi_468 == FALSE && li_56)) li_48 = TRUE;
      }
      if (gi_1024 > 0) {
         if ((gi_180 == 0 && Bid >= g_order_open_price_1252 + gd_184 * gd_1328 * MathPow(gd_192, gi_1024)) || (gi_180 == 1 && Bid <= g_order_open_price_1252 - gd_184 * gd_1328 * MathPow(gd_192,
            gi_1024)) && gi_468 || (gi_468 == FALSE && li_56)) li_52 = TRUE;
      }
   }
   bool li_68 = TRUE;
   bool li_72 = TRUE;
   if (gi_460) {
      if (gi_1024 > 0) li_68 = FALSE;
      if (gi_1020 > 0) li_72 = FALSE;
   }
   if (li_40 == 1 && li_60 && li_56 && li_68 && gi_1320 && li_44 && li_4) {
      if (reversesignals) li_52 = TRUE;
      else li_48 = TRUE;
      if (gi_456) {
         gi_1320 = FALSE;
         gi_1324 = TRUE;
      }
   }
   if (li_40 == 2 && li_64 && li_56 && li_72 && gi_1324 && li_44 && li_4) {
      if (reversesignals) li_48 = TRUE;
      else li_52 = TRUE;
      if (gi_456) {
         gi_1320 = TRUE;
         gi_1324 = FALSE;
      }
   }
   if (li_52) {
      if (oppositeclose) {
         if (gi_304) partialclose(0, 2);
         else close(0);
      }
   }
   if (li_48) {
      if (oppositeclose) {
         if (gi_304) partialclose(1, 2);
         else close(1);
      }
   }
   if (hidetp || hidesl) {
      hideclose(0);
      hideclose(1);
   }
   if (gi_792 && li_0) {
      closetime(0);
      closetime(1);
   }
   if (onecancelother) {
      if (gi_1024 > 0) {
         delete(OP_BUYSTOP);
         delete(OP_BUYLIMIT);
      }
      if (gi_1020 > 0) {
         delete(OP_SELLSTOP);
         delete(OP_SELLLIMIT);
      }
   }
   if (gi_308) {
      partialclose(0, 1);
      partialclose(1, 1);
   }
   if (gi_308) {
      partialclose2(0, 1);
      partialclose2(1, 1);
   }
   if (gi_968 == TRUE && gd_1220 >= (-1.0 * gd_1300)) {
      close(0);
      close(1);
   }
   gi_968 = FALSE;
   if (gi_152 && (!gi_176)) {
      gd_1308 = 0;
      gd_1300 = 0;
      if (OrdersHistoryTotal() > 0) {
         for (g_pos_920 = 0; g_pos_920 <= OrdersHistoryTotal(); g_pos_920++) {
            OrderSelect(g_pos_920, SELECT_BY_POS, MODE_HISTORY);
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
               g_order_profit_1188 = OrderProfit();
               g_order_lots_1180 = OrderLots();
            }
         }
      }
      gd_1196 = 0;
      if (g_order_profit_1188 < 0.0) {
         gi_972 = FALSE;
         if (OrdersHistoryTotal() > 0) {
            for (g_pos_920 = OrdersHistoryTotal(); g_pos_920 >= 0; g_pos_920--) {
               OrderSelect(g_pos_920, SELECT_BY_POS, MODE_HISTORY);
               if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
                  if (OrderProfit() > 0.0) gi_972 = TRUE;
                  if (gi_972 == FALSE) gd_1308 += OrderProfit();
               }
            }
         }
         gd_1196 = g_order_lots_1180 * gd_160;
         if (gi_156 == 1) gi_968 = TRUE;
         gd_1300 = NormalizeDouble(gd_1308 / 100.0 * gd_168, 2);
      } else gd_1196 = lots;
   }
   if (maxspread != 0.0)
      if (Ask - Bid > maxspread * gd_1344 * gd_1328) return (0);
   if (maxtrades < 100)
      if (gi_1016 >= maxtrades) return (0);
   if (mm)
      if (gi_152 == FALSE || (gi_152 && (!gi_176) && g_order_profit_1188 >= 0.0) || (gi_152 && gi_176)) lots = lotsoptimized();
   gd_1148 = lots;
   gd_1156 = lots;
   if (gi_152) {
      if (gi_176) {
         gd_1148 = lots * MathPow(gd_160, gi_1020);
         gd_1156 = lots * MathPow(gd_160, gi_1024);
      } else {
         gd_1148 = gd_1196;
         gd_1156 = gd_1196;
      }
   }
   if (li_48 && g_count_932 < tradesperbar && (!gi_100)) {
      if (oppositedelete) {
         delete(OP_SELLSTOP);
         delete(OP_SELLLIMIT);
      }
      gi_1000 = 0;
      g_count_996 = 0;
      gi_1012 = 0;
      if (stoporders || limitorders)
         if (expiration > 0) gi_1012 = TimeCurrent() + 60 * expiration - 5;
      if (!ecn) {
         if (instantorders && gi_968 == FALSE) {
            while (gi_1000 <= 0 && g_count_996 < gi_940) {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               gi_1000 = open(OP_BUY, gd_1148, Ask, stoploss, takeprofit, gi_1012, Blue);
               if (gi_1000 < 0) {
                  if (gi_88) Print("Error opening BUY order! ", errordescription(GetLastError()));
                  g_count_996++;
               }
            }
         }
         if (instantorders && gi_968 == TRUE) {
            while (gi_1000 <= 0 && g_count_996 < gi_940) {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               gi_1000 = open(OP_BUY, gd_1148, Ask, stoploss, 0, gi_1012, Blue);
               if (gi_1000 < 0) {
                  if (gi_88) Print("Error opening BUY order! ", errordescription(GetLastError()));
                  g_count_996++;
               }
            }
         }
         if (stoporders) {
            if (gi_884 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_BUYSTOP, gd_1148, Ask + gap * gd_1328, stoploss, takeprofit, gi_1012, Blue);
               gi_884 = Time[0];
               g_count_932++;
            }
         }
         if (limitorders) {
            if (gi_888 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_BUYLIMIT, gd_1148, Bid - gap * gd_1328, stoploss, takeprofit, gi_1012, Blue);
               gi_888 = Time[0];
               g_count_932++;
            }
         }
         if (gi_492) {
            if (gi_900 != Time[0]) {
               if (gi_496) delete(OP_BUYSTOP);
               RefreshRates();
               gi_1000 = open(OP_SELLSTOP, gd_1148, Bid - stoploss * gd_1328, gi_500, gi_504, gi_1012, Red);
               gi_900 = Time[0];
            }
         }
      }
      if (ecn) {
         if (instantorders) {
            while (gi_1000 <= 0 && g_count_996 < gi_940) {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               gi_1000 = open(OP_BUY, gd_1148, Ask, 0, 0, gi_1012, Blue);
               if (gi_1000 < 0) {
                  if (gi_88) Print("Error opening BUY order! ", errordescription(GetLastError()));
                  g_count_996++;
               }
            }
         }
         if (stoporders) {
            if (gi_884 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_BUYSTOP, gd_1148, Ask + gap * gd_1328, 0, 0, gi_1012, Blue);
               gi_884 = Time[0];
               g_count_932++;
            }
         }
         if (limitorders) {
            if (gi_888 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_BUYLIMIT, gd_1148, Bid - gap * gd_1328, 0, 0, gi_1012, Blue);
               gi_888 = Time[0];
               g_count_932++;
            }
         }
         if (gi_492) {
            if (gi_900 != Time[0]) {
               if (gi_496) delete(OP_BUYSTOP);
               RefreshRates();
               gi_1000 = open(OP_SELLSTOP, gd_1148, Bid - stoploss * gd_1328, 0, 0, gi_1012, Red);
               gi_900 = Time[0];
            }
         }
      }
      if (instantorders) {
         if (gi_1000 <= 0) {
            if (gi_88) Print("Error Occured : " + errordescription(GetLastError()));
         } else g_count_932++;
      }
      if (gi_92) {
         if (gi_912 != Time[0]) {
            RefreshRates();
            RefreshRates();
            SendMail("[Long Trade]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits));
            gi_912 = Time[0];
         }
      }
   }
   if (li_52 && g_count_936 < tradesperbar && (!gi_96)) {
      if (oppositedelete) {
         delete(OP_BUYSTOP);
         delete(OP_BUYLIMIT);
      }
      gi_1000 = 0;
      g_count_996 = 0;
      gi_1012 = 0;
      if (stoporders || limitorders)
         if (expiration > 0) gi_1012 = TimeCurrent() + 60 * expiration - 5;
      if (!ecn) {
         if (instantorders && gi_968 == FALSE) {
            while (gi_1000 <= 0 && g_count_996 < gi_940) {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               gi_1000 = open(OP_SELL, gd_1156, Bid, stoploss, takeprofit, gi_1012, Red);
               if (gi_1000 < 0) {
                  if (gi_88) Print("Error opening BUY order! ", errordescription(GetLastError()));
                  g_count_996++;
               }
            }
         }
         if (instantorders && gi_968 == TRUE) {
            while (gi_1000 <= 0 && g_count_996 < gi_940) {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               gi_1000 = open(OP_SELL, gd_1156, Bid, stoploss, 0, gi_1012, Red);
               if (gi_1000 < 0) {
                  if (gi_88) Print("Error opening BUY order! ", errordescription(GetLastError()));
                  g_count_996++;
               }
            }
         }
         if (stoporders) {
            if (gi_892 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_SELLSTOP, gd_1156, Bid - gap * gd_1328, stoploss, takeprofit, gi_1012, Red);
               gi_892 = Time[0];
               g_count_936++;
            }
         }
         if (limitorders) {
            if (gi_896 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_SELLLIMIT, gd_1156, Ask + gap * gd_1328, stoploss, takeprofit, gi_1012, Red);
               gi_896 = Time[0];
               g_count_936++;
            }
         }
         if (gi_492) {
            if (gi_904 != Time[0]) {
               if (gi_496) delete(OP_SELLSTOP);
               RefreshRates();
               gi_1000 = open(OP_BUYSTOP, gd_1148, Ask + stoploss * gd_1328, gi_500, gi_504, gi_1012, Red);
               gi_904 = Time[0];
            }
         }
      }
      if (ecn) {
         if (instantorders) {
            while (gi_1000 <= 0 && g_count_996 < gi_940) {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               gi_1000 = open(OP_SELL, gd_1156, Bid, 0, 0, gi_1012, Red);
               if (gi_1000 < 0) {
                  if (gi_88) Print("Error opening BUY order! ", errordescription(GetLastError()));
                  g_count_996++;
               }
            }
         }
         if (stoporders) {
            if (gi_892 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_SELLSTOP, gd_1156, Bid - gap * gd_1328, 0, 0, gi_1012, Red);
               gi_892 = Time[0];
               g_count_936++;
            }
         }
         if (limitorders) {
            if (gi_896 != Time[0]) {
               RefreshRates();
               gi_1000 = open(OP_SELLLIMIT, gd_1156, Ask + gap * gd_1328, 0, 0, gi_1012, Red);
               gi_896 = Time[0];
               g_count_936++;
            }
         }
         if (gi_492) {
            if (gi_904 != Time[0]) {
               if (gi_496) delete(OP_SELLSTOP);
               RefreshRates();
               gi_1000 = open(OP_BUYSTOP, gd_1148, Ask + stoploss * gd_1328, 0, 0, gi_1012, Red);
               gi_904 = Time[0];
            }
         }
      }
      if (instantorders) {
         if (gi_1000 <= 0) {
            if (gi_88) Print("Error Occured : " + errordescription(GetLastError()));
         } else g_count_936++;
      }
      if (gi_92) {
         if (gi_916 != Time[0]) {
            RefreshRates();
            RefreshRates();
            SendMail("[Short Trade]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits));
            gi_916 = Time[0];
         }
      }
   }
   if (ecn) ecnmodify(stoploss, takeprofit);
   if (onetimecalculation) gi_880 = Time[0];
   return (0);
}

int open(int a_cmd_0, double ad_4, double ad_12, double ad_20, double ad_28, int a_datetime_36, color a_color_40) {
   int ticket_44 = 0;
   if (ad_4 < minlot) ad_4 = minlot;
   if (ad_4 > maxlot) ad_4 = maxlot;
   if (a_cmd_0 == OP_BUY || a_cmd_0 == OP_BUYSTOP || a_cmd_0 == OP_BUYLIMIT) {
      if (hidesl == FALSE && ad_20 > 0.0) g_price_1132 = ad_12 - ad_20 * gd_1328;
      else g_price_1132 = 0;
      if (hidetp == FALSE && ad_28 > 0.0) g_price_1140 = ad_12 + ad_28 * gd_1328;
      else g_price_1140 = 0;
   }
   if (a_cmd_0 == OP_SELL || a_cmd_0 == OP_SELLSTOP || a_cmd_0 == OP_SELLLIMIT) {
      if (hidesl == FALSE && ad_20 > 0.0) g_price_1132 = ad_12 + ad_20 * gd_1328;
      else g_price_1132 = 0;
      if (hidetp == FALSE && ad_28 > 0.0) g_price_1140 = ad_12 - ad_28 * gd_1328;
      else g_price_1140 = 0;
   }
   ticket_44 = OrderSend(Symbol(), a_cmd_0, NormalizeDouble(ad_4, lotdigits), NormalizeDouble(ad_12, Digits), gd_432 * gd_1344, g_price_1132, g_price_1140, comment +
      " " + DoubleToStr(magic, 0), magic, a_datetime_36, a_color_40);
   return (ticket_44);
}

double lotsoptimized() {
   double ld_ret_0;
   if (stoploss > 0.0) ld_ret_0 = AccountBalance() * (risk / 100.0) / (stoploss * gd_1328 / MarketInfo(Symbol(), MODE_TICKSIZE) * MarketInfo(Symbol(), MODE_TICKVALUE));
   else ld_ret_0 = NormalizeDouble(AccountBalance() / gi_956 * minlot * risk, lotdigits);
   return (ld_ret_0);
}

/*int checktime() {
   if (TimeCurrent() < gda_1204[TimeYear(TimeCurrent()) - 1999] && TimeCurrent() > gda_1208[TimeYear(TimeCurrent()) - 1999]) gi_1004 = gi_708;
   else gi_1004 = gi_712;
   string ls_0 = Year() + "." + Month() + "." + Day();
   if (gi_716) {
      gi_992 = gi_720 + gi_1004;
      if (gi_992 > 23) gi_992 -= 24;
      if (gi_992 < 10) gs_1108 = "0" + gi_992;
      if (gi_992 > 9) gs_1108 = gi_992;
      if (gi_724 < 10) gs_1116 = "0" + gi_724;
      if (gi_724 > 9) gs_1116 = gi_724;
      g_str2time_864 = StrToTime(ls_0 + " " + gs_1108 + ":" + gs_1116);
   }
   if (gi_728) {
      gi_976 = gi_732 + gi_1004;
      if (gi_976 > 23) gi_976 -= 24;
      if (gi_976 < 10) gs_1044 = "0" + gi_976;
      if (gi_976 > 9) gs_1044 = gi_976;
      if (gi_736 < 10) gs_1060 = "0" + gi_736;
      if (gi_736 > 9) gs_1060 = gi_736;
      g_str2time_852 = StrToTime(ls_0 + " " + gs_1044 + ":" + gs_1060);
      gi_984 = gi_740 + gi_1004;
      if (gi_984 > 23) gi_984 -= 24;
      if (gi_984 < 10) gs_1068 = "0" + gi_984;
      if (gi_984 > 9) gs_1068 = gi_984;
      if (gi_744 < 10) gs_1076 = "0" + gi_744;
      if (gi_744 > 9) gs_1076 = gi_744;
      g_str2time_856 = StrToTime(ls_0 + " " + gs_1068 + ":" + gs_1076);
   }
   if (gi_752) {
      gi_988 = gi_756 + gi_1004;
      if (gi_988 > 23) gi_988 -= 24;
      if (gi_988 < 10) gs_1092 = "0" + gi_988;
      if (gi_988 > 9) gs_1092 = gi_988;
      if (gi_760 < 10) gs_1100 = "0" + gi_760;
      if (gi_760 > 9) gs_1100 = gi_760;
      g_str2time_860 = StrToTime(ls_0 + " " + gs_1092 + ":" + gs_1100);
   }
   if (gi_764) {
      gi_980 = gi_772 + gi_1004;
      if (gi_980 > 23) gi_980 -= 24;
      if (gi_980 < 10) gs_1052 = "0" + gi_980;
      if (gi_980 > 9) gs_1052 = gi_980;
      if (gi_776 < 10) gs_1084 = "0" + gi_776;
      if (gi_776 > 9) gs_1084 = gi_776;
      g_str2time_872 = StrToTime(ls_0 + " " + gs_1052 + ":" + gs_1084);
   }
   if (gi_728)
      if ((gi_976 <= gi_984 && TimeCurrent() < g_str2time_852 || TimeCurrent() > g_str2time_856) || (gi_976 > gi_984 && TimeCurrent() < g_str2time_852 && TimeCurrent() > g_str2time_856)) return (1);
   if (gi_748 == FALSE)
      if (DayOfWeek() == 0) return (1);
   if (gi_752)
      if (DayOfWeek() == 5 && TimeCurrent() > g_str2time_860) return (1);
   if (gi_716)
      if (DayOfWeek() == 1 && TimeCurrent() < g_str2time_864) return (1);
   if (gi_764)
      if (TimeCurrent() > g_str2time_872 - 60 * gi_768 && TimeCurrent() < g_str2time_872 + 60 * gi_780) return (1);
   return (0);
}*/

int count(int a_cmd_0) {
   g_count_928 = 0;
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderType() == a_cmd_0 && OrderMagicNumber() == magic) g_count_928++;
      }
      return (g_count_928);
   }
   return (0);
}

void close(int ai_0) {
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal() - 1; g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (ai_0 == 0 && OrderType() == OP_BUY) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && gi_300 == 0 || (gi_300 > 0 && OrderProfit() / (10.0 * OrderLots()) < (-1 * gi_300))) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), gd_432 * gd_1344);
            }
         }
         if (ai_0 == 1 && OrderType() == OP_SELL) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && gi_300 == 0 || (gi_300 > 0 && OrderProfit() / (10.0 * OrderLots()) < (-1 * gi_300))) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), gd_432 * gd_1344);
            }
         }
         if (ai_0 == 3) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), gd_432 * gd_1344);
            }
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), gd_432 * gd_1344);
            }
         }
      }
   }
}

void partialclose(int ai_0, int ai_4) {
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal() - 1; g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (ai_0 == 0 && OrderType() == OP_BUY) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderLots() >= lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_348 * OrderLots())) || ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots() / 2.0, NormalizeDouble(Bid, Digits), gd_432 * gd_1344);
            }
         }
         if (ai_0 == 1 && OrderType() == OP_SELL) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderLots() >= lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_348 * OrderLots())) || ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots() / 2.0, NormalizeDouble(Ask, Digits), gd_432 * gd_1344);
            }
         }
         if (ai_0 == 3) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY && OrderLots() >= lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_348 * OrderLots())) ||
               ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots() / 2.0, NormalizeDouble(Bid, Digits), gd_432 * gd_1344);
            }
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL && OrderLots() >= lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_348 * OrderLots())) ||
               ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots() / 2.0, NormalizeDouble(Ask, Digits), gd_432 * gd_1344);
            }
         }
      }
   }
}

void partialclose2(int ai_0, int ai_4) {
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal() - 1; g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (ai_0 == 0 && OrderType() == OP_BUY) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderLots() < lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_364 * OrderLots())) || ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), NormalizeDouble(OrderLots() * gd_372, lotdigits), NormalizeDouble(Bid, Digits), gd_432 * gd_1344);
            }
         }
         if (ai_0 == 1 && OrderType() == OP_SELL) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderLots() < lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_364 * OrderLots())) || ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), NormalizeDouble(OrderLots() * gd_372, lotdigits), NormalizeDouble(Ask, Digits), gd_432 * gd_1344);
            }
         }
         if (ai_0 == 3) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY && OrderLots() < lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_364 * OrderLots())) ||
               ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), NormalizeDouble(OrderLots() * gd_372, lotdigits), NormalizeDouble(Bid, Digits), gd_432 * gd_1344);
            }
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL && OrderLots() < lots && (ai_4 == 1 && OrderProfit() >= 10.0 * (gd_364 * OrderLots())) ||
               ai_4 == 2) {
               RefreshRates();
               OrderClose(OrderTicket(), NormalizeDouble(OrderLots() * gd_372, lotdigits), NormalizeDouble(Ask, Digits), gd_432 * gd_1344);
            }
         }
      }
   }
}

void hideclose(int ai_0) {
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal() - 1; g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (ai_0 == 0 && OrderType() == OP_BUY) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && (hidesl && stoploss > 0.0 && NormalizeDouble(OrderClosePrice() - OrderOpenPrice(), Digits) <= (-1.0 * stoploss) * gd_1328 - MarketInfo(Symbol(),
               MODE_SPREAD) * gd_1328) || (hidetp && takeprofit > 0.0 && NormalizeDouble(OrderClosePrice() - OrderOpenPrice(), Digits) >= takeprofit * gd_1328)) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots(), Bid, gd_432 * gd_1344);
            }
         }
         if (ai_0 == 1 && OrderType() == OP_SELL) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && (hidesl && stoploss > 0.0 && NormalizeDouble(OrderOpenPrice() - OrderClosePrice(), Digits) <= (-1.0 * stoploss) * gd_1328 - MarketInfo(Symbol(),
               MODE_SPREAD) * gd_1328) || (hidetp && takeprofit > 0.0 && NormalizeDouble(OrderOpenPrice() - OrderClosePrice(), Digits) >= takeprofit * gd_1328)) {
               RefreshRates();
               OrderClose(OrderTicket(), OrderLots(), Ask, gd_432 * gd_1344);
            }
         }
      }
   }
}

void closetime(int ai_0) {
   gd_1276 = 0;
   gi_1008 = 0;
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (ai_0 == 0 && OrderType() == OP_BUY) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
               gd_1276 = NormalizeDouble(OrderClosePrice() - OrderOpenPrice(), Digits);
               gi_1008 = TimeCurrent() - OrderOpenTime();
               if ((gd_1276 >= gi_800 * gd_1328 && gi_1008 > 60 * gi_796 && gi_1008 < 60 * gi_804) || (gd_1276 >= gi_808 * gd_1328 && gi_1008 > 60 * gi_804 && gi_1008 < 60 * gi_812) ||
                  (gd_1276 >= gi_816 * gd_1328 && gi_1008 > 60 * gi_812 && gi_1008 < 60 * gi_820) || (gd_1276 >= gi_824 * gd_1328 && gi_1008 > 60 * gi_820 && gi_1008 < 60 * gi_828) ||
                  (gd_1276 >= gi_832 * gd_1328 && gi_1008 > 60 * gi_828 && gi_1008 < 60 * gi_836) || (gd_1276 >= gi_840 * gd_1328 && gi_1008 > 60 * gi_836 && gi_1008 < 60 * gi_844) ||
                  (gd_1276 >= gi_848 * gd_1328 && gi_1008 > 60 * gi_844)) {
                  RefreshRates();
                  OrderClose(OrderTicket(), OrderLots(), Bid, gd_432 * gd_1344);
               }
            }
         }
         if (ai_0 == 1 && OrderType() == OP_SELL) {
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
               gd_1276 = NormalizeDouble(OrderClosePrice() - OrderOpenPrice(), Digits);
               gi_1008 = TimeCurrent() - OrderOpenTime();
               if ((gd_1276 >= gi_800 * gd_1328 && gi_1008 > 60 * gi_796 && gi_1008 < 60 * gi_804) || (gd_1276 >= gi_808 * gd_1328 && gi_1008 > 60 * gi_804 && gi_1008 < 60 * gi_812) ||
                  (gd_1276 >= gi_816 * gd_1328 && gi_1008 > 60 * gi_812 && gi_1008 < 60 * gi_820) || (gd_1276 >= gi_824 * gd_1328 && gi_1008 > 60 * gi_820 && gi_1008 < 60 * gi_828) ||
                  (gd_1276 >= gi_832 * gd_1328 && gi_1008 > 60 * gi_828 && gi_1008 < 60 * gi_836) || (gd_1276 >= gi_840 * gd_1328 && gi_1008 > 60 * gi_836 && gi_1008 < 60 * gi_844) ||
                  (gd_1276 >= gi_848 * gd_1328 && gi_1008 > 60 * gi_844)) {
                  RefreshRates();
                  OrderClose(OrderTicket(), OrderLots(), Ask, gd_432 * gd_1344);
               }
            }
         }
      }
   }
}

void delete(int a_cmd_0) {
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (a_cmd_0 != 6)
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == a_cmd_0) OrderDelete(OrderTicket());
         if (a_cmd_0 == 6)
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP || OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());
      }
   }
}

void movebreakeven(double ad_0, double ad_8) {
   RefreshRates();
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
            if (OrderType() == OP_BUY) {
               if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) < NormalizeDouble(ad_0 * gd_1328, Digits)) continue;
               if (!(NormalizeDouble(OrderStopLoss() - OrderOpenPrice(), Digits) < NormalizeDouble(ad_8 * gd_1328, Digits) || OrderStopLoss() == 0.0)) continue;
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() + ad_8 * gd_1328, Digits), OrderTakeProfit(), 0, Blue);
               return;
            }
            if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(ad_0 * gd_1328, Digits)) {
               if (NormalizeDouble(OrderOpenPrice() - OrderStopLoss(), Digits) < NormalizeDouble(ad_8 * gd_1328, Digits) || OrderStopLoss() == 0.0) {
                  OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() - ad_8 * gd_1328, Digits), OrderTakeProfit(), 0, Red);
                  return;
               }
            }
         }
      }
   }
}

void movetrailingstop(double ad_0, double ad_8) {
   RefreshRates();
   if (OrdersTotal() > 0) {
      for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
         OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
            if (OrderType() == OP_BUY) {
               if (!(NormalizeDouble(Ask, Digits) > NormalizeDouble(OrderOpenPrice() + ad_0 * gd_1328, Digits) && NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(Bid - (ad_8 +
                  trailingstep) * gd_1328, Digits))) continue;
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - ad_8 * gd_1328, Digits), OrderTakeProfit(), 0, Blue);
               return;
            }
            if (NormalizeDouble(Bid, Digits) < NormalizeDouble(OrderOpenPrice() - ad_0 * gd_1328, Digits) && NormalizeDouble(OrderStopLoss(), Digits) > NormalizeDouble(Ask + (ad_8 +
               trailingstep) * gd_1328, Digits) || OrderStopLoss() == 0.0) {
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + ad_8 * gd_1328, Digits), OrderTakeProfit(), 0, Red);
               return;
            }
         }
      }
   }
}

void movetrailingprofit(double ad_0, double ad_8) {
   RefreshRates();
   for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
      if (OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
            if (OrderType() == OP_BUY) {
               if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) <= NormalizeDouble((-1.0 * ad_0) * gd_1328, Digits))
                  if (NormalizeDouble(OrderTakeProfit(), Digits) > NormalizeDouble(Bid + (ad_8 + trailingstep) * gd_1328, Digits) || NormalizeDouble(OrderTakeProfit(), Digits) == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(Bid + ad_8 * gd_1328, Digits), 0, Blue);
            }
            if (OrderType() == OP_SELL) {
               if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) <= NormalizeDouble((-1.0 * ad_0) * gd_1328, Digits))
                  if (NormalizeDouble(OrderTakeProfit(), Digits) < NormalizeDouble(Ask - (ad_8 + trailingstep) * gd_1328, Digits)) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(Ask - ad_8 * gd_1328, Digits), 0, Red);
            }
         }
      }
   }
}

void ecnmodify(double ad_0, double ad_8) {
   for (g_pos_920 = OrdersTotal(); g_pos_920 >= 0; g_pos_920--) {
      OrderSelect(g_pos_920, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) {
         if (OrderType() == OP_BUY) {
            if (OrderStopLoss() == 0.0 && ad_0 > 0.0 && ad_8 == 0.0) {
               RefreshRates();
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask - ad_0 * gd_1328, Digits), OrderTakeProfit(), 0, Red);
            }
            if (OrderTakeProfit() == 0.0 && ad_0 == 0.0 && ad_8 > 0.0) {
               RefreshRates();
               OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(Ask + ad_8 * gd_1328, Digits), 0, Red);
            }
            if (OrderTakeProfit() == 0.0 && OrderStopLoss() == 0.0 && ad_0 > 0.0 && ad_8 > 0.0) {
               RefreshRates();
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask - ad_0 * gd_1328, Digits), NormalizeDouble(Ask + ad_8 * gd_1328, Digits), 0, Red);
            }
         }
         if (OrderType() == OP_SELL) {
            if (OrderStopLoss() == 0.0 && ad_0 > 0.0 && ad_8 == 0.0) {
               RefreshRates();
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid + ad_0 * gd_1328, Digits), OrderTakeProfit(), 0, Red);
            }
            if (OrderTakeProfit() == 0.0 && ad_0 == 0.0 && ad_8 > 0.0) {
               RefreshRates();
               OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(Bid - ad_8 * gd_1328, Digits), 0, Red);
            }
            if (OrderTakeProfit() == 0.0 && OrderStopLoss() == 0.0 && ad_0 > 0.0 && ad_8 > 0.0) {
               RefreshRates();
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid + ad_0 * gd_1328, Digits), NormalizeDouble(Bid - ad_8 * gd_1328, Digits), 0, Red);
            }
         }
      }
   }
}

string errordescription(int ai_0) {
   string ls_ret_4;
   switch (ai_0) {
   case 0:
   case 1:
      ls_ret_4 = "no error";
      break;
   case 2:
      ls_ret_4 = "common error";
      break;
   case 3:
      ls_ret_4 = "invalid trade parameters";
      break;
   case 4:
      ls_ret_4 = "trade server is busy";
      break;
   case 5:
      ls_ret_4 = "old version of the client terminal";
      break;
   case 6:
      ls_ret_4 = "no connection with trade server";
      break;
   case 7:
      ls_ret_4 = "not enough rights";
      break;
   case 8:
      ls_ret_4 = "too frequent requests";
      break;
   case 9:
      ls_ret_4 = "malfunctional trade operation";
      break;
   case 64:
      ls_ret_4 = "account disabled";
      break;
   case 65:
      ls_ret_4 = "invalid account";
      break;
   case 128:
      ls_ret_4 = "trade timeout";
      break;
   case 129:
      ls_ret_4 = "invalid price";
      break;
   case 130:
      ls_ret_4 = "invalid stops";
      break;
   case 131:
      ls_ret_4 = "invalid trade volume";
      break;
   case 132:
      ls_ret_4 = "market is closed";
      break;
   case 133:
      ls_ret_4 = "trade is disabled";
      break;
   case 134:
      ls_ret_4 = "not enough money";
      break;
   case 135:
      ls_ret_4 = "price changed";
      break;
   case 136:
      ls_ret_4 = "off quotes";
      break;
   case 137:
      ls_ret_4 = "broker is busy";
      break;
   case 138:
      ls_ret_4 = "requote";
      break;
   case 139:
      ls_ret_4 = "order is locked";
      break;
   case 140:
      ls_ret_4 = "long positions only allowed";
      break;
   case 141:
      ls_ret_4 = "too many requests";
      break;
   case 145:
      ls_ret_4 = "modification denied because order too close to market";
      break;
   case 146:
      ls_ret_4 = "trade context is busy";
      break;
   case 4000:
      ls_ret_4 = "no error";
      break;
   case 4001:
      ls_ret_4 = "wrong function pointer";
      break;
   case 4002:
      ls_ret_4 = "array index is out of range";
      break;
   case 4003:
      ls_ret_4 = "no memory for function call stack";
      break;
   case 4004:
      ls_ret_4 = "recursive stack overflow";
      break;
   case 4005:
      ls_ret_4 = "not enough stack for parameter";
      break;
   case 4006:
      ls_ret_4 = "no memory for parameter string";
      break;
   case 4007:
      ls_ret_4 = "no memory for temp string";
      break;
   case 4008:
      ls_ret_4 = "not initialized string";
      break;
   case 4009:
      ls_ret_4 = "not initialized string in array";
      break;
   case 4010:
      ls_ret_4 = "no memory for array\' string";
      break;
   case 4011:
      ls_ret_4 = "too long string";
      break;
   case 4012:
      ls_ret_4 = "remainder from zero divide";
      break;
   case 4013:
      ls_ret_4 = "zero divide";
      break;
   case 4014:
      ls_ret_4 = "unknown command";
      break;
   case 4015:
      ls_ret_4 = "wrong jump (never generated error)";
      break;
   case 4016:
      ls_ret_4 = "not initialized array";
      break;
   case 4017:
      ls_ret_4 = "dll calls are not allowed";
      break;
   case 4018:
      ls_ret_4 = "cannot load library";
      break;
   case 4019:
      ls_ret_4 = "cannot call function";
      break;
   case 4020:
      ls_ret_4 = "expert function calls are not allowed";
      break;
   case 4021:
      ls_ret_4 = "not enough memory for temp string returned from function";
      break;
   case 4022:
      ls_ret_4 = "system is busy (never generated error)";
      break;
   case 4050:
      ls_ret_4 = "invalid function parameters count";
      break;
   case 4051:
      ls_ret_4 = "invalid function parameter value";
      break;
   case 4052:
      ls_ret_4 = "string function internal error";
      break;
   case 4053:
      ls_ret_4 = "some array error";
      break;
   case 4054:
      ls_ret_4 = "incorrect series array using";
      break;
   case 4055:
      ls_ret_4 = "custom indicator error";
      break;
   case 4056:
      ls_ret_4 = "arrays are incompatible";
      break;
   case 4057:
      ls_ret_4 = "global variables processing error";
      break;
   case 4058:
      ls_ret_4 = "global variable not found";
      break;
   case 4059:
      ls_ret_4 = "function is not allowed in testing mode";
      break;
   case 4060:
      ls_ret_4 = "function is not confirmed";
      break;
   case 4061:
      ls_ret_4 = "send mail error";
      break;
   case 4062:
      ls_ret_4 = "string parameter expected";
      break;
   case 4063:
      ls_ret_4 = "integer parameter expected";
      break;
   case 4064:
      ls_ret_4 = "double parameter expected";
      break;
   case 4065:
      ls_ret_4 = "array as parameter expected";
      break;
   case 4066:
      ls_ret_4 = "requested history data in update state";
      break;
   case 4099:
      ls_ret_4 = "end of file";
      break;
   case 4100:
      ls_ret_4 = "some file error";
      break;
   case 4101:
      ls_ret_4 = "wrong file name";
      break;
   case 4102:
      ls_ret_4 = "too many opened files";
      break;
   case 4103:
      ls_ret_4 = "cannot open file";
      break;
   case 4104:
      ls_ret_4 = "incompatible access to a file";
      break;
   case 4105:
      ls_ret_4 = "no order selected";
      break;
   case 4106:
      ls_ret_4 = "unknown symbol";
      break;
   case 4107:
      ls_ret_4 = "invalid price parameter for trade function";
      break;
   case 4108:
      ls_ret_4 = "invalid ticket";
      break;
   case 4109:
      ls_ret_4 = "trade is not allowed";
      break;
   case 4110:
      ls_ret_4 = "longs are not allowed";
      break;
   case 4111:
      ls_ret_4 = "shorts are not allowed";
      break;
   case 4200:
      ls_ret_4 = "object is already exist";
      break;
   case 4201:
      ls_ret_4 = "unknown object property";
      break;
   case 4202:
      ls_ret_4 = "object is not exist";
      break;
   case 4203:
      ls_ret_4 = "unknown object type";
      break;
   case 4204:
      ls_ret_4 = "no object name";
      break;
   case 4205:
      ls_ret_4 = "object coordinates error";
      break;
   case 4206:
      ls_ret_4 = "no specified subwindow";
      break;
   default:
      ls_ret_4 = "unknown error";
   }
   return (ls_ret_4);
}

Recommend