Navigation´╝ÜHome > Content >

ExpertAdvisor_v0.1.mq4

Time: 2017-01-16 | Download file:ExpertAdvisor_v0.1.mq4

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

extern bool Conservative = TRUE;
extern int MagicNumber = 5485669;
extern string CustomOrderComment = "SuperScalper EA";
extern string Triggers = "----------EA Triggers Settings-----------";
extern bool UseStandardEntry = TRUE;
extern string Tip_BBandClearanceLong = "Set automatically if left at 999, in points";
extern int BBandClearanceLong = 999;
extern string Tip_BBandClearanceShort = "Set automatically if left at 999, in points";
extern int BBandClearanceShort = 999;
extern bool UseBClearance = TRUE;
int gi_148 = 20;
extern string Tip_BClearance = "Set automatically if left at 999, in points";
extern int BClearance = 999;
extern bool UseCBand = FALSE;
extern string Tip_CBandClearance = "Set automatically if left at 999, in points";
extern int CBandClearance = 999;
int gi_180 = 60;
int gi_184 = 100;
int gi_188 = 300;
extern string Tip_MaxAvSpread = "Set automatically if left at 999, in points";
extern int MaxAvSpread = 999;


extern string Sep0 = "=============================";
extern string Sep1 = "New Edu Options";
extern string Sep2 = "=============================";
extern string Tip_BB1Period = "Set automatically if left at 999, in points";
extern int BB1Period = 999;
bool bb1 = TRUE;
extern string Tip_BB2Period = "Set automatically if left at 999, in points";
extern int BB2Period = 999;
bool bb2 = TRUE;
extern string Tip_BB3Period = "Set automatically if left at 999, in points";
extern int BB3Period = 999;
bool bb3 = TRUE;
extern string Tip_MaxSlippage = "Set automatically if left at 999, in points";
extern int MaxSlippage = 999;
bool maxslip = TRUE;
extern string Tip_PendingStopClearanceLong = "Set automatically if left at 999, in points";
extern int PendingStopClearanceLong = 999;
bool pscl = TRUE;
extern string Tip_PendingStopClearanceShort = "Set automatically if left at 999, in points";
extern int PendingStopClearanceShort = 999;
bool pscs = TRUE;
extern string Tip_Slippage = "Set automatically if left at 999, in points";
extern int Slippage = 999;
bool slip = TRUE;
extern string Tip_StopLossMoveLong = "Set automatically if left at 999, in points";
extern int StopLossMoveLong = 999;
bool slml = TRUE;
extern string Tip_StopLossMoveShort = "Set automatically if left at 999, in points";
extern int StopLossMoveShort = 999;
bool slms = TRUE;
extern string Tip_StopLossTrailClearanceLong = "Set automatically if left at 999, in points";
extern int StopLossTrailClearanceLong = 999;
bool sltcl = TRUE;
extern string Tip_StopLossTrailClearanceShort = "Set automatically if left at 999, in points";
extern int StopLossTrailClearanceShort = 999;
bool sltcs = TRUE;
extern string Tip_StopLossTrailLong = "Set automatically if left at 999, in points";
extern int StopLossTrailLong = 999;
bool sltl = TRUE;
extern string Tip_StopLossTrailShort = "Set automatically if left at 999, in points";
extern int StopLossTrailShort = 999;
bool slts = TRUE;
extern string Tip_TakeProfit = "Set automatically if left at 999, in points";
extern int TakeProfit = 999;
bool tp = TRUE;



extern string Sep3 = "=============================";
extern string Sep4 = "Money Management";
extern string Sep5 = "=============================";
extern bool MoneyManagement = TRUE;
extern double RiskPercentage = 0.5;
extern double MaxLots = 10.0;
extern double FixedLots = 0.1;
extern string Sep6 = "=============================";
extern string Sep7 = "Trade Zone Functionality";
extern string Sep8 = "=============================";
extern bool UseTimeZone = FALSE;
extern string TZ1StartTime = "00:00";
extern string TZ1EndTime = "23:59";
extern string TZ2StartTime = "00:00";
extern string TZ2EndTime = "23:59";
extern bool UseFridayClose = TRUE;
extern string FridayClose = "17:30";
extern bool UseMaxTradesFilter = TRUE;
extern string Tip_MaxTrades = "Set automatically if left at 999";
extern int MaxTrades = 999;
extern int MaxTradesSeconds = 60;
extern int StopLevelBuffer = 0;
extern bool UseMaxDailyLoss = TRUE;
extern double MaxDailyLossPercent = 1.0;
extern bool UseAllPairs = TRUE;
extern double MaxPercentAllPairs = 2.0;
extern int MaxPercentPairFilter = 2;
extern bool Verbose = FALSE;
extern int RetryIntervalMilliseconds = 20;


bool gi_388 = FALSE;
int gi_392 = 111;
int gi_396 = 0;
bool gi_400 = FALSE;
bool gi_404 = TRUE;
bool gi_408 = FALSE;
int gi_412 = 100;
string gs_420 = "";
double gd_428 = 1.0;
int gi_444 = 600;
int gi_448 = 0;
int gi_452 = 2;
int gi_468 = PRICE_OPEN;
int gi_476 = 5;
int gi_480 = 10;
bool gi_512 = TRUE;
double gd_516 = 1.5;
bool gi_524 = TRUE;
double gd_528 = 1.5;
int gi_536;
int gi_540 = 5;
bool gi_544 = TRUE;
bool gi_548 = TRUE;
bool gi_552 = TRUE;
bool gi_556 = TRUE;
bool gi_560 = TRUE;
bool gi_564 = TRUE;
bool gi_568 = TRUE;
bool gi_572 = TRUE;
bool gi_576 = TRUE;
string gs_580 = "";
bool gi_588 = FALSE;
double gd_592 = 0.0;
double gd_600 = 0.0;
double gd_608 = 0.0;
double gd_616 = 0.0;
double gd_624 = 0.0;
double gd_632 = 0.0;
double gd_640 = 0.0;
double gd_648 = 0.0;
double gd_656 = 0.0;
double gd_664;
double gd_672;
int gi_680 = 9999;
int gi_684 = 9999;
int gi_688 = 9999;
double gd_692;
double gd_700 = 0.0;
int gi_708 = 0;
string gs_712;
double gda_720[100];
int gi_724 = 0;
double gd_728;
double gd_736;
bool gi_744;
double gd_748;
double gd_756;
double gd_764;
double gd_772;
double gd_780;
double gd_788;
double gd_796;
double gd_804;
double gd_812;
string gs_820;
string gs_828;
bool gi_836 = FALSE;
int gi_840 = 0;
double gd_844 = 0.0;
int gi_852;
int gi_856;
int gi_860;
double gda_864[];
double gda_868[];
int gia_872[];
int gia_876[];
int gi_880;
int gi_884;
string gs_888 = "";
int gi_896 = 0;
int gi_900 = 0;
int gi_904 = 999;
string gs_908;
string gs_916 = "0123456789ABCDEF";
int gi_924;
int gi_928;
int gi_932;
double gd_936;
double gd_944;
int gi_952 = 0;
int gi_956 = 0;
int gi_960 = 0;
int gi_964 = 0;
double gd_968;

int init() {
   ArrayResize(gda_864, gi_184);
   ArrayResize(gda_868, gi_184);
   ArrayResize(gia_872, gi_184);
   ArrayResize(gia_876, gi_184);
   ArrayInitialize(gia_872, 0);
   ArrayInitialize(gia_876, 0);
   ArrayInitialize(gda_864, Bid);
   ArrayInitialize(gda_868, 0);
   gd_592 = 0;
   gd_600 = 0;
   gd_608 = 0;
   gd_616 = 0;
   gd_624 = 0;
   gd_632 = 0;
   gd_640 = 0;
   gd_648 = 0;
   gd_656 = 0;
   gs_580 = "";
   gs_820 = "false";
   if (Conservative) gs_820 = "true";
   gs_828 = "Using fixed lots";
   if (MoneyManagement) gs_828 = StringConcatenate(DoubleToStr(RiskPercentage, 2), " %");
   Comment("\nWelcome to the NMi Super Scalper, please wait while we do some initial checks...");
   Sleep(3500);
   if (MaxAvSpread != 999) gi_548 = FALSE;
   if (BClearance != 999) gi_560 = FALSE;
   if (MaxTrades != 999) gi_556 = FALSE;
   if (BBandClearanceLong != 999) gi_564 = FALSE;
   if (BBandClearanceShort != 999) gi_568 = FALSE;
   if (CBandClearance != 999) gi_572 = FALSE;
   
   if (BB1Period != 999) bb1 = FALSE;
   if (BB2Period != 999) bb2 = FALSE;
   if (BB3Period != 999) bb3 = FALSE;
   if (MaxSlippage != 999) maxslip = FALSE;
   if (PendingStopClearanceLong != 999) pscl = FALSE;
   if (PendingStopClearanceShort != 999) pscs = FALSE;
   if (Slippage != 999) slip = FALSE;
   if (StopLossMoveLong != 999) slml = FALSE;
   if (StopLossMoveShort != 999) slms = FALSE;
   if (StopLossTrailClearanceLong != 999) sltcl = FALSE;
   if (StopLossTrailClearanceShort != 999) sltcs = FALSE;
   if (StopLossTrailLong != 999) sltl = FALSE;
   if (StopLossTrailShort != 999) slts = FALSE;
   if (TakeProfit != 999) tp = FALSE;

   if (MaxLots > MarketInfo(Symbol(), MODE_MAXLOT)) MaxLots = MarketInfo(Symbol(), MODE_MAXLOT);
   HideTestIndicators(TRUE);
   Print("########################################################################");
   gi_576 = gi_544;
   if (gi_544) f0_38();
   else f0_33();
   for (int li_0 = 0; li_0 < gi_536; li_0++) gda_720[li_0] = -1.0;
   if (Verbose) {
      Print("----------------------");
      Print("Printing debug info...");
      Print("Symbol: " + Symbol());
      Print("Broker stoplevel: " + MarketInfo(Symbol(), MODE_STOPLEVEL));
      Print("Point value: " + Point);
      Print("Digits: " + Digits);
      Print("Spread: " + MarketInfo(Symbol(), MODE_SPREAD));
      Print("Ticksize: " + MarketInfo(Symbol(), MODE_TICKSIZE));
      Print("Tickvalue: " + MarketInfo(Symbol(), MODE_TICKVALUE));
      Print("Market open: " + IsTradeAllowed());
      Print("MaxAvSpread: " + MaxAvSpread);
      if (!gi_544) {
         Print("Delay_Seconds: " + gi_188);
         Print("PreTrailingLong: " + gi_512);
         Print("PreTrailFactorLong: " + gd_516);
         Print("PreTrailingShort: " + gi_524);
         Print("PreTrailFactorShort: " + gd_528);
         Print("StopLevelBuffer: " + StopLevelBuffer);
         Print("UseSpikeSpreadFilter: " + gi_404);
         Print("MaxCuSpreadSecs: " + gi_476);
         Print("MaxCuSpreadDelta: " + gi_480);
         Print("MaxAvSpread: " + MaxAvSpread);
         Print("MaxSlippage: " + MaxSlippage);
         Print("UseTimeZone: " + UseTimeZone);
         Print("UseFridayClose: " + UseFridayClose);
         Print("FridayClose: " + FridayClose);
         Print("NoFridayTrade: " + gi_400);
         Print("TZOpen_Sec: " + gi_444);
         Print("SpreadHistTicks: " + gi_536);
         Print("UseMaxTradesFilter: " + UseMaxTradesFilter);
         Print("MaxTrades: " + MaxTrades);
         Print("MaxTradesSeconds: " + MaxTradesSeconds);
         Print("UseMaxDailyLoss: " + UseMaxDailyLoss);
         Print("MaxDailyLossPercent: " + MaxDailyLossPercent);
         Print("UseAllPairs: " + UseAllPairs);
         Print("MaxPercentAllPairs: " + MaxPercentAllPairs);
         Print("MaxPercentPairFilter: " + MaxPercentPairFilter);
         Print("UseSpikeSpeedFilter: " + gi_408);
         Print("MaxSpikeSpeed: " + gi_412);
         Print("MaxRetryPerTick: " + gi_540);
         Print("RetryIntervalMilliseconds: " + RetryIntervalMilliseconds);
         Print("Verbose: " + Verbose);
         Print("ProductionBuild: " + gi_544);
         Print("UsePlanBEntry: " + gi_388);
         Print("PlanBMagicNumber: " + gi_392);
         Print("PlanBOffSet: " + gi_396);
         Print("BB1Period: " + BB1Period);
         Print("BB2Period: " + BB2Period);
         Print("BB3Period: " + BB3Period);
         Print("BBDeviation: " + gi_452);
         Print("BBMethod: " + gi_468);
         Print("BBandClearanceLong: " + BBandClearanceLong);
         Print("BBandClearanceShort: " + BBandClearanceShort);
         Print("TakeProfit: " + TakeProfit);
         Print("Slippage: " + Slippage);
         Print("GapFilter: " + gd_428);
         Print("MinTriggerOne: " + gi_148);
         Print("Trigger_One_Seconds: " + gi_180);
         Print("TicksBufferSize: " + gi_184);
         Print("BClearance: " + BClearance);
         Print("CBandClearance: " + CBandClearance);
         Print("MaxTrades: " + MaxTrades);
         Print("RiskPercentage by MM(without Spread and Commissions): " + RiskPercentage);
         Print("PendingStopClearanceLong: " + PendingStopClearanceLong);
         Print("PendingStopClearanceShort: " + PendingStopClearanceShort);
         Print("StopLossMoveLong: " + StopLossMoveLong);
         Print("StopLossMoveShort: " + StopLossMoveShort);
         Print("StopLossTrailClearanceLong: " + StopLossTrailClearanceLong);
         Print("StopLossTrailClearanceShort: " + StopLossTrailClearanceShort);
         Print("StopLossTrailLong: " + StopLossTrailLong);
         Print("StopLossTrailShort: " + StopLossTrailShort);
      }
      Print("End of debug info...");
      Print("----------------------");
   }
   gd_672 = Bid;
   gd_728 = Bid;
   gd_736 = Ask;
   gd_804 += StopLevelBuffer * Point;
   if (Period() != PERIOD_M1) gs_580 = "This EA only runs on M1!";
   if (Digits != 3 && Digits != 5) gs_580 = "This EA only runs on 5-digit brokers!";
   if (MaxAvSpread < 6 && MaxAvSpread > 0) gs_580 = "You set your MaxAvSpread to less than 6, please note this setting is in POINTS";
   if (gs_580 != "") {
      gi_576 = TRUE;
      Print("\nError: ", gs_580);
   } else Comment("\nInitialized, waiting for first tick...");
   gs_712 = StringConcatenate(WindowExpertName(), "_", AccountNumber(), "_", Symbol(), "_", MagicNumber, "_");
   if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.01) gi_724 = 2;
   else gi_724 = 1;
   gi_860 = TimeCurrent();
   return (0);
}

int deinit() {
   Print("########################################################################");
   Comment("");
   return (0);
}

int start() {
   double ld_16;
   bool li_28;
   double ld_32;
   double ld_40;
   double ld_48;
   double ld_56;
   double ld_64;
   double ld_72;
   double ld_80;
   double ld_88;
   double ld_96;
   double ld_104;
   for (int li_0 = gi_184 - 1; li_0 > 0; li_0--) {
      gda_864[li_0] = gda_864[li_0 - 1];
      gia_872[li_0] = gia_872[li_0 - 1];
   }
   gda_864[0] = Bid;
   gia_872[0] = TimeCurrent();
   for (int li_4 = gi_184 - 1; li_4 > 0; li_4--) {
      gda_868[li_4] = gda_868[li_4 - 1];
      gia_876[li_4] = gia_876[li_4 - 1];
   }
   gda_868[0] = Ask;
   gia_876[0] = TimeCurrent();
   bool li_8 = FALSE;
   bool li_12 = FALSE;
   if (UseAllPairs && (!IsTesting())) {
      ld_16 = GlobalVariableGet(MagicNumber + "MaxLoss" + TimeToStr(TimeCurrent(), TIME_DATE));
      if (f0_14() && GlobalVariableGet(MagicNumber + Symbol() + TimeToStr(TimeCurrent(), TIME_DATE)) == 0.0) {
         GlobalVariableSet(MagicNumber + "MaxLoss" + TimeToStr(TimeCurrent(), TIME_DATE), ld_16 + 1.0);
         GlobalVariableSet(MagicNumber + Symbol() + TimeToStr(TimeCurrent(), TIME_DATE), 1);
      }
   }
   if (gi_840 != 0 && Verbose) f0_46(gi_840);
   if (!gi_576) {
      if (Seconds() == 15 || Seconds() == 45) {
         f0_25();
         f0_47();
      }
      if (gi_544) {
         if (!IsTesting()) {
            if (gi_884 != Day()) {
               gi_884 = Day();
               MathSrand(TimeLocal());
               gi_880 = MathRand();
            }
            if (iVolume(Symbol(), PERIOD_D1, 0) == gi_880) f0_38();
         }
      }
      f0_45();
      gi_744 = TRUE;
      for (int li_24 = 0; gi_744 && li_24 < gi_540; li_24++) {
         gd_728 = Bid;
         gd_736 = Ask;
         gi_744 = FALSE;
         li_28 = f0_18();
         if (!li_28) f0_8();
         if (gi_588) {
            f0_52();
            f0_51();
            f0_53(gi_708);
            f0_19();
         } else {
            if ((!gi_576) && f0_3() && (!f0_27()) && (!f0_48()) && f0_37() && li_28 && f0_12() && f0_6() && (!f0_26()) && f0_9() && GlobalVariableGet(MagicNumber + "MaxLoss" +
               TimeToStr(TimeCurrent(), TIME_DATE)) < MaxPercentPairFilter) {
               ld_32 = iBands(NULL, 0, BB1Period, gi_452, 0, gi_468, MODE_UPPER, 0);
               ld_40 = iBands(NULL, 0, BB2Period, gi_452, 0, gi_468, MODE_UPPER, 0);
               ld_48 = iBands(NULL, 0, BB3Period, gi_452, 0, gi_468, MODE_UPPER, 0);
               ld_56 = f0_36(-1);
               ld_64 = iClose(Symbol(), Period(), 1);
               ld_72 = iOpen(Symbol(), Period(), 1);
               if ((Ask - gda_868[ArrayMinimum(gda_868, f0_24(gia_876, TimeCurrent() - gi_180), 0)]) / Point >= CBandClearance + ld_56 * gd_428 && CBandClearance != 0 && gi_180 != 0) li_8 = TRUE;
               if ((UseCBand && li_8) || (gd_736 > ld_32 + BBandClearanceShort * Point + ld_56 * gd_428 && gd_736 > ld_40 + BBandClearanceShort * Point + ld_56 * gd_428 && gd_736 > ld_48 +
                  BBandClearanceShort * Point + ld_56 * gd_428 && UseStandardEntry) || (UseBClearance && (ld_64 - ld_72) / Point >= gi_148 + ld_56 * gd_428 && gd_728 >= ld_64 + BClearance * Point + ld_56 * gd_428)) {
                  gi_588 = f0_2(0, OP_SELLSTOP, MagicNumber);
                  if (gi_588) return (0);
               }
               ld_80 = iBands(NULL, 0, BB1Period, gi_452, 0, gi_468, MODE_LOWER, 0);
               ld_88 = iBands(NULL, 0, BB2Period, gi_452, 0, gi_468, MODE_LOWER, 0);
               ld_96 = iBands(NULL, 0, BB3Period, gi_452, 0, gi_468, MODE_LOWER, 0);
               ld_104 = f0_36(1);
               if ((gda_864[ArrayMaximum(gda_864, f0_24(gia_872, TimeCurrent() - gi_180), 0)] - Bid) / Point >= CBandClearance + ld_104 * gd_428 && CBandClearance != 0 && gi_180 != 0) li_12 = TRUE;
               if ((UseCBand && li_12) || (gd_728 < ld_80 - BBandClearanceLong * Point - ld_104 * gd_428 && gd_728 < ld_88 - BBandClearanceLong * Point - ld_104 * gd_428 && gd_728 < ld_96 - BBandClearanceLong * Point - ld_104 * gd_428 &&
                  UseStandardEntry) || (UseBClearance && (ld_72 - ld_64) / Point >= gi_148 + ld_56 * gd_428 && gd_728 <= ld_64 - BClearance * Point - ld_56 * gd_428)) {
                  gi_588 = f0_2(0, OP_BUYSTOP, MagicNumber);
                  if (gi_588) return (0);
               }
            }
         }
         gd_672 = gd_728;
      }
      if (f0_10() == 0) gi_588 = FALSE;
   }
   if (gi_388) f0_34();
   f0_21();
   f0_29();
   f0_11();
   return (0);
}

int f0_22(int ai_0, int ai_4 = 0, int ai_8 = 0, int ai_12 = -1) {
   bool li_16;
   if (ai_12 < 0) {
      switch (ai_4) {
      case MODE_TRADES:
         ai_12 = OrdersTotal();
         break;
      case MODE_HISTORY:
         ai_12 = OrdersHistoryTotal();
      }
   }
   for (int li_24 = ai_8; li_24 < ai_12; li_24++) {
      if (!(OrderSelect(li_24, SELECT_BY_POS, ai_4))) break;
      if (OrderSymbol() == Symbol() || gi_836 && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == gi_392) {
         if (ai_4 == MODE_TRADES) {
            gi_840 = OrderTicket();
            gd_844 = OrderOpenPrice();
         }
         switch (ai_0) {
         case 1:
            li_16 = f0_44();
            break;
         case 2:
            li_16 = f0_15();
            break;
         case 3:
            li_16 = f0_7();
            break;
         case 4:
            li_16 = f0_1();
            break;
         case 5:
            li_16 = f0_23();
            break;
         case 6:
            li_16 = f0_41();
            break;
         case 7:
            li_16 = f0_13();
            break;
         case 8:
            li_16 = f0_4();
            break;
         case 9:
            li_16 = f0_31();
            break;
         case 10:
            li_16 = f0_16();
            break;
         case 11:
            li_16 = f0_17();
         }
         if (!li_16) return (0);
      }
   }
   return (1);
}

void f0_25() {
   string ls_0 = StringConcatenate(gs_712, "LastHistoryCount");
   int li_8 = GlobalVariableGet(ls_0);
   int li_12 = OrdersHistoryTotal();
   f0_22(1, MODE_HISTORY, li_8, li_12);
   GlobalVariableSet(ls_0, li_12);
}

int f0_44() {
   double ld_0 = MathAbs((OrderOpenPrice() - OrderClosePrice()) / Point);
   double ld_8 = OrderProfit();
   if (ld_8 < 0.0) ld_0 = -1.0 * ld_0;
   double ld_16 = f0_30();
   gd_608 = (gd_608 * gd_616 + ld_0) / (gd_616 + 1.0);
   gd_616 += 1.0;
   gd_600 += ld_0;
   gd_656 += ld_16;
   gd_592 += ld_8;
   if (OrderCommission() < 0.0) gd_664 += OrderCommission();
   gd_664 += ld_8;
   return (1);
}

void f0_51() {
   f0_22(2, MODE_TRADES);
}

int f0_15() {
   double ld_4;
   double ld_12;
   switch (OrderType()) {
   case OP_BUY:
      ld_4 = MathMin(gd_728 - gd_780, gd_728 - gd_804);
      if (OrderStopLoss() >= ld_4) break;
      gi_708 = f0_32(gi_708, StopLossTrailLong, OrderTicket(), OrderType(), OrderOpenPrice(), gd_700);
      f0_5(ld_4);
      break;
   case OP_SELL:
      ld_12 = MathMax(gd_736 + gd_788, gd_736 + gd_804);
      if (OrderStopLoss() <= ld_12) break;
      gi_708 = f0_32(gi_708, StopLossTrailShort, OrderTicket(), OrderType(), OrderOpenPrice(), gd_700);
      f0_5(ld_12);
   }
   return (1);
}

double f0_35(double ad_0) {
   return (NormalizeDouble(ad_0, Digits));
}

int f0_32(int ai_0, int ai_4, int ai_8, int ai_12, double ad_16, double ad_24) {
   if (ai_12 == 0 && f0_35(ad_16 - ad_24) > 0.0) {
      Print("SLTClearance before: ", ai_0);
      if (ai_0 - f0_35(ad_16 - ad_24) / Point > ai_4) {
         ai_0 = ai_0 - f0_35(ad_16 - ad_24) / Point;
         Print(f0_50(), "StopLossTrailClearance reduced due to slippage of ", f0_35(ad_16 - ad_24) / Point, " points on entry for order ticket: ", ai_8);
      }
   } else {
      if (ai_12 == 1 && f0_35(ad_24 - ad_16) > 0.0) {
         if (ai_0 - f0_35(ad_24 - ad_16) / Point > ai_4) {
            ai_0 = ai_0 - f0_35(ad_24 - ad_16) / Point;
            Print(f0_50(), "StopLossTrailClearance reduced due to slippage of ", f0_35(ad_24 - ad_16) / Point, " points on entry for order ticket: ", ai_8);
         }
      }
   }
   return (ai_0);
}

int f0_53(int ai_0) {
   double ld_4 = 0;
   int li_12 = OrdersTotal();
   for (int li_16 = 0; li_16 < li_12; li_16++) {
      if (!(OrderSelect(li_16, SELECT_BY_POS, MODE_TRADES))) break;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY && gi_512 && gd_728 > OrderOpenPrice() && gd_728 < OrderOpenPrice() + ai_0 * Point) {
            ld_4 = OrderOpenPrice() - gd_780 + (gd_728 - OrderOpenPrice()) * gd_516;
            if (!(f0_35(ld_4) > f0_35(OrderStopLoss()) && gd_728 - f0_35(ld_4) > StopLossTrailLong * Point)) continue;
            Print(f0_50(), "Applying pre-trailing stop to long order with order ticket: ", OrderTicket());
            if (!f0_5(ld_4)) {
               Print(f0_50(), "Applying pre-trailing stop to long order failed with order ticket: ", OrderTicket());
               continue;
            }
            Print(f0_50(), "Applying pre-trailing stop to long order succeeded with order ticket: ", OrderTicket());
            continue;
         }
         if (OrderType() == OP_SELL && gi_524 && gd_736 < OrderOpenPrice() && gd_736 > OrderOpenPrice() - ai_0 * Point) {
            ld_4 = OrderOpenPrice() + gd_788 - (OrderOpenPrice() - gd_736) * gd_528;
            if (f0_35(ld_4) < f0_35(OrderStopLoss()) && f0_35(ld_4) - gd_736 > StopLossTrailLong * Point) {
               Print(f0_50(), "Applying pre-trailing stop to short order with order ticket: ", OrderTicket());
               if (!f0_5(ld_4)) {
                  Print(f0_50(), "Applying pre-trailing stop to short order failed with order ticket: ", OrderTicket());
                  continue;
               }
               Print(f0_50(), "Applying pre-trailing stop to short order succeeded with order ticket: ", OrderTicket());
            }
         }
      }
   }
   return (0);
}

void f0_19() {
   f0_22(3);
}

int f0_7() {
   double ld_0;
   if (OrderType() == OP_BUY && gd_728 - OrderOpenPrice() > gi_708 * Point) {
      ld_0 = f0_35(gd_728 - StopLossTrailLong * Point);
      if (f0_35(ld_0) > f0_35(OrderStopLoss())) {
         Print(f0_50(), "Applying trailing stop to long order with order ticket: ", OrderTicket());
         if (!f0_5(ld_0)) Print(f0_50(), "Applying trailing stop to long order failed with order ticket: ", OrderTicket());
         else Print(f0_50(), "Applying trailing stop to long order succeeded with order ticket: ", OrderTicket());
      }
   } else {
      if (OrderType() == OP_SELL && OrderOpenPrice() - gd_736 > gi_708 * Point) {
         ld_0 = gd_736 + StopLossTrailShort * Point;
         if (f0_35(ld_0) < f0_35(OrderStopLoss())) {
            Print(f0_50(), "Applying trailing stop to short order with order ticket: ", OrderTicket());
            if (!f0_5(ld_0)) Print(f0_50(), "Applying trailing stop to short order failed with order ticket: ", OrderTicket());
            else Print(f0_50(), "Applying trailing stop to short order succeeded with order ticket: ", OrderTicket());
         }
      }
   }
   return (1);
}

void f0_52() {
   f0_22(4);
}

int f0_1() {
   double ld_4;
   double ld_12;
   switch (OrderType()) {
   case OP_BUYSTOP:
      ld_4 = f0_35(gd_736 + gd_764);
      ld_12 = ld_4 - (gd_736 - gd_728) - gd_780;
      if (OrderOpenPrice() <= f0_35(ld_4)) break;
      Print(f0_50(), "Attempting to change order entry price for long order order with order ticket: ", OrderTicket());
      if (!f0_49(OrderTicket(), ld_4, ld_12, ld_4 + gd_796)) Print(f0_50(), "Attempting to change order entry price for long order failed with order ticket: ", OrderTicket());
      else {
         gd_700 = ld_4;
         Print(f0_50(), "Attempting to change order entry price for long order succeeded with order ticket: ", OrderTicket());
      }
      break;
   case OP_SELLSTOP:
      ld_4 = f0_35(gd_728 - gd_772);
      ld_12 = ld_4 + (gd_736 - gd_728) + gd_788;
      if (OrderOpenPrice() >= f0_35(ld_4)) break;
      Print(f0_50(), "Attempting to change order entry price for short order order with order ticket: ", OrderTicket());
      if (!f0_49(OrderTicket(), ld_4, ld_12, ld_4 - gd_796)) Print(f0_50(), "Attempting to change order entry price for short order failed with order ticket: ", OrderTicket());
      else {
         gd_700 = ld_4;
         Print(f0_50(), "Attempting to change order entry price for short order succeeded with order ticket: ", OrderTicket());
      }
   }
   return (1);
}

void f0_11() {
   if (gi_576) {
      Comment("\n!ERROR!\n\n " + gs_580);
      return;
   }
   if (gs_888 == "") gs_888 = StringSubstr("1.18", 5, StringLen("1.18") - 6);
   string ls_0 = StringConcatenate("still trading (", FridayClose, ")");
   if (f0_48()) ls_0 = "Closed for trading";
   if (!UseFridayClose) ls_0 = "Not in use";
   double ld_8 = MaxAvSpread;
   string ls_16 = StringConcatenate("\n", "NMi Super Scalper", " Version ", "1.18", 
      "\nCurrent spread: ", DoubleToStr((gd_736 - gd_728) / Point, 0), " points", 
      "\nCurrent Average Spread/", gi_536, ": ", DoubleToStr(f0_28() / Point, 0), " points", 
      "\nMaxAvSpread is set to: ", DoubleToStr(ld_8, 0), " points", 
      "\nCommission: ", DoubleToStr(gd_692, 1), " points", 
      "\nNext lot size Long: ", DoubleToStr(f0_43(StopLossMoveLong), 2), 
      "\nNext lot size Short: ", DoubleToStr(f0_43(StopLossMoveShort), 2), 
      "\nStopLoss Long: ", StopLossMoveLong, " points", 
      "\nStopLoss Short: ", StopLossMoveShort, " points", 
      "\nRisk by MoneyManagement: ", gs_828, 
      "\nPendingStopClearanceLong is set to: ", DoubleToStr(PendingStopClearanceLong, 0), " points", 
      "\nPendingStopClearanceShort is set to: ", DoubleToStr(PendingStopClearanceShort, 0), " points", 
      "\nBBandClearanceLong is set to: ", DoubleToStr(BBandClearanceLong, 0), " points", 
      "\nBBandClearanceShort is set to: ", DoubleToStr(BBandClearanceShort, 0), " points", 
      "\nCBandClearance is set to: ", DoubleToStr(CBandClearance, 0), " points", 
      "\nBClearance is set to: ", DoubleToStr(BClearance, 0), " points", 
      "\nConservative: ", gs_820, 
      "\nMagicNumber: ", MagicNumber, 
   "\n\nBroker time: ", TimeToStr(TimeCurrent()));
   if (gi_400) {
      ls_16 = StringConcatenate(ls_16, 
      "\nNo Friday Trade is set to true.");
   } else {
      ls_16 = StringConcatenate(ls_16, 
      "\nFridayCloseTime: ", ls_0);
   }
   if (UseTimeZone) {
      ls_16 = StringConcatenate(ls_16, 
      "\nTrade Zone 1 is: ", TZ1StartTime, " to ", TZ1EndTime);
      ls_16 = StringConcatenate(ls_16, 
      "\nTrade Zone 2 is: ", TZ2StartTime, " to ", TZ2EndTime);
      if (f0_3()==true) {
         ls_16 = StringConcatenate(ls_16, 
         "\n Currently within trade zone and trading!");
      } else {
         ls_16 = StringConcatenate(ls_16, 
         "\n Currently outside trade zone and NOT trading!");
      }
   } else {
      ls_16 = StringConcatenate(ls_16, 
      "\nNot using Trade Zone. Will trade 24 hours.");
   }
   ls_16 = StringConcatenate(ls_16, 
   "\n\nAverage open slippage: ", DoubleToStr(gd_640, 1));
   ls_16 = StringConcatenate(ls_16, 
   "\nAverage close slippage: ", DoubleToStr(gd_624, 1));
   ls_16 = StringConcatenate(ls_16, 
   "\n\nProfit/Loss this session: ", DoubleToStr(gd_664, 2));
   Comment(ls_16);
}

void f0_45() {
   gda_720[gi_896] = gd_736 - gd_728;
   gi_896 = (gi_896 + 1) % gi_536;
}

int f0_18() {
   if (!gi_404) return (1);
   if (gd_736 - gd_728 > gd_756) gi_900 = TimeCurrent();
   if (TimeCurrent() - gi_900 >= gi_476) return (1);
   return (0);
}

int f0_37() {
   if (f0_28() < gd_748) return (1);
   return (0);
}

double f0_28() {
   double ld_0 = 0.0;
   for (int li_8 = 0; li_8 < gi_536 && gda_720[li_8] >= 0.0; li_8++) ld_0 += gda_720[li_8];
   if (li_8 > 0) return (ld_0 / li_8);
   return (0.0);
}

void f0_47() {
   gd_692 = 0;
   int li_0 = OrdersHistoryTotal();
   for (int li_4 = 0; li_4 < li_0; li_4++) {
      OrderSelect(li_4, SELECT_BY_POS, MODE_HISTORY);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() <= OP_SELL) {
         gd_692 = f0_30();
         return;
      }
   }
}

double f0_30() {
   if (OrderCommission() < 0.0) return (-1.0 * (OrderCommission() / MarketInfo(Symbol(), MODE_TICKVALUE) / OrderLots()));
   return (0.0);
}

double f0_36(int ai_0) {
   gi_688 = 9999;
   double ld_4 = 0.0;
   if (ai_0 == -1) {
      for (int li_12 = 0; li_12 < BB1Period; li_12++) {
         if (f0_35(Open[li_12]) > f0_35(Close[li_12 + 1])) {
            ld_4 = f0_35(Open[li_12]) - f0_35(Close[li_12 + 1]);
            gi_688 = 1;
            gi_680 = li_12;
            break;
         }
      }
   } else {
      if (ai_0 == 1) {
         for (li_12 = 0; li_12 < BB1Period; li_12++) {
            if (f0_35(Open[li_12]) < f0_35(Close[li_12 + 1])) {
               ld_4 = f0_35(Close[li_12 + 1]) - f0_35(Open[li_12]);
               gi_688 = -1;
               gi_684 = li_12;
               break;
            }
         }
      }
   }
   return (ld_4);
}

bool f0_48() {
   string ls_4;
   string ls_12;
   int li_0 = TimeCurrent();
   if (TimeDayOfWeek(li_0) != 5) return (FALSE);
   if (gi_400) return (TRUE);
   if (UseFridayClose) {
      ls_4 = TimeToStr(li_0, TIME_DATE);
      ls_12 = StringConcatenate(ls_4, " ", FridayClose);
      if (li_0 >= StrToTime(ls_12)) return (TRUE);
   }
   return (FALSE);
}

bool f0_27() {
   int li_4;
   int li_8;
   if (gi_904 >= 7) {
      for (int li_0 = 0; li_0 <= 7; li_0++) {
         li_4 = iTime(NULL, PERIOD_D1, li_0);
         li_8 = TimeDayOfWeek(li_4);
         if (li_8 < gi_904) {
            gi_904 = li_8;
            gs_908 = TimeToStr(li_4, TIME_MINUTES);
         }
      }
   }
   int li_12 = TimeCurrent();
   if (TimeDayOfWeek(li_12) != gi_904) return (FALSE);
   string ls_16 = TimeToStr(li_12, TIME_DATE);
   string ls_24 = StringConcatenate(ls_16, " ", gs_908);
   if (li_12 < StrToTime(ls_24) + gi_444) return (TRUE);
   return (FALSE);
}

int f0_3() {
   bool li_0 = FALSE;
   if (!UseTimeZone) li_0 = TRUE;
   int li_4 = TimeCurrent();
   if (UseTimeZone) {
      if (li_4 > StrToTime(TZ1StartTime) && li_4 < StrToTime(TZ1EndTime)) li_0 = TRUE;
      if (li_4 > StrToTime(TZ2StartTime) && li_4 < StrToTime(TZ2EndTime)) li_0 = TRUE;
   }
   if (iTime(Symbol(), 0, 0) - gi_860 < 60) li_0 = FALSE;
   return (li_0);
}

void f0_38() {
   gi_576 = TRUE;
   Print("Connecting to server...");
   Print("Updating settings from server...");
   gd_592 = 0;
   gd_600 = 0;
   gd_608 = 0;
   gd_616 = 0;
   gd_656 = 0;
   gd_640 = 0;
   gd_624 = 0;
   gd_648 = 0;
   gd_632 = 0;
   if (StringFind(Symbol(),"EURUSD",0) != -1 || StringFind(Symbol(),"USDCHF",0) != -1 || StringFind(Symbol(),"GBPUSD",0) != -1 || StringFind(Symbol(),"USDJPY",0)  != -1 || StringFind(Symbol(),"EURJPY",0) != -1 || StringFind(Symbol(),"AUDUSD",0) != -1 )
   {
      if (StringFind(Symbol(),"EURUSD",0) != -1)
      {
         gi_576 = FALSE;
         gd_812 = 999999.00000000;
         if (bb1) BB1Period = 30;
         if (bb2) BB2Period = 25;
         if (bb3) BB3Period = 6;
         if (gi_548) MaxAvSpread = 20;
         if (gi_556) MaxTrades = 2;
         if (gi_560) BClearance = 160;
         if (gi_564) BBandClearanceLong = 160;
         if (gi_568) BBandClearanceShort = 160;
         if (gi_572) CBandClearance = 180;
         if (maxslip) MaxSlippage = 15;
         if (pscl) PendingStopClearanceLong = 18;
         if (pscs) PendingStopClearanceShort = 18;
         if (slip) Slippage = 10;
         gi_536 = 30;
         if (slml) StopLossMoveLong = 30;
         if (slms) StopLossMoveShort = 30;
         if (sltcl) StopLossTrailClearanceLong = 24;
         if (sltcs) StopLossTrailClearanceShort = 24;
         if (sltl) StopLossTrailLong = 22;
         if (slts) StopLossTrailShort = 22;
         if (tp) TakeProfit = 500;
         gi_480 = 15;
         Print("Settings Updated.");
         Print("Connection to NMi server closed.");
      }
      if (StringFind(Symbol(),"USDCHF",0) != -1)
      {
         gi_576 = FALSE;
         gd_812 = 999999.00000000;
         if (bb1) BB1Period = 25;
         if (bb2) BB2Period = 20;
         if (bb3) BB3Period = 10;
         if (gi_548) MaxAvSpread = 20;
         if (gi_556) MaxTrades = 2;
         if (gi_560) BClearance = 140;
         if (gi_564) BBandClearanceLong = 160;
         if (gi_568) BBandClearanceShort = 160;
         if (gi_572) CBandClearance = 180;
         if (maxslip) MaxSlippage = 15;
         if (pscl) PendingStopClearanceLong = 18;
         if (pscs) PendingStopClearanceShort = 18;
         if (slip) Slippage = 10;
         gi_536 = 30;
         if (slml) StopLossMoveLong = 32;
         if (slms) StopLossMoveShort = 32;
         if (sltcl) StopLossTrailClearanceLong = 24;
         if (sltcs) StopLossTrailClearanceShort = 24;
         if (sltl) StopLossTrailLong = 22;
         if (slts) StopLossTrailShort = 22;
         if (tp) TakeProfit = 500;
         gi_480 = 15;
         Print("Settings Updated.");
         Print("Connection to NMi server closed.");
      }
      if (StringFind(Symbol(),"GBPUSD",0) != -1)
      {
         gi_576 = FALSE;
         gd_812 = 999999.00000000;
         if (bb1) BB1Period = 30;
         if (bb2) BB2Period = 25;
         if (bb3) BB3Period = 5;
         if (gi_548) MaxAvSpread = 25;
         if (gi_556) MaxTrades = 2;
         if (gi_560) BClearance = 180;
         if (gi_564) BBandClearanceLong = 160;
         if (gi_568) BBandClearanceShort = 160;
         if (gi_572) CBandClearance = 200;
         if (maxslip) MaxSlippage = 15;
         if (pscl) PendingStopClearanceLong = 20;
         if (pscs) PendingStopClearanceShort = 20;
         if (slip) Slippage = 10;
         gi_536 = 30;
         if (slml) StopLossMoveLong = 32;
         if (slms) StopLossMoveShort = 32;
         if (sltcl) StopLossTrailClearanceLong = 24;
         if (sltcs) StopLossTrailClearanceShort = 24;
         if (sltl) StopLossTrailLong = 22;
         if (slts) StopLossTrailShort = 22;
         if (tp) TakeProfit = 500;
         gi_480 = 15;
         Print("Settings Updated.");
         Print("Connection to NMi server closed.");
      }
      if (StringFind(Symbol(),"USDJPY",0) != -1)
      {
         gi_576 = FALSE;
         gd_812 = 999999.00000000;
         if (bb1) BB1Period = 25;
         if (bb2) BB2Period = 20;
         if (bb3) BB3Period = 10;
         if (gi_548) MaxAvSpread = 20;
         if (gi_556) MaxTrades = 2;
         if (gi_560) BClearance = 140;
         if (gi_564) BBandClearanceLong = 160;
         if (gi_568) BBandClearanceShort = 160;
         if (gi_572) CBandClearance = 180;
         if (maxslip) MaxSlippage = 15;
         if (pscl) PendingStopClearanceLong = 18;
         if (pscs) PendingStopClearanceShort = 18;
         if (slip) Slippage = 10;
         gi_536 = 30;
         if (slml) StopLossMoveLong = 28;
         if (slms) StopLossMoveShort = 28;
         if (sltcl) StopLossTrailClearanceLong = 22;
         if (sltcs) StopLossTrailClearanceShort = 22;
         if (sltl) StopLossTrailLong = 20;
         if (slts) StopLossTrailShort = 20;
         if (tp) TakeProfit = 500;
         gi_480 = 15;
         Print("Settings Updated.");
         Print("Connection to NMi server closed.");
      }
      if (StringFind(Symbol(),"EURJPY",0) != -1)
      {
         gi_576 = FALSE;
         gd_812 = 999999.00000000;
         if (bb1) BB1Period = 35;
         if (bb2) BB2Period = 25;
         if (bb3) BB3Period = 8;
         if (gi_548) MaxAvSpread = 25;
         if (gi_556) MaxTrades = 2;
         if (gi_560) BClearance = 160;
         if (gi_564) BBandClearanceLong = 160;
         if (gi_568) BBandClearanceShort = 160;
         if (gi_572) CBandClearance = 180;
         if (maxslip) MaxSlippage = 15;
         if (pscl) PendingStopClearanceLong = 18;
         if (pscs) PendingStopClearanceShort = 18;
         if (slip) Slippage = 15;
         gi_536 = 30;
         if (slml) StopLossMoveLong = 30;
         if (slms) StopLossMoveShort = 30;
         if (sltcl) StopLossTrailClearanceLong = 24;
         if (sltcs) StopLossTrailClearanceShort = 24;
         if (sltl) StopLossTrailLong = 22;
         if (slts) StopLossTrailShort = 22;
         if (tp) TakeProfit = 500;
         gi_480 = 15;
         Print("Settings Updated.");
         Print("Connection to NMi server closed.");
      }
      if (StringFind(Symbol(),"AUDUSD",0) != -1)
      {
         gi_576 = FALSE;
         gd_812 = 999999.00000000;
         if (bb1) BB1Period = 25;
         if (bb2) BB2Period = 15;
         if (bb3) BB3Period = 10;
         if (gi_548) MaxAvSpread = 20;
         if (gi_556) MaxTrades = 2;
         if (gi_560) BClearance = 160;
         if (gi_564) BBandClearanceLong = 140;
         if (gi_568) BBandClearanceShort = 140;
         if (gi_572) CBandClearance = 160;
         if (maxslip) MaxSlippage = 15;
         if (pscl) PendingStopClearanceLong = 18;
         if (pscs) PendingStopClearanceShort = 18;
         if (slip) Slippage = 15;
         gi_536 = 30;
         if (slml) StopLossMoveLong = 30;
         if (slms) StopLossMoveShort = 30;
         if (sltcl) StopLossTrailClearanceLong = 24;
         if (sltcs) StopLossTrailClearanceShort = 24;
         if (sltl) StopLossTrailLong = 22;
         if (slts) StopLossTrailShort = 22;
         if (tp) TakeProfit = 500;
         gi_480 = 15;
         Print("Settings Updated.");
         Print("Connection to NMi server closed.");
      }
   } else {
      gi_576 = TRUE;
      gs_580 = "This pair is not supported.";
      Print(gs_580);
      Print("Connection to NMi server closed.");
   }
   f0_33();
}

void f0_33() {
   int li_0 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   if (li_0 > PendingStopClearanceLong) {
      PendingStopClearanceLong = li_0;
      Print("PendingStopClearanceLong automatically adjusted to minimum broker level of ", DoubleToStr(li_0, 0), " points");
   }
   if (li_0 > PendingStopClearanceShort) {
      PendingStopClearanceShort = li_0;
      Print("PendingStopClearanceShort automatically adjusted to minimum broker level of ", DoubleToStr(li_0, 0), " points");
   }
   if (li_0 > StopLossTrailLong) {
      StopLossTrailLong = li_0;
      Print("StopLossTrailLong automatically adjusted to minimum broker level of ", DoubleToStr(li_0, 0), " points");
   }
   if (li_0 > StopLossTrailShort) {
      StopLossTrailShort = li_0;
      Print("StopLossTrailShort automatically adjusted to minimum broker level of ", DoubleToStr(li_0, 0), " points");
   }
   if (gi_536 > 100) {
      gi_536 = 100;
      Print("SpreadHistTicks reduced to maximum supported value of " + gi_536 + " ticks");
   }
   if (RiskPercentage > 100.0) {
      RiskPercentage = 100.0;
      Print("RiskValue automatically adjusted to maximum supported value of 100%");
   }
   if (BBandClearanceLong < 100) {
      BBandClearanceLong = 100;
      Print("BBandClearanceLong automatically adjusted to minimum supported value of 100");
   }
   if (BBandClearanceShort < 100) {
      BBandClearanceShort = 100;
      Print("BBandClearanceShort automatically adjusted to minimum supported value of 100");
   }
   if (CBandClearance < 100) {
      CBandClearance = 100;
      Print("CBandClearance automatically adjusted to minimum supported value of 100");
   }
   if (BClearance < 100) {
      BClearance = 100;
      Print("BClearance automatically adjusted to minimum supported value of 100");
   }
   if (MaxLots > gd_812 && gd_812 > 0.0) MaxLots = gd_812;
   gd_748 = Point * MaxAvSpread;
   gd_756 = Point * gi_480 + gd_748;
   gd_764 = Point * PendingStopClearanceLong;
   gd_772 = Point * PendingStopClearanceShort;
   gd_780 = Point * StopLossMoveLong;
   gd_788 = Point * StopLossMoveShort;
   gd_796 = Point * TakeProfit;
   gd_804 = Point * li_0;
}
/*
void f0_40(string as_0, string as_8, string &asa_16[]) {
   int li_20 = -1;
   int li_24 = 0;
   for (int li_28 = 0; li_24 != -1; li_28++) {
      li_24 = StringFind(as_8, as_0, li_20 + 1);
      ArrayResize(asa_16, li_28 + 1);
      asa_16[li_28] = "";
      if (li_24 == -1) {
         if (li_20 + 1 != StringLen(as_8)) asa_16[li_28] = StringSubstr(as_8, li_20 + 1, StringLen(as_8));
      } else
         if (li_20 + 1 != li_24) asa_16[li_28] = StringSubstr(as_8, li_20 + 1, li_24 - li_20 - 1);
      li_20 = StringFind(as_8, as_0, li_24);
   }
}

string f0_42(string as_0) {
   string ls_24;
   int li_32;
   int li_8 = StringLen(as_0);
   string ls_12 = "";
   for (int li_20 = 0; li_20 < li_8; li_20++) {
      ls_24 = StringSubstr(as_0, li_20, 1);
      li_32 = StringGetChar(ls_24, 0);
      if ((li_32 > '/' && li_32 < ':') || (li_32 > '@' && li_32 < '[') || (li_32 > '`' && li_32 < '{')) ls_12 = StringConcatenate(ls_12, ls_24);
      else {
         if (li_32 == ' ') ls_12 = StringConcatenate(ls_12, "+");
         else ls_12 = StringConcatenate(ls_12, "%", f0_39(li_32));
      }
   }
   return (ls_12);
}
*/
int f0_24(int aia_0[], int ai_4) {
   for (int li_8 = 0; li_8 < ArraySize(aia_0); li_8++)
      if (aia_0[li_8] <= ai_4) break;
   return (li_8);
}
/*
string f0_39(int ai_0) {
   string ls_4 = "";
   int li_12 = ai_0 % 16;
   int li_16 = (ai_0 - li_12) / 16;
   if (li_16 > 15) ls_4 = StringConcatenate(f0_39(li_16), StringSubstr(gs_916, li_12, 1));
   else ls_4 = StringConcatenate(StringSubstr(gs_916, li_16, 1), StringSubstr(gs_916, li_12, 1));
   return (ls_4);
}
*/
int f0_2(double ad_0, int ai_8, int ai_12) {
   color li_16;
   string ls_20;
   double ld_28;
   double ld_36;
   double ld_44;
   double ld_52;
   int li_76;
   switch (ai_8) {
   case OP_BUYSTOP:
      ld_28 = f0_43(StopLossMoveLong);
      li_16 = Green;
      ls_20 = "Long";
      gi_708 = StopLossTrailClearanceLong;
      break;
   case OP_SELLSTOP:
      ld_28 = f0_43(StopLossMoveShort);
      li_16 = Red;
      ls_20 = "Short";
      gi_708 = StopLossTrailClearanceShort;
      break;
   default:
      Print("Error: Unsupported order type ", ls_20, ", trade abandoned.");
      return (0);
   }
   if (f0_0() < 0) {
      Print(f0_50(), "Trade context was busy and the ", ls_20, " trade was abandoned.");
      return (0);
   }
   switch (ai_8) {
   case OP_BUYSTOP:
      ld_36 = gd_736;
      gd_700 = gd_736 + gd_764;
      if (ad_0 != 0.0) gd_700 = ad_0;
      ld_44 = gd_700 - (gd_736 - gd_728) - gd_780;
      ld_52 = gd_728 - gd_764 + gd_796;
      if (ad_0 == 0.0) break;
      ld_52 = 0;
      break;
   case OP_SELLSTOP:
      ld_36 = gd_728;
      gd_700 = gd_728 - gd_772;
      if (ad_0 != 0.0) gd_700 = ad_0;
      ld_44 = gd_700 + (gd_736 - gd_728) + gd_788;
      ld_52 = gd_736 + gd_772 - gd_796;
      if (ad_0 == 0.0) break;
      ld_52 = 0;
   }
   double ld_68 = f0_35(gd_700);
   if (ld_68 == 0.0) ld_68 = f0_35(ld_36);
   RefreshRates();
   if (Bid != gd_728 || Ask != gd_736) {
      Print(f0_50(), "Bid and/or Ask price has changed and the OrderSend was abandoned.");
      gi_744 = TRUE;
   } else {
      Print(f0_50(), "Current Market: ", DoubleToStr(ld_36, Digits), ". ", ls_20, " Trade Entry: ", DoubleToStr(ld_68, Digits), ". ", "Lots: ", DoubleToStr(ld_28, gi_724),
         ". ", "StopLoss: ", DoubleToStr(ld_44, Digits), ". ", "TakeProfit: ", DoubleToStr(ld_52, Digits), ".");
      if (OrderSend(Symbol(), ai_8, ld_28, ld_68, Slippage, f0_35(ld_44), f0_35(ld_52), CustomOrderComment, ai_12, 0, li_16) >= 0) return (1);
      li_76 = GetLastError();
      Print(f0_50(), ls_20, " OrderSend failed with error #", li_76, ": ", ErrorDescription(li_76), ", Trade Entry Price: ", DoubleToStr(ld_68, Digits), ", Volume: ", DoubleToStr(ld_28,
         Digits));
   }
   return (0);
}

int f0_0() {
   int li_12;
   int li_0 = 15;
   string ls_4 = Symbol();
   if (!IsTradeAllowed()) {
      li_12 = GetTickCount();
      Print("Trade context is busy! Wait until it is free...");
      while (true) {
         Print("Waiting for trade context...");
         if (IsStopped()) {
            Print(ls_4, ": The expert was terminated by the user!");
            return (-1);
         }
         if (GetTickCount() - li_12 > 1000 * li_0) {
            Print("The waiting limit exceeded (" + li_0 + " Sec.)!");
            return (-2);
         }
         if (IsTradeAllowed()) {
            Print(ls_4, ": Trade context has become free!");
            return (0);
         }
         Sleep(RetryIntervalMilliseconds);
      }
   }
   Print(ls_4, ": Trade context is free!");
   return (1);
}

string f0_50() {
   string ls_0 = TimeToStr(iTime(Symbol(), 0, 0)) + ": ";
   return (ls_0);
}

bool f0_49(int ai_0, double ad_4, double ad_12, double ad_20) {
   int li_28;
   int li_32;
   int li_36;
   bool li_40;
   if (f0_0() < 0) {
      Print(f0_50(), "Trade context was busy and the modification of the existing trade was abandoned.");
      return (FALSE);
   }
   RefreshRates();
   if (Bid != gd_728 || Ask != gd_736) {
      Print(f0_50(), "Bid and/or Ask price has changed and the modification of the existing trade was abandoned.");
      gi_744 = TRUE;
   } else {
      li_28 = GetTickCount();
      gi_852++;
      OrderModify(ai_0, ad_4, ad_12, ad_20, 0, Red);
      gi_856 += GetTickCount() - li_28;
      li_32 = GetLastError();
      if (li_32 == 0/* NO_ERROR */) return (TRUE);
      li_36 = 0;
      while (li_32 == 130/* INVALID_STOPS */ && li_36 < gi_540) {
         li_36++;
         li_28 = GetTickCount();
         gi_852++;
         li_40 = OrderModify(ai_0, ad_4, ad_12, ad_20, 0, Red);
         gi_856 += GetTickCount() - li_28;
         if (li_40 == TRUE) return (TRUE);
         li_32 = GetLastError();
      }
      Print(f0_50(), "OrderModify failed with error #", li_32, ": ", ErrorDescription(li_32), " - Ask: ", gd_736, ". Bid: ", gd_728, ". Stop Loss: ", ad_12, ". Ticket Number: ",
         ai_0, ".");
   }
   return (FALSE);
}

bool f0_5(double ad_0) {
   return (f0_49(OrderTicket(), OrderOpenPrice(), ad_0, OrderTakeProfit()));
}

double f0_43(double ad_0) {
   double ld_16;
   double ld_24;
   if (gi_576) return (0.0);
   double ld_8 = FixedLots;
   if (MoneyManagement) {
      ld_16 = AccountBalance() * (RiskPercentage / 100.0);
      ld_24 = ad_0 * MarketInfo(Symbol(), MODE_TICKVALUE);
      if (ld_24 == 0.0) Print(f0_50(), "MoneyManagement temporarily disabled due to division by: ", ld_24);
      else ld_8 = ld_16 / (ad_0 * MarketInfo(Symbol(), MODE_TICKVALUE));
   }
   return (NormalizeDouble(MathMin(ld_8, MaxLots), gi_724));
}

int f0_10() {
   gi_924 = 0;
   f0_22(5);
   return (gi_924);
}

int f0_23() {
   gi_924++;
   return (1);
}

void f0_8() {
   f0_22(6);
}

int f0_41() {
   if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP) OrderDelete(OrderTicket());
   return (1);
}

int f0_6() {
   gi_928 = 0;
   gi_932 = 0;
   f0_22(7);
   if (gi_956 != 0 && gi_928 == 0) {
      OrderSelect(gi_956, SELECT_BY_TICKET, MODE_TRADES);
      if (OrderOpenPrice() - gd_936 > MaxSlippage * Point) gi_952 = TimeCurrent();
   }
   gi_956 = gi_928;
   if (gi_960 != 0 && gi_932 == 0) {
      OrderSelect(gi_960, SELECT_BY_TICKET, MODE_TRADES);
      if (gd_944 - OrderOpenPrice() > MaxSlippage * Point) gi_952 = TimeCurrent();
   }
   gi_960 = gi_932;
   return (TimeCurrent() - gi_952 >= gi_188);
}

int f0_13() {
   switch (OrderType()) {
   case OP_BUYSTOP:
      gd_936 = OrderOpenPrice();
      gi_928 = OrderTicket();
      break;
   case OP_SELLSTOP:
      gd_944 = OrderOpenPrice();
      gi_932 = OrderTicket();
   }
   return (1);
}

int f0_9() {
   if (!UseMaxTradesFilter) return (1);
   gi_964 = 0;
   f0_22(8, MODE_HISTORY);
   if (gi_964 >= MaxTrades) return (0);
   return (1);
}

int f0_4() {
   if (OrderType() == OP_BUY || OrderType() == OP_SELL && TimeCurrent() - OrderCloseTime() < MaxTradesSeconds && OrderProfit() < 0.0) gi_964++;
   if (OrderType() == OP_BUY || OrderType() == OP_SELL && TimeCurrent() - OrderCloseTime() < MaxTradesSeconds && OrderProfit() > 0.0) gi_964 = 0;
   return (1);
}

int f0_14() {
   gd_968 = 0;
   f0_22(9, MODE_HISTORY);
   if (gd_968 <= -(MaxDailyLossPercent / 100.0 * (AccountBalance() + MathAbs(gd_968)))) return (1);
   return (0);
}

bool f0_26() {
   if (!UseMaxDailyLoss) return (FALSE);
   gd_968 = 0;
   f0_22(9, MODE_HISTORY);
   if (gd_968 <= -(MaxDailyLossPercent / 100.0 * (AccountBalance() + MathAbs(gd_968)))) return (TRUE);
   gd_968 = 0;
   if (UseAllPairs) {
      gi_836 = TRUE;
      f0_22(9, MODE_HISTORY);
      gi_836 = FALSE;
      if (gd_968 <= -(MaxPercentAllPairs / 100.0 * (AccountBalance() + MathAbs(gd_968)))) return (TRUE);
   }
   return (FALSE);
}

int f0_31() {
   if (OrderType() == OP_BUY || OrderType() == OP_SELL && TimeCurrent() - OrderCloseTime() <= 86400)
      if (OrderProfit() < 0.0) gd_968 += OrderProfit();
   return (1);
}

int f0_12() {
   if (!gi_408) return (1);
   if (MathAbs(gd_672 - gd_728) > gi_412 * Point) return (0);
   return (1);
}

void f0_21() {
   f0_22(10);
}

int f0_16() {
   double ld_4;
   double ld_12;
   switch (OrderType()) {
   case OP_BUY:
      ld_4 = MathMin(gd_728 - gd_780, gd_728 - gd_804);
      if (OrderStopLoss() >= ld_4) break;
      f0_5(ld_4);
      break;
   case OP_SELL:
      ld_12 = MathMax(gd_736 + gd_788, gd_736 + gd_804);
      if (OrderStopLoss() <= ld_12) break;
      f0_5(ld_12);
   }
   return (1);
}
/*
string f0_20(string as_0) {
   string ls_32;
   string ls_40;
   string ls_48;
   string ls_56;
   string ls_64;
   string ls_8 = "1b0iaj1dk0kK1SJ0SM1EA0ioOPefr";
   for (int li_16 = 1000; li_16 > 100 || li_16 < 10; li_16 /= 500) li_16 = MathRand();
   string ls_20 = li_16;
   for (int li_28 = 0; li_28 < StringLen(as_0); li_28++) {
      ls_32 = StringSubstr(as_0, li_28, 1);
      ls_40 = StringSubstr(ls_8, li_28 % StringLen(ls_8) - 1, 1);
      ls_48 = StringSubstr(ls_8, li_28 % StringLen(ls_8) + 1, 1);
      ls_56 = StringSubstr(ls_8, li_28 % StringLen(ls_8) - 2, 1);
      ls_64 = StringConcatenate(ls_40, ls_48, ls_32, ls_48);
      ls_20 = StringConcatenate(ls_20, ls_64);
   }
   return (ls_20);
}
*/
void f0_29() {
   f0_22(11);
}

int f0_17() {
   double ld_4;
   switch (OrderType()) {
   case OP_BUY:
      if (gd_728 - OrderOpenPrice() <= gi_708 * Point) break;
      ld_4 = f0_35(gd_728 - StopLossTrailLong * Point);
      if (f0_35(ld_4) <= f0_35(OrderStopLoss())) break;
      Print(f0_50(), "Applying trailing stop to long order with order ticket: ", OrderTicket());
      if (!f0_5(ld_4)) Print(f0_50(), "Applying trailing stop to long order failed with order ticket: ", OrderTicket());
      else Print(f0_50(), "Applying trailing stop to long order succeeded with order ticket: ", OrderTicket());
      break;
   case OP_SELL:
      if (OrderOpenPrice() - gd_736 <= gi_708 * Point) break;
      ld_4 = gd_736 + StopLossTrailShort * Point;
      if (f0_35(ld_4) >= f0_35(OrderStopLoss())) break;
      Print(f0_50(), "Applying trailing stop to short order with order ticket: ", OrderTicket());
      if (!f0_5(ld_4)) Print(f0_50(), "Applying trailing stop to short order failed with order ticket: ", OrderTicket());
      else Print(f0_50(), "Applying trailing stop to short order succeeded with order ticket: ", OrderTicket());
   }
   return (1);
}

int f0_46(int ai_0) {
   int li_4;
   int li_8;
   int li_12;
   string ls_16;
   if (OrderSelect(ai_0, SELECT_BY_TICKET, MODE_HISTORY)) {
      if (gi_856 > 0 && gi_852 > 0) Print("Average OrderModification Time = ", DoubleToStr(gi_856 / gi_852, 0), "MilliSeconds over ", gi_852, " Modifications");
      Print("Net profit = ", DoubleToStr(OrderProfit() - OrderCommission() - OrderSwap(), 2), " ", AccountCurrency());
      if (OrderType() == OP_BUY) li_4 = (OrderClosePrice() - OrderOpenPrice()) / Point;
      if (OrderType() == OP_SELL) li_4 = (OrderOpenPrice() - OrderClosePrice()) / Point;
      Print("Net points profit = ", li_4);
      Print("Commission Points = ", DoubleToStr(gd_692, 1));
      if (OrderType() == OP_BUY) li_8 = (OrderStopLoss() - OrderClosePrice()) / Point;
      if (OrderType() == OP_SELL) li_8 = (OrderClosePrice() - OrderStopLoss()) / Point;
      gd_624 = (gd_624 * gd_632 + li_8) / (gd_632 + 1.0);
      gd_632 += 1.0;
      Print("StopLoss Slippage = ", li_8);
      Print("StopLoss Fill = ", DoubleToStr(OrderClosePrice(), Digits));
      Print("OrderStopLoss = ", DoubleToStr(OrderStopLoss(), Digits));
      if (OrderType() == OP_BUY) li_12 = (OrderOpenPrice() - gd_844) / Point;
      if (OrderType() == OP_SELL) li_12 = (gd_844 - OrderOpenPrice()) / Point;
      gd_640 = (gd_640 * gd_648 + li_12) / (gd_648 + 1.0);
      gd_648 += 1.0;
      Print("Entry Slippage = ", li_12);
      Print("OrderFill = ", DoubleToStr(OrderOpenPrice(), Digits));
      Print("OrderEntry = ", DoubleToStr(gd_844, Digits));
      Print("OrderSymbol = ", OrderSymbol());
      Print("OrderVolume = ", DoubleToStr(OrderLots(), 2));
      if (OrderType() == OP_BUY) ls_16 = "Buy";
      if (OrderType() == OP_SELL) ls_16 = "Sell";
      Print("OrderType = ", ls_16);
      Print("OrderTicket = ", ai_0);
      Print("===OrderReport===");
      ai_0 = 0;
      gi_856 = 0;
      gi_852 = 0;
      gi_840 = 0;
   }
   return (ai_0);
}

void f0_34() {
   double ld_12;
   int li_0 = 0;
   int li_4 = 0;
   bool li_8 = FALSE;
   for (int li_20 = 0; li_20 < OrdersTotal(); li_20++) {
      if (OrderSelect(li_20, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) {
         if (OrderType() == OP_BUY) {
            li_0 = 1;
            ld_12 = OrderStopLoss();
            if (OrderStopLoss() >= OrderOpenPrice()) li_8 = TRUE;
         }
         if (OrderType() == OP_SELL) {
            li_0 = -1;
            ld_12 = OrderStopLoss();
            if (OrderStopLoss() <= OrderOpenPrice()) li_8 = TRUE;
         }
      }
   }
   for (int li_24 = 0; li_24 < OrdersTotal(); li_24++) {
      if (OrderSelect(li_24, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == gi_392 && OrderSymbol() == Symbol()) {
         if (OrderType() == OP_BUY) {
            li_4 = 1;
            f0_16();
            f0_17();
         }
         if (OrderType() == OP_SELL) {
            li_4 = -1;
            f0_16();
            f0_17();
         }
         if (OrderType() > OP_SELL && li_8) OrderDelete(OrderTicket());
         if (OrderType() == OP_BUYSTOP) {
            li_4 = 1;
            if (OrderOpenPrice() != ld_12 + gi_396 * Point) f0_49(OrderTicket(), ld_12 + gi_396 * Point, ld_12 + gi_396 * Point - (gd_736 - gd_728) - gd_780, 0);
         }
         if (OrderType() == OP_SELLSTOP) {
            li_4 = -1;
            if (OrderOpenPrice() != ld_12 - gi_396 * Point) f0_49(OrderTicket(), ld_12 - gi_396 * Point, ld_12 - gi_396 * Point + (gd_736 - gd_728) + gd_788, 0);
         }
      }
   }
   if (li_4 == 0 && (!li_8)) {
      if (li_0 == 1) f0_2(ld_12 - gi_396 * Point, OP_SELLSTOP, gi_392);
      if (li_0 == -1) f0_2(ld_12 + gi_396 * Point, OP_BUYSTOP, gi_392);
   }
}

Recommend