
#property copyright "Copyright © 2008, FAPTURBO.com"
#property link      "http://fapturbo.com"

#import "FapTurbo.dll"
   int fun1(int a0, int a1, double a2, double a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13);
   bool fun2(double a0, int a1, double a2, double a3, int a4, int a5, double a6);
   bool fun3(double a0, int a1, double a2, double a3, int a4, int a5, double a6);
   bool fun4(double a0, int a1, int a2);
#import

extern string ____Scalper___________ = "--- Scalper EURCHF, EURGPB, GBPCHF or USDCAD M15 ---";
extern bool UseScalperStrategy = TRUE;
extern double Scalper_Lots = 0.1;
extern bool Scalper_UseMM = TRUE;
extern double Scalper_LotsRiskReductor = 5.0;
extern double Scalper_MaxLots = 10.0;
extern int Scalper_GMTOffset = 1;
extern bool Scalper_StealthMode = TRUE;
extern bool Scalper_UseCustomLevels = TRUE;
extern int Scalper_RelaxHours = 0;
extern bool Scalper_SimpleHeightFilter = TRUE;
extern bool Scalper_TrendFilter = TRUE;
extern bool Scalper_TradeFriday = FALSE;
extern int Scalper_OneTrade = 0;
extern bool Scalper_UseFilterMA = FALSE;
extern int Scalper_PeriodFilterMA = 100;
extern int Scalper_PriceFilterMA = 0;
extern int Scalper_MethodFilterMA = 0;
extern int Scalper_SlipageInc = 0;
extern string Scalper_ExpertComment = "FapTurboScalper";
extern string ____FapTurbo__________ = "---------- FapTurbo EUR/USD M1 ----------";
extern double FapTurbo_Lots = 0.01;
extern double FapTurbo_LotsRiskReductor = 1.0;
extern int FapTurbo_MaxOrders = 2;
extern int FapTurbo_MaxLots = 10;
extern int FapTurbo_StopTime = 9;
extern int FapTurbo_aaa = 35;
extern int FapTurbo_bbb = 48;
extern double FapTurbo_TakeProfit = 140.0;
extern double FapTurbo_StopLoss = 500.0;
extern double FapTurbo_TrailingStop = 0.0;
extern int FapTurbo_DurationInHours = 0;
extern int FapTurbo_CloseAfterXmonths = 1;
extern int FapTurbo_PeriodMALarge = 100;
extern int FapTurbo_PeriodMASmall = 30;
extern int FapTurbo_PriceMA_0_6 = 0;
extern int FapTurbo_TypeMA_0_3 = 0;
extern int FapTurbo_ShiftMALarge = 3;
extern int FapTurbo_ShiftMASmall = 1;
extern int FapTurbo_LookForDays = 2;
extern int FapTurbo_CriticalDays = 45;
extern int FapTurbo_RelaxDays = 0;
extern double FapTurbo_HedgingLotReducer = 0.0;
extern int FapTurbo_Hedging = 0;
extern int FapTurbo_TradeNFP = 1;
extern int FapTurbo_TradeFriday = 1;
extern int FapTurbo_Prudent = 0;
extern int FapTurbo_SymAlligatorOnCritica = 1;
extern int FapTurbo_FixedDirection = 1;
extern int FapTurbo_ClsLsrOnMrktChnge = 0;
extern int FapTurbo_AlwaysTrade = 0;
extern double FapTurbo_LowLot = 0.1;
extern int FapTurbo_TooGoodToBeTrue = 50;
extern int FapTurbo_PrudentPeriod = 30;
extern int FapTurbo_StartWorkTimeHour = 0;
extern int FapTurbo_StartWorkTimeMin = 0;
extern int FapTurbo_EndWorkTimeHour = 0;
extern int FapTurbo_EndWorkTimeMin = 0;
extern int FapTurbo_OneTrade = 0;
extern double FapTurbo_SpanGator = 0.5;
extern int FapTurbo_SlipPage = 3;
extern string FapTurbo_ExpertComment = "FapTurboEA";
extern string ____Other_Parameters__ = "-----------------------------------------";
extern int MagicNumber = 12464337;
extern color ColorBuy = Blue;
extern color ColorSell = Red;
extern bool WriteLog = TRUE;
extern bool WriteDebugLog = FALSE;
extern bool PrintLogOnChart = TRUE;

int gi_424 = 6;
int gi_428 = 112;
int gi_432 = 25;
int gi_436 = 60;
int gi_440 = 3;
int gi_444 = 140;
int gi_448 = 2;
int gi_452 = 170;
int gi_456 = 0;
int gi_460 = 200;
int gi_464 = -1;
int gi_468 = 240;
int gi_472 = -4;
double gd_476 = 0.3;
int gi_484 = 5;
int gi_488 = 53;
int gi_492 = 25;
int gi_496 = 75;
int gi_500 = 3;
int gi_504 = 100;
int gi_508 = 2;
int gi_512 = 135;
int gi_516 = 0;
int gi_520 = 210;
int gi_524 = -1;
int gi_528 = 245;
int gi_532 = -4;
double gd_536 = 0.2;
int gi_544 = 10;
int gi_548 = 75;
int gi_552 = 75;
int gi_556 = 80;
int gi_560 = 3;
int gi_564 = 145;
int gi_568 = 2;
int gi_572 = 180;
int gi_576 = 0;
int gi_580 = 205;
int gi_584 = -1;
int gi_588 = 250;
int gi_592 = -4;
double gd_596 = 0.15;
int gi_604 = 10;
int gi_608 = 58;
int gi_612 = 23;
int gi_616 = 80;
int gi_620 = 3;
int gi_624 = 145;
int gi_628 = 2;
int gi_632 = 180;
int gi_636 = 0;
int gi_640 = 205;
int gi_644 = -1;
int gi_648 = 250;
int gi_652 = -4;
double gd_656 = 0.35;
int gi_664 = 21;
int gi_668 = 1;
int gi_672 = 50;
int g_period_676 = 8;
int g_period_680 = 6;
int gi_684 = 30;
int g_period_688 = 20;
int gi_692 = 36;
int gi_696 = 20;
int g_period_700 = 5;
int g_applied_price_704 = PRICE_CLOSE;
int g_ma_method_708 = MODE_SMA;
int gi_712 = 4;
int gi_716 = 3;
int gi_720 = 150;
int gi_724 = 21;
int gi_728 = 40;
int gi_732 = 21;
bool gi_736 = TRUE;
int gi_752;
int gi_756;
double gd_760;
double g_maxlot_768;
double g_minlot_776;
double g_lotstep_784;
double gd_792;
double gd_800;
string g_symbol_808;
bool gi_816 = TRUE;
bool gi_820 = TRUE;
int g_datetime_824;
int g_datetime_828;
int g_datetime_832;
int gi_836;
int gi_840;
int gi_844;
int gi_848;
int gi_852;
int gi_856;
int gi_860;
int gi_864;
int gi_868;
int gi_872;
int gi_876;
int gi_880;
int gi_884;
int gi_888;
int gi_892;
int gi_896;
int gi_900;
int gi_904;
int gi_908;
int gi_912;
int gi_916;
int gi_920;
int gi_924;
int gi_928;
double gd_932;
double gd_940;
double gd_948;
double gd_956;
double gd_964;
double gd_972;
double gd_980;
double gd_988;
double gd_996;
double gd_1004;
double gd_1012;
bool gi_1020;
bool gi_1024;
bool gi_1028;
bool gi_1032;
bool gi_1036;
bool gi_1040;
int g_datetime_1044;
int g_datetime_1052;
int gi_1056;
int gi_1060;
double g_icustom_1064;
double g_icustom_1072;
double g_icustom_1080;
double g_digits_1088;
double g_str2dbl_1096;
double g_ifractals_1104;
double g_ifractals_1112;
double g_ima_1120;
double g_ima_1128;
double g_ima_1136;
double g_ima_1144;
double g_ima_1152;
double g_ima_1160;
double gda_1168[];
double gda_1172[];
string g_dbl2str_1176;
string gs_1184;
string gs_1192;
bool gi_1200 = TRUE;

int init() {
   double l_leverage_0;
   string ls_8;
   if (!PrintLogOnChart) Comment("");
   if (!IsDllsAllowed()) {
      Comment("Warning: Set Parameter \"AllowDLL Imports\" ON in menu Tools -> Options -> ExpertAdvisors.");
      gi_736 = FALSE;
      return (0);
   }
   gi_736 = TRUE;
   g_symbol_808 = Symbol();
   if (Digits < 4) {
      gd_760 = 0.01;
      gi_752 = 2;
   } else {
      gd_760 = 0.0001;
      gi_752 = 4;
   }
   g_maxlot_768 = MarketInfo(g_symbol_808, MODE_MAXLOT);
   g_minlot_776 = MarketInfo(g_symbol_808, MODE_MINLOT);
   g_lotstep_784 = MarketInfo(g_symbol_808, MODE_LOTSTEP);
   gd_792 = MarketInfo(g_symbol_808, MODE_MARGINREQUIRED) * g_lotstep_784;
   if (!UseScalperStrategy) {
      if (StringSubstr(g_symbol_808, 0, 6) != "EURUSD" || Period() != PERIOD_M1) {
         Alert("Use Fapturbo system only on EURUSD M1.");
         Print("Use Fapturbo system only on EURUSD M1.");
         Comment("Error: Wrong TimeFrame or Currency Pair! Read instructions!");
         gi_736 = FALSE;
         return (0);
      }
      gi_736 = TRUE;
      if (FapTurbo_StartWorkTimeHour < 0 || FapTurbo_StartWorkTimeHour > 23) FapTurbo_StartWorkTimeHour = 0;
      if (FapTurbo_StartWorkTimeMin < 0 || FapTurbo_StartWorkTimeMin > 59) FapTurbo_StartWorkTimeMin = 0;
      if (FapTurbo_EndWorkTimeHour < 0 || FapTurbo_EndWorkTimeHour > 23) FapTurbo_EndWorkTimeHour = 0;
      if (FapTurbo_EndWorkTimeMin < 0 || FapTurbo_EndWorkTimeMin > 59) FapTurbo_EndWorkTimeMin = 0;
      if (FapTurbo_CloseAfterXmonths < 0) FapTurbo_CloseAfterXmonths = 0;
      if (FapTurbo_CloseAfterXmonths > 12) FapTurbo_CloseAfterXmonths = 12;
      l_leverage_0 = AccountLeverage();
      gd_800 = NormalizeDouble(FapTurbo_LotsRiskReductor * (100 / l_leverage_0), 2);
   } else {
      ls_8 = StringSubstr(g_symbol_808, 0, 6);
      if ((ls_8 != "EURGBP" && ls_8 != "EURCHF" && ls_8 != "GBPCHF" && ls_8 != "USDCAD") || Period() != PERIOD_M15) {
         Alert("Use scalper system only on EURCHF, EURGPB, GBPCHF or USDCAD M15.");
         Print("Use scalper system only on EURCHF, EURGPB, GBPCHF or USDCAD M15.");
         Comment("Error: Wrong TimeFrame or Currency Pair! Read instructions!");
         gi_736 = FALSE;
         return (0);
      }
      gi_736 = TRUE;
      if (ls_8 == "EURGBP") {
         gi_852 = gi_424;
         gi_856 = gi_428;
         gi_860 = gi_432;
         gd_932 = gd_476;
         gi_864 = gi_436;
         gi_872 = gi_444;
         gi_880 = gi_452;
         gi_888 = gi_460;
         gi_896 = gi_468;
         gi_868 = gi_440;
         gi_876 = gi_448;
         gi_884 = gi_456;
         gi_892 = gi_464;
         gi_900 = gi_472;
      } else {
         if (ls_8 == "EURCHF") {
            gi_852 = gi_484;
            gi_856 = gi_488;
            gi_860 = gi_492;
            gd_932 = gd_536;
            gi_864 = gi_496;
            gi_872 = gi_504;
            gi_880 = gi_512;
            gi_888 = gi_520;
            gi_896 = gi_528;
            gi_868 = gi_500;
            gi_876 = gi_508;
            gi_884 = gi_516;
            gi_892 = gi_524;
            gi_900 = gi_532;
         } else {
            if (ls_8 == "GBPCHF") {
               gi_852 = gi_544;
               gi_856 = gi_548;
               gi_860 = gi_552;
               gd_932 = gd_596;
               gi_864 = gi_556;
               gi_872 = gi_564;
               gi_880 = gi_572;
               gi_888 = gi_580;
               gi_896 = gi_588;
               gi_868 = gi_560;
               gi_876 = gi_568;
               gi_884 = gi_576;
               gi_892 = gi_584;
               gi_900 = gi_592;
            } else {
               gi_852 = gi_604;
               gi_856 = gi_608;
               gi_860 = gi_612;
               gd_932 = gd_656;
               gi_864 = gi_616;
               gi_872 = gi_624;
               gi_880 = gi_632;
               gi_888 = gi_640;
               gi_896 = gi_648;
               gi_868 = gi_620;
               gi_876 = gi_628;
               gi_884 = gi_636;
               gi_892 = gi_644;
               gi_900 = gi_652;
            }
         }
      }
      gd_948 = NormalizeDouble((-1 * gi_856) * gd_760, gi_752);
      gd_940 = NormalizeDouble(gi_852 * gd_760, gi_752);
      gi_904 = 60 * gi_864;
      gi_908 = 60 * gi_872;
      gi_912 = 60 * gi_880;
      gi_916 = 60 * gi_888;
      gi_920 = 60 * gi_896;
      gd_956 = gi_868 * gd_760;
      gd_964 = gi_876 * gd_760;
      gd_972 = gi_884 * gd_760;
      gd_980 = gi_892 * gd_760;
      gd_988 = gi_900 * gd_760;
      gd_1012 = NormalizeDouble(gi_860 * gd_760, gi_752);
      gd_996 = (MarketInfo(g_symbol_808, MODE_SPREAD) + 0.1) * Point;
      gd_1004 = NormalizeDouble(gi_856 * gd_760, gi_752);
      gi_836 = 100 - gi_684;
      gi_840 = 100 - gi_692;
      gi_844 = gi_696 / 2 + 50;
      gi_848 = 50 - gi_696 / 2;
      gi_924 = gi_664 + Scalper_GMTOffset;
      gi_928 = gi_668 + Scalper_GMTOffset;
      while (true) {
         if (gi_924 >= 24) {
            gi_924 -= 24;
            continue;
         }
         if (gi_924 >= 0) break;
         gi_924 += 24;
      }
      while (true) {
         if (gi_928 >= 24) {
            gi_928 -= 24;
            continue;
         }
         if (gi_928 >= 0) break;
         gi_928 += 24;
      }
      if (Scalper_PeriodFilterMA <= 0) Scalper_UseFilterMA = FALSE;
      if (Scalper_PriceFilterMA < PRICE_CLOSE || Scalper_PriceFilterMA > PRICE_WEIGHTED) Scalper_UseFilterMA = FALSE;
      if (Scalper_MethodFilterMA < MODE_SMA || Scalper_MethodFilterMA > MODE_LWMA) Scalper_UseFilterMA = FALSE;
      l_leverage_0 = AccountLeverage();
      gd_800 = NormalizeDouble(Scalper_LotsRiskReductor * (100 / l_leverage_0), 2);
   }
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   if (!gi_736) return (0);
   if (!UseScalperStrategy) FapTurbo();
   else Scalper();
   return (0);
}

void FapTurbo() {
   int l_datetime_0;
   bool li_4;
   bool li_8;
   bool li_12;
   bool li_16;
   bool li_20;
   string ls_24;
   int li_36;
   int li_40;
   double l_price_44;
   double l_price_52;
   g_digits_1088 = MarketInfo(g_symbol_808, MODE_DIGITS);
   g_dbl2str_1176 = DoubleToStr(g_str2dbl_1096, g_digits_1088);
   g_str2dbl_1096 = StrToDouble(g_dbl2str_1176);
   if (IsTradeAllowed()) {
      if (IsConnected()) {
         if (IsStopped() == 0) {
            if (IsTradeContextBusy()) {
               Print("Trade context is busy!");
               return;
            }
            if (IsDateTimeEnabled(TimeCurrent())) {
               if (CheckParams() > 0 ) {
                  if (PrepareIndicators()>0) {
                     l_datetime_0 = iTime(NULL, PERIOD_D1, 0);
                     if (g_datetime_1052 != l_datetime_0) {
                        g_datetime_1052 = l_datetime_0;
                        gs_1192 = "";
                        if (WriteLog) Print("---------------------- Start New Daily Bar: ", TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS), " ----------------------");
                        if (WriteDebugLog) PrintDebugLog();
                        gi_1024 = FALSE;
                        gi_1028 = FALSE;
                        gi_1032 = FALSE;
                        gi_1036 = FALSE;
                        if (FapTurbo_FixedDirection != 0) gi_1040 = TRUE;
                        li_4 = TRUE;
                        li_8 = TRUE;
                        li_12 = FALSE;
                        li_16 = TRUE;
                        li_20 = FALSE;
                        if (!Rule1(0)) {
                           ls_24 = "Critical Day. Expected Cross in " + gi_1056 + " days.";
                           gs_1192 = gs_1192 + ls_24 
                           + "\n";
                           if (WriteLog) Print(ls_24);
                           li_4 = FALSE;
                        } else {
                           if (!Relax1()) {
                              ls_24 = "Relax Days Left = " + gi_1060 + " (after Cross).";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              li_4 = FALSE;
                           } else {
                              ls_24 = "NO Expected Cross. -> Possible to trade.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                           }
                        }
                        if (!Rule2(0)) {
                           if (FapTurbo_Prudent != 0) {
                              ls_24 = "Prudent Day. No Trading.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              li_8 = FALSE;
                           } else {
                              ls_24 = "Prudent Day Trading.";
                              if (FapTurbo_SymAlligatorOnCritica != 0) {
                                 ls_24 = ls_24 + " Trading SymAlligator today.";
                                 gi_1024 = TRUE;
                              } else ls_24 = ls_24 + " Simple Trading today.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              gi_1028 = TRUE;
                              li_12 = TRUE;
                           }
                        } else {
                           if (!Relax2()) {
                              ls_24 = "Relax Days Left = " + gi_1060 + " (after Prudent).";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              li_8 = FALSE;
                           } else {
                              ls_24 = "NO Prudent Day. -> Possible to trade.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                           }
                        }
                        if (!Rule3(0)) {
                           gi_1040 = FALSE;
                           ls_24 = "TooGoodToBeTrue Day (Start from " + TimeToStr(iTime(NULL, PERIOD_D1, gi_1060), TIME_DATE) + ").";
                           if (FapTurbo_Prudent != 0) {
                              ls_24 = ls_24 + " No Trading.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              li_16 = FALSE;
                           } else {
                              if (FapTurbo_SymAlligatorOnCritica != 0) {
                                 ls_24 = ls_24 + " Trading SymAlligator today.";
                                 gi_1024 = TRUE;
                              } else ls_24 = ls_24 + " Simple Trading today.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              gi_1028 = TRUE;
                              li_20 = TRUE;
                           }
                        } else {
                           if (!Relax3()) {
                              gi_1040 = FALSE;
                              ls_24 = "Prudent Period TooGoodToBeTrue day left = " + gi_1060 + ".";
                              if (FapTurbo_Prudent != 0) {
                                 ls_24 = ls_24 + " No Trading.";
                                 gs_1192 = gs_1192 + ls_24 
                                 + "\n";
                                 if (WriteLog) Print(ls_24);
                                 li_16 = FALSE;
                              } else {
                                 if (FapTurbo_SymAlligatorOnCritica != 0) {
                                    ls_24 = ls_24 + " Trading SymAlligator today.";
                                    gi_1024 = TRUE;
                                 } else ls_24 = ls_24 + " Simple Trading today.";
                                 gs_1192 = gs_1192 + ls_24 
                                 + "\n";
                                 if (WriteLog) Print(ls_24);
                                 gi_1028 = TRUE;
                                 li_20 = TRUE;
                              }
                           } else {
                              ls_24 = "NO TooGoodToBeTrue Day. -> Possible to trade.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                           }
                        }
                        if (li_4 && li_8 && !li_12 && li_16 && !li_20) {
                           ls_24 = "Simple Trading Day.";
                           gs_1192 = gs_1192 + ls_24 
                           + "\n";
                           if (WriteLog) Print(ls_24);
                           gi_1028 = TRUE;
                           gi_1020 = TRUE;
                           gi_1032 = FALSE;
                        } else {
                           if (FapTurbo_AlwaysTrade != 0) {
                              gi_1032 = TRUE;
                              gi_1024 = TRUE;
                              ls_24 = "AlwaysTrade: Trading SymAlligator today with LowLot.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                           }
                        }
                        if (li_12 || li_20) gi_1020 = TRUE;
                        if (!li_4 || !li_8 || !li_16) gi_1020 = FALSE;
                        if (FapTurbo_TradeNFP == 0) {
                           if (TimeDayOfWeek(l_datetime_0) == 5 && TimeDay(l_datetime_0) <= 7) {
                              ls_24 = "Does not trade on the first Friday of month.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              gi_1036 = TRUE;
                           }
                        }
                        if (FapTurbo_TradeFriday == 0) {
                           if (TimeDayOfWeek(l_datetime_0) == 5) {
                              ls_24 = "Does not trade on the Friday.";
                              gs_1192 = gs_1192 + ls_24 
                              + "\n";
                              if (WriteLog) Print(ls_24);
                              gi_1036 = TRUE;
                           }
                        }
                        if (gi_1036) ls_24 = "The final resolution: NO TRADE today.";
                        else {
                           if (!gi_1020) {
                              if (!gi_1032) ls_24 = "The final resolution: NO TRADE today.";
                              else ls_24 = "The final resolution: to TRADE WITH LOWLOT today.";
                           } else ls_24 = "The final resolution: to TRADE today.";
                        }
                        gs_1192 = gs_1192 + ls_24;
                        if (WriteLog) {
                           Print(ls_24);
                           Print("------------------------------------------------------------------------------------------------");
                        }
                     }
                     if (PrintLogOnChart) {
                        Comment("" 
                           + "\n" 
                           + "FapTurbo" 
                           + "\n" 
                           + "------------------------------------------------" 
                           + "\n" 
                           + "BROKER INFORMATION:" 
                           + "\n" 
                           + "Broker Company:      " + AccountCompany() 
                           + "\n" 
                           + "------------------------------------------------" 
                           + "\n" 
                           + "ACCOUNT INFORMATION:" 
                           + "\n" 
                           + "Account Name:          " + AccountName() 
                           + "\n" 
                           + "Account Number:       " + AccountNumber() 
                           + "\n" 
                           + "Account Leverage:     " + DoubleToStr(AccountLeverage(), 0) 
                           + "\n" 
                           + "Account Balance:       " + DoubleToStr(AccountBalance(), 2) 
                           + "\n" 
                           + "Account Currency:     " + AccountCurrency() 
                           + "\n" 
                           + "Account Equity:         " + DoubleToStr(AccountEquity(), 2) 
                           + "\n" 
                           + "------------------------------------------------" 
                           + "\n" 
                           + "MARGIN INFORMATION:" 
                           + "\n" 
                           + "Free Margin:              " + DoubleToStr(AccountFreeMargin(), 2) 
                           + "\n" 
                           + "Used Margin:              " + DoubleToStr(AccountMargin(), 2) 
                           + "\n" 
                           + "------------------------------------------------" 
                           + "\n" 
                           + "Actual Server Time     " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
                           + "\n" 
                           + "------------------------------------------------" 
                           + "\n" 
                           + "STRATEGY INFORMATION:" 
                           + "\n" 
                           + gs_1192 
                           + "\n" 
                           + "------------------------------------------------" 
                           + "\n" 
                           + "DEBUG INFORMATION:" 
                           + "\n" 
                           + "lastMALarge = " + DoubleToStr(g_ima_1128, gi_752) + ",  prevMALarge = " + DoubleToStr(g_ima_1120, gi_752) + ",  farMALarge = " + DoubleToStr(g_ima_1152, gi_752) 
                           + "\n" 
                        + "lastMASmall = " + DoubleToStr(g_ima_1144, gi_752) + ",  prevMASmall = " + DoubleToStr(g_ima_1136, gi_752) + ",  farMASmall = " + DoubleToStr(g_ima_1160, gi_752));
                     }
                     li_36 = CalculateCurrentOrders();
                     if (li_36 > 0) {
                        for (int li_32 = li_36 - 1; li_32 >= 0; li_32--) {
                           if (GetOrderByPos(li_32)) {
                              if (OrderMagicNumber() == MagicNumber) {
                                 if (TradeSignalCloseOrder() || TradeSignalCloseOrderOnTime(li_32)) CloseOrder(OrderTicket(), OrderLots(), OrderType(), FapTurbo_SlipPage + 10);
                                 else {
                                    if (FapTurbo_TakeProfit != 0.0 && NormalizeDouble(OrderTakeProfit(), gi_752) == 0.0) {
                                       if (OrderType() == OP_BUY) {
                                          li_40 = NormalizeDouble((OrderClosePrice() - OrderOpenPrice()) / gd_760, gi_752);
                                          l_price_44 = NormalizeDouble(OrderOpenPrice() + FapTurbo_TakeProfit * gd_760, gi_752);
                                       } else {
                                          li_40 = NormalizeDouble((OrderOpenPrice() - OrderClosePrice()) / gd_760, gi_752);
                                          l_price_44 = NormalizeDouble(OrderOpenPrice() - FapTurbo_TakeProfit * gd_760, gi_752);
                                       }
                                       if (li_40 >= FapTurbo_TakeProfit) {
                                          gs_1184 = "Price at level TakeProfit.";
                                          CloseOrder(OrderTicket(), OrderLots(), OrderType(), FapTurbo_SlipPage + 10);
                                          return;
                                       }
                                       if (FapTurbo_TakeProfit * gd_760 > MarketInfo(g_symbol_808, MODE_STOPLEVEL) * Point) {
                                          while (!IsTradeAllowed()) Sleep(1000);
                                          OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_44, 0, Red);
                                       }
                                    }
                                    if (FapTurbo_StopLoss != 0.0 && NormalizeDouble(OrderStopLoss(), gi_752) == 0.0) {
                                       if (OrderType() == OP_BUY) {
                                          li_40 = NormalizeDouble((OrderClosePrice() - OrderOpenPrice()) / gd_760, gi_752);
                                          l_price_52 = NormalizeDouble(OrderOpenPrice() - FapTurbo_StopLoss * gd_760, gi_752);
                                       } else {
                                          li_40 = NormalizeDouble((OrderOpenPrice() - OrderClosePrice()) / gd_760, gi_752);
                                          l_price_52 = NormalizeDouble(OrderOpenPrice() + FapTurbo_StopLoss * gd_760, gi_752);
                                       }
                                       if (li_40 <= -1.0 * FapTurbo_StopLoss) {
                                          gs_1184 = "Price at level StopLoss.";
                                          CloseOrder(OrderTicket(), OrderLots(), OrderType(), FapTurbo_SlipPage + 10);
                                          return;
                                       }
                                       if (FapTurbo_StopLoss * gd_760 > MarketInfo(g_symbol_808, MODE_STOPLEVEL) * Point) {
                                          while (!IsTradeAllowed()) Sleep(1000);
                                          OrderModify(OrderTicket(), OrderOpenPrice(), l_price_52, OrderTakeProfit(), 0, Red);
                                       }
                                    }
                                    if (FapTurbo_TrailingStop > 0.0) TrailOrderStop();
                                 }
                              }
                           }
                        }
                        if (li_36 < FapTurbo_MaxOrders)
                           if ((TimeCurrent() - g_datetime_1044) / 60 >= FapTurbo_StopTime) TrueOpen();
                     } else TrueOpen();
                  }
               }
            }
         }
      }
   }
}

int CalculateCurrentOrders() {
   int li_ret_0;
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))
         if (OrderMagicNumber() == MagicNumber && OrderSymbol() == g_symbol_808) li_ret_0++;
   }
   return (li_ret_0);
}

int TrueOpen() {
   int li_4;
   int li_8;
   double l_minlot_12;
   double l_minlot_20;
   double ld_28;
   if (!IsTradeTime(TimeCurrent())) return (0);
   int li_0 = TradeSignalOpenOrder();
   if (li_0 == 0) return (0);
   if (FapTurbo_OneTrade != 0) {
      if (HaveTrade()) {
         if (WriteDebugLog) Print("Already have one trade inside this interval of time.");
         return (0);
      }
   }
   if (FapTurbo_Hedging != 0) {
      li_4 = FapTurbo_MaxOrders / 2;
      if (FapTurbo_MaxOrders % 2 != 0) li_4++;
      if (li_0 == 1) {
         li_8 = HavePositions(OP_BUY);
         if (li_8 >= li_4) {
            if (WriteLog) Print("Hedging: already there are open " + li_8 + " orders. The signal to BUY is blocked.");
            return (0);
         }
      } else {
         li_8 = HavePositions(OP_SELL);
         if (li_8 >= li_4) {
            if (WriteLog) Print("Hedging: already there are open " + li_8 + " orders. The signal to SELL is blocked.");
            return (0);
         }
      }
   }
   if (FapTurbo_HedgingLotReducer != 0.0) {
      if (li_0 == 1) l_minlot_12 = NormalizeDouble(OpenPosVol(OP_BUY) / FapTurbo_HedgingLotReducer, 2);
      else l_minlot_12 = NormalizeDouble(OpenPosVol(OP_SELL) / FapTurbo_HedgingLotReducer, 2);
      if (l_minlot_12 != 0.0) {
         l_minlot_20 = MarketInfo(g_symbol_808, MODE_MINLOT);
         if (l_minlot_12 < l_minlot_20) l_minlot_12 = l_minlot_20;
         if (!gi_1032) {
            ld_28 = l_minlot_12;
            if (WriteLog) Print("HedgingLot: the order will be open by the reduced lots.");
         } else {
            if (l_minlot_12 > FapTurbo_LowLot) {
               ld_28 = FapTurbo_LowLot;
               if (WriteLog) Print("HedgingLot: the reduced lots more than LowLot, the order will be open by the LowLot lots.");
            } else {
               ld_28 = l_minlot_12;
               if (WriteLog) Print("HedgingLot: the order will be open by the reduced lots.");
            }
         }
      } else {
         if (!gi_1032) ld_28 = CalcLotsVolume();
         else ld_28 = FapTurbo_LowLot;
      }
   } else {
      if (!gi_1032) ld_28 = CalcLotsVolume();
      else ld_28 = FapTurbo_LowLot;
   }
   if (ld_28 == 0.0 || !CheckAccount(DirectionOrderType(li_0), ld_28)) return (0);
   int li_36 = OpenOrder(li_0, ld_28, FapTurbo_ExpertComment);
   return (0);
}

int CheckParams() {
   if (Bars < 100) {
      Print("Bars less than 100");
      return (0);
   }
   if (FapTurbo_TakeProfit < 10.0) {
      Print("FapTurbo_TakeProfit is less than 10");
      return (0);
   }
   if (FapTurbo_Lots <= 0.0 && FapTurbo_LotsRiskReductor < 0.0) {
      Print("FapTurbo_LotsRiskReductor is less than 0");
      return (0);
   }
   return (1);
}

bool CheckAccount(int a_cmd_0, double ad_4) {
   bool li_ret_12 = TRUE;
   double ld_16 = AccountFreeMarginCheck(g_symbol_808, a_cmd_0, ad_4);
   if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) li_ret_12 = FALSE;
   if (!li_ret_12) Print("No money to open more orders.", " Lot=", ad_4, " Free Margin = ", AccountFreeMargin(), " Balance = ", AccountBalance());
   return (li_ret_12);
}

double CalcLotsVolume() {
   double ld_ret_0;
   if (FapTurbo_Lots > 0.0) ld_ret_0 = NormalizeLot(FapTurbo_Lots, 0, "");
   else {
      ld_ret_0 = NormalizeDouble(MathFloor(AccountFreeMargin() * gd_800 / 100.0 / gd_792) * g_lotstep_784, 2);
      if (ld_ret_0 < g_minlot_776) ld_ret_0 = g_minlot_776;
      if (ld_ret_0 > g_maxlot_768) ld_ret_0 = g_maxlot_768;
   }
   if (ld_ret_0 > FapTurbo_MaxLots) ld_ret_0 = FapTurbo_MaxLots;
   return (ld_ret_0);
}

int PrepareIndicators() {
   double l_ifractals_20;
   g_icustom_1064 = iCustom(NULL, 0, "Alligator", 13, 8, 8, 5, 5, 3, 0, 0);
   g_icustom_1072 = iCustom(NULL, 0, "Alligator", 13, 8, 8, 5, 5, 3, 1, 0);
   g_icustom_1080 = iCustom(NULL, 0, "Alligator", 13, 8, 8, 5, 5, 3, 2, 0);
   int li_8 = 3;
   g_ifractals_1104 = 0;
   g_ifractals_1112 = 0;
   for (int li_4 = 0; li_4 <= li_8; li_4++) {
      l_ifractals_20 = iFractals(NULL, 0, MODE_LOWER, li_4);
      if (l_ifractals_20 != 0.0) g_ifractals_1104 = l_ifractals_20;
      l_ifractals_20 = iFractals(NULL, 0, MODE_UPPER, li_4);
      if (l_ifractals_20 != 0.0) g_ifractals_1112 = l_ifractals_20;
   }
   li_8 = 0;
   ArrayResize(gda_1168, li_8 + 1);
   ArrayResize(gda_1172, li_8 + 1);
   for (li_4 = 0; li_4 <= li_8; li_4++) {
      gda_1168[li_4] = iDeMarker(NULL, 0, FapTurbo_aaa, li_4);
      gda_1172[li_4] = (-iWPR(NULL, 0, FapTurbo_bbb, li_4 + 1)) / 100.0;
   }
   g_ima_1120 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_ShiftMALarge);
   g_ima_1128 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, 0);
   g_ima_1136 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_ShiftMASmall);
   g_ima_1144 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, 0);
   g_ima_1152 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_LookForDays + FapTurbo_ShiftMALarge);
   g_ima_1160 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_LookForDays + FapTurbo_ShiftMASmall);
   return (1);
}

int TradeSignalOpenOrder() {
   int li_ret_0 = fun1(gi_1036, gi_1020, g_ima_1120, g_ima_1128, gi_1032, gi_1024, IsGatorActiveUp(), IsGatorActiveDown(), WasWPROverBuy(), WasWPROverSell(), IsFractalLower(), IsFractalUpper(), WasDemarkerHigh(), WasDemarkerLow());
   if (li_ret_0 == 0) return (0);
   if (gi_1040) {
      if (li_ret_0 == 1) {
         if (g_ima_1120 > g_ima_1128 && g_ima_1136 > g_ima_1144) li_ret_0 = 0;
         else
            if (WriteLog) Print("Filter FixedDirection allow a signal to BUY.");
      } else {
         if (g_ima_1120 < g_ima_1128 && g_ima_1136 < g_ima_1144) li_ret_0 = 0;
         else
            if (WriteLog) Print("Filter FixedDirection allow a signal to SELL.");
      }
   }
   if (li_ret_0 == 0) return (0);
   if (gi_1028 && WriteLog) {
      if (IsGatorActiveUp()) Print("Alligator on BUY.");
      else Print("Alligator on SELL.");
   }
   if (WriteDebugLog) PrintDebugLog();
   return (li_ret_0);
}

int TradeSignalCloseOrder() {
   if (FapTurbo_ClsLsrOnMrktChnge != 0) {
      if (OrderProfit() < 0.0 && TimeDay(OrderOpenTime()) != TimeDay(Time[0])) {
         if (OrderType() == OP_BUY) {
            if (g_ima_1136 > g_ima_1144) {
               if (WriteDebugLog) PrintDebugLog();
               gs_1184 = "MASmall going down.";
               return (1);
            }
         } else {
            if (g_ima_1136 < g_ima_1144) {
               if (WriteDebugLog) PrintDebugLog();
               gs_1184 = "MASmall going up.";
               return (1);
            }
         }
      }
   }
   return (!IsOrderProfitable());
}

double NormalizeLot(double ad_0, bool ai_8 = FALSE, string a_symbol_12 = "") {
   double ld_ret_20;
   double ld_28;
   if (a_symbol_12 == "" || a_symbol_12 == "0") a_symbol_12 = g_symbol_808;
   double l_lotstep_36 = MarketInfo(a_symbol_12, MODE_LOTSTEP);
   double l_minlot_44 = MarketInfo(a_symbol_12, MODE_MINLOT);
   double l_maxlot_52 = MarketInfo(a_symbol_12, MODE_MAXLOT);
   if (l_minlot_44 == 0.0) l_minlot_44 = 0.1;
   if (l_maxlot_52 == 0.0) l_maxlot_52 = 100;
   if (l_lotstep_36 > 0.0) ld_28 = 1 / l_lotstep_36;
   else ld_28 = 1 / l_minlot_44;
   if (ai_8) ld_ret_20 = MathCeil(ad_0 * ld_28) / ld_28;
   else ld_ret_20 = MathFloor(ad_0 * ld_28) / ld_28;
   if (ld_ret_20 < l_minlot_44) ld_ret_20 = l_minlot_44;
   if (ld_ret_20 > l_maxlot_52) ld_ret_20 = l_maxlot_52;
   return (ld_ret_20);
}

int TradeSignalCloseOrderOnTime(int ai_unused_0) {
   int l_month_4;
   int li_8;
   if (FapTurbo_DurationInHours > 0) {
      if (TimeCurrent() - OrderOpenTime() >= 3600 * FapTurbo_DurationInHours) {
         gs_1184 = "Limite duration of open position, after " + FapTurbo_DurationInHours + " hours.";
         return (1);
      }
   }
   if (FapTurbo_CloseAfterXmonths > 0) {
      l_month_4 = TimeMonth(OrderOpenTime());
      li_8 = TimeMonth(TimeCurrent());
      if (l_month_4 != li_8) {
         if (l_month_4 > li_8) li_8 += 12;
         if (li_8 - l_month_4 >= FapTurbo_CloseAfterXmonths) {
            gs_1184 = "Start new month, after " + FapTurbo_CloseAfterXmonths + " months.";
            return (1);
         }
      }
   }
   return (0);
}

bool IsDateTimeEnabled(int ai_0) {
   int l_day_of_year_4 = TimeDayOfYear(ai_0);
   int l_day_of_week_8 = TimeDayOfWeek(ai_0);
   return (l_day_of_week_8 > 0 && l_day_of_week_8 < 6 && l_day_of_year_4 > 7 && l_day_of_year_4 < 360);
}

bool IsGatorActiveUp() {
   return (g_icustom_1080 - g_icustom_1072 >= FapTurbo_SpanGator * gd_760 && g_icustom_1072 - g_icustom_1064 >= FapTurbo_SpanGator * gd_760 && g_icustom_1080 - g_icustom_1064 >= FapTurbo_SpanGator * gd_760);
}

int IsGatorActiveDown() {
   return (g_icustom_1072 - g_icustom_1080 >= FapTurbo_SpanGator * gd_760 && g_icustom_1064 - g_icustom_1072 >= FapTurbo_SpanGator * gd_760 && g_icustom_1064 - g_icustom_1080 >= FapTurbo_SpanGator * gd_760);
}

int IsFractalLower() {
   return (g_ifractals_1104 != 0.0);
}

int IsFractalUpper() {
   return (g_ifractals_1112 != 0.0);
}

bool IsOrderProfitable() {
   return (TRUE);
}

int WasDemarkerLow() {
   return (ArrayMinValue(gda_1168) < 0.5);
}

int WasDemarkerHigh() {
   return (ArrayMaxValue(gda_1168) > 0.5);
}

int WasWPROverBuy() {
   return (ArrayMinValue(gda_1172) <= 0.25);
}

int WasWPROverSell() {
   return (ArrayMaxValue(gda_1172) >= 0.75);
}

int OpenOrder(int ai_0, double a_lots_4, string a_comment_12 = "") {
   int l_color_48;
   double l_price_28 = 0;
   double l_price_36 = 0;
   double l_price_20 = PriceOpen(ai_0);
   l_price_36 = l_price_20 + FapTurbo_TakeProfit * gd_760 * ai_0;
   if (FapTurbo_StopLoss > 0.0) l_price_28 = PriceClose(ai_0) - FapTurbo_StopLoss * gd_760 * ai_0;
   int l_ticket_44 = OrderSend(g_symbol_808, DirectionOrderType(ai_0), a_lots_4, l_price_20, FapTurbo_SlipPage, 0, 0, a_comment_12, MagicNumber, 0, ColorOpen(ai_0));
   Sleep(1000);
   if (l_ticket_44 >= 0) {
      l_color_48 = MarketInfo(g_symbol_808, MODE_STOPLEVEL) * Point;
      if (FapTurbo_TakeProfit * gd_760 > l_color_48 || FapTurbo_TakeProfit == 0.0)
         if (FapTurbo_StopLoss * gd_760 > l_color_48 || FapTurbo_StopLoss == 0.0) OrderModify(l_ticket_44, l_price_20, l_price_28, l_price_36, 0, Red);
      g_datetime_1044 = iTime(g_symbol_808, 0, 0);
   } else IsError("Error at opening: ");
   return (0);
}

bool GetOrderByPos(int a_pos_0) {
   return (OrderSelect(a_pos_0, SELECT_BY_POS, MODE_TRADES) && OrderType() <= OP_SELL && OrderSymbol() == g_symbol_808);
}

void TrailOrderStop() {
   int li_0;
   double ld_4;
   double ld_12;
   double l_price_20;
   double ld_28;
   double ld_36;
   int li_44;
   if (OrderTicket() > 0) {
      li_0 = OrderTypeDirection();
      ld_4 = NormalizeDouble(FapTurbo_TrailingStop * gd_760 * li_0, gi_752);
      ld_12 = NormalizeDouble(iif(li_0 > 0 || OrderStopLoss() != 0.0, OrderStopLoss(), C'0x3F,0x42,0x0F'), gi_752);
      l_price_20 = NormalizeDouble(PriceClose(li_0) - ld_4, gi_752);
      ld_28 = NormalizeDouble(l_price_20 - OrderOpenPrice(), gi_752);
      ld_36 = NormalizeDouble(l_price_20 - ld_12, gi_752);
      if (ld_28 * li_0 > 0.0 && ld_36 * li_0 >= gd_760) {
         if (OrderType() == OP_BUY) li_44 = (Bid - l_price_20) / gd_760;
         else li_44 = (l_price_20 - Ask) / gd_760;
         if (li_44 > MarketInfo(g_symbol_808, MODE_STOPLEVEL) * Point) {
            while (!IsTradeAllowed()) Sleep(1000);
            OrderModify(OrderTicket(), OrderOpenPrice(), l_price_20, OrderTakeProfit(), 0, ColorOpen(li_0));
         }
      }
   }
}

int OrderTypeDirection() {
   int li_ret_0 = 0;
   if (OrderType() == OP_BUY) li_ret_0 = 1;
   if (OrderType() == OP_SELL) li_ret_0 = -1;
   return (li_ret_0);
}

int DirectionOrderType(int ai_0) {
   return (iif(ai_0 > 0, 0, 1));
}

int ColorOpen(int ai_0) {
   return (iif(ai_0 > 0, ColorBuy, ColorSell));
}

double PriceOpen(int ai_0) {
   return (iif(ai_0 > 0, Ask, Bid));
}

double PriceClose(int ai_0) {
   return (iif(ai_0 > 0, Bid, Ask));
}

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

int IsError(string as_0 = "Raptor V1") {
   int l_error_8 = GetLastError();
   bool li_ret_12 = l_error_8 > 1/* NO_RESULT */;
   if (li_ret_12) Print(as_0, " error = ", l_error_8, "; desc = ", ErrorDescription(l_error_8));
   return (li_ret_12);
}

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 (never returned error)";
      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 (never returned error)";
      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 147:
      ls_ret_4 = "expirations are denied by broker";
      break;
   case 148:
      ls_ret_4 = "amount of open and pending orders has reached the limit";
      break;
   case 4000:
      ls_ret_4 = "no error (never generated code)";
      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 in the expert properties";
      break;
   case 4110:
      ls_ret_4 = "longs are not allowed in the expert properties";
      break;
   case 4111:
      ls_ret_4 = "shorts are not allowed in the expert properties";
      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);
}

double ArrayMinValue(double ada_0[]) {
   return (ada_0[ArrayMinimum(ada_0)]);
}

double ArrayMaxValue(double ada_0[]) {
   return (ada_0[ArrayMaximum(ada_0)]);
}

bool Rule1(int ai_0) {
   if (FapTurbo_CriticalDays <= 0) return (TRUE);
   double l_ima_4 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_ShiftMALarge + ai_0);
   double l_ima_12 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_LookForDays + FapTurbo_ShiftMALarge + ai_0);
   double l_ima_20 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_ShiftMASmall + ai_0);
   double l_ima_28 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_LookForDays + FapTurbo_ShiftMASmall + ai_0);
   double ld_36 = (l_ima_4 - l_ima_12) / FapTurbo_LookForDays;
   double ld_44 = l_ima_4 + ld_36;
   double ld_52 = (l_ima_20 - l_ima_28) / FapTurbo_LookForDays;
   double ld_60 = l_ima_20 + ld_52;
   gi_1056 = (ld_60 - ld_44) / (ld_36 - ld_52);
   if (gi_1056 > 0 && gi_1056 < FapTurbo_CriticalDays) return (FALSE);
   return (TRUE);
}

bool Rule2(int ai_0) {
   double l_ima_4 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_ShiftMASmall + ai_0);
   double l_ima_12 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, ai_0);
   double l_ima_20 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, FapTurbo_ShiftMALarge + ai_0);
   double l_ima_28 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, ai_0);
   if ((l_ima_20 > l_ima_28 && l_ima_4 < l_ima_12) || (l_ima_20 < l_ima_28 && l_ima_4 > l_ima_12)) return (FALSE);
   return (TRUE);
}

bool Rule3(int ai_0) {
   if (FapTurbo_TooGoodToBeTrue <= 0) return (TRUE);
   gi_1060 = 0;
   double ld_4 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, ai_0 + 1), gi_752);
   double ld_12 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, ai_0), gi_752);
   double ld_20 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, ai_0 + 1), gi_752);
   double ld_28 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, ai_0), gi_752);
   bool li_ret_36 = TRUE;
   if (ld_4 > ld_12 && ld_20 > ld_28) {
      for (int li_40 = ai_0; li_40 < Bars; li_40++) {
         ld_4 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40 + 1), gi_752);
         ld_12 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40), gi_752);
         ld_20 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40 + 1), gi_752);
         ld_28 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40), gi_752);
         if (ld_4 < ld_12 || ld_20 < ld_28) break;
      }
      gi_1060 = ai_0 + li_40;
   } else {
      if (ld_4 < ld_12 && ld_20 < ld_28) {
         for (li_40 = ai_0; li_40 < Bars; li_40++) {
            ld_4 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40 + 1), gi_752);
            ld_12 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40), gi_752);
            ld_20 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40 + 1), gi_752);
            ld_28 = NormalizeDouble(iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_40), gi_752);
            if (ld_4 > ld_12 || ld_20 > ld_28) break;
         }
         gi_1060 = ai_0 + li_40;
      } else return (li_ret_36);
   }
   if (FapTurbo_TooGoodToBeTrue <= gi_1060) li_ret_36 = FALSE;
   return (li_ret_36);
}

int Rule31(int ai_0) {
   double l_ima_12;
   double l_ima_20;
   double l_ima_28;
   double l_ima_36;
   if (FapTurbo_TooGoodToBeTrue <= 0) return (1);
   bool li_4 = TRUE;
   for (int li_8 = ai_0; li_8 < FapTurbo_TooGoodToBeTrue + ai_0; li_8++) {
      l_ima_12 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_8 + 1);
      l_ima_20 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMASmall, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_8);
      l_ima_28 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_8 + 1);
      l_ima_36 = iMA(NULL, PERIOD_D1, FapTurbo_PeriodMALarge, 0, FapTurbo_TypeMA_0_3, FapTurbo_PriceMA_0_6, li_8);
      if ((l_ima_12 > l_ima_20 && l_ima_28 < l_ima_36) || (l_ima_12 < l_ima_20 && l_ima_28 > l_ima_36)) li_4 = FALSE;
   }
   if (li_4) return (0);
   return (1);
}

bool Relax1() {
   if (FapTurbo_RelaxDays <= 0) return (TRUE);
   for (int li_0 = 1; li_0 < FapTurbo_RelaxDays + 1; li_0++)
      if (!(Rule1(li_0))) break;
   gi_1060 = FapTurbo_RelaxDays + 1 - li_0;
   if (gi_1060 == 0) return (TRUE);
   return (FALSE);
}

bool Relax2() {
   if (FapTurbo_RelaxDays <= 0 || FapTurbo_Prudent == 0) return (TRUE);
   for (int li_0 = 1; li_0 < FapTurbo_RelaxDays + 1; li_0++)
      if (!(Rule2(li_0))) break;
   gi_1060 = FapTurbo_RelaxDays + 1 - li_0;
   if (gi_1060 == 0) return (TRUE);
   return (FALSE);
}

bool Relax3() {
   if (FapTurbo_TooGoodToBeTrue <= 0) return (TRUE);
   if (FapTurbo_PrudentPeriod <= 0) return (TRUE);
   for (int li_0 = 1; li_0 < FapTurbo_PrudentPeriod + 1; li_0++)
      if (!(Rule31(li_0))) break;
   gi_1060 = FapTurbo_PrudentPeriod + 1 - li_0;
   if (gi_1060 == 0) return (TRUE);
   return (FALSE);
}

void PrintDebugLog() {
   Print("lastMALarge = ", g_ima_1128, ",  prevMALarge = ", g_ima_1120, ",  farMALarge = ", g_ima_1152);
   Print("lastMASmall = ", g_ima_1144, ",  prevMASmall = ", g_ima_1136, ",  farMASmall = ", g_ima_1160);
}

int HavePositions(int a_cmd_0) {
   int l_count_4 = 0;
   int l_ord_total_8 = OrdersTotal();
   for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) {
      if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
      if (OrderMagicNumber() == MagicNumber) {
         if (OrderType() == a_cmd_0)
            if (OrderSymbol() == g_symbol_808) l_count_4++;
      }
   }
   return (l_count_4);
}

double OpenPosVol(int a_cmd_0) {
   int l_datetime_24;
   double l_ord_lots_4 = 0;
   int l_datetime_12 = -2147483648;
   int l_ord_total_16 = OrdersTotal();
   for (int l_pos_20 = 0; l_pos_20 < l_ord_total_16; l_pos_20++) {
      if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
      if (OrderMagicNumber() == MagicNumber) {
         if (OrderType() == a_cmd_0) {
            if (OrderSymbol() == g_symbol_808) {
               l_datetime_24 = OrderOpenTime();
               if (l_datetime_24 > l_datetime_12) {
                  l_datetime_12 = l_datetime_24;
                  l_ord_lots_4 = OrderLots();
               }
            }
         }
      }
   }
   return (l_ord_lots_4);
}

bool IsTradeTime(int ai_0) {
   int li_12;
   int li_16;
   int l_hour_4 = TimeHour(ai_0);
   int l_minute_8 = TimeMinute(ai_0);
   if (FapTurbo_StartWorkTimeHour == FapTurbo_EndWorkTimeHour && FapTurbo_StartWorkTimeMin == FapTurbo_EndWorkTimeMin) return (TRUE);
   if (FapTurbo_EndWorkTimeMin == 0) {
      if (FapTurbo_EndWorkTimeHour == 0) li_12 = 23;
      else li_12 = FapTurbo_EndWorkTimeHour - 1;
      li_16 = 59;
   } else {
      li_12 = FapTurbo_EndWorkTimeHour;
      li_16 = FapTurbo_EndWorkTimeMin - 1;
   }
   if (FapTurbo_StartWorkTimeHour == li_12) {
      if (FapTurbo_StartWorkTimeMin == li_16) return (TRUE);
      if (FapTurbo_StartWorkTimeMin < li_16) {
         if (l_hour_4 != FapTurbo_StartWorkTimeHour) return (FALSE);
         if (l_minute_8 < FapTurbo_StartWorkTimeMin || l_minute_8 > li_16) return (FALSE);
         return (TRUE);
      }
      if (FapTurbo_StartWorkTimeMin > li_16) {
         if (l_hour_4 == FapTurbo_StartWorkTimeHour)
            if (l_minute_8 < FapTurbo_StartWorkTimeMin && l_minute_8 > li_16) return (FALSE);
         return (TRUE);
      }
   }
   if (FapTurbo_StartWorkTimeHour < li_12) {
      if (l_hour_4 < FapTurbo_StartWorkTimeHour || l_hour_4 > li_12) return (FALSE);
      if (l_hour_4 == FapTurbo_StartWorkTimeHour && l_minute_8 < FapTurbo_StartWorkTimeMin) return (FALSE);
      if (l_hour_4 == li_12 && l_minute_8 > li_16) return (FALSE);
      return (TRUE);
   }
   if (FapTurbo_StartWorkTimeHour > li_12) {
      if (l_hour_4 < FapTurbo_StartWorkTimeHour && l_hour_4 > li_12) return (FALSE);
      if (l_hour_4 == FapTurbo_StartWorkTimeHour && l_minute_8 < FapTurbo_StartWorkTimeMin) return (FALSE);
      if (l_hour_4 == li_12 && l_minute_8 > li_16) return (FALSE);
      return (TRUE);
   }
   return (TRUE);
}

bool HaveTrade() {
   int l_datetime_28;
   if (FapTurbo_StartWorkTimeHour == FapTurbo_EndWorkTimeHour && FapTurbo_StartWorkTimeMin == FapTurbo_EndWorkTimeMin) return (FALSE);
   int l_datetime_0 = TimeCurrent();
   int li_4 = iTime(NULL, PERIOD_D1, 0);
   int l_hour_8 = TimeHour(l_datetime_0);
   bool li_12 = FALSE;
   if (FapTurbo_StartWorkTimeHour > FapTurbo_EndWorkTimeHour) {
      if (l_hour_8 < FapTurbo_StartWorkTimeHour) li_12 = TRUE;
   } else {
      if (FapTurbo_StartWorkTimeHour == FapTurbo_EndWorkTimeHour) {
         if (FapTurbo_StartWorkTimeMin > FapTurbo_EndWorkTimeMin) {
            if (l_hour_8 < FapTurbo_StartWorkTimeHour) {
               if (l_hour_8 < FapTurbo_StartWorkTimeHour) li_12 = TRUE;
            } else {
               if (l_hour_8 == FapTurbo_StartWorkTimeHour)
                  if (TimeMinute(l_datetime_0) < FapTurbo_EndWorkTimeMin) li_12 = TRUE;
            }
         }
      }
   }
   if (li_12) li_4 -= 86400;
   li_4 += 3600 * FapTurbo_StartWorkTimeHour + 60 * FapTurbo_StartWorkTimeMin;
   int li_16 = OrdersTotal() - 1;
   int l_datetime_20 = -2147483648;
   for (int l_pos_24 = li_16; l_pos_24 >= 0; l_pos_24--) {
      if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == g_symbol_808) {
               l_datetime_28 = OrderOpenTime();
               if (l_datetime_20 < l_datetime_28) l_datetime_20 = l_datetime_28;
            }
         }
      }
   }
   if (l_datetime_20 >= li_4) return (TRUE);
   li_16 = OrdersHistoryTotal() - 1;
   l_datetime_20 = -2147483648;
   for (l_pos_24 = li_16; l_pos_24 >= 0; l_pos_24--) {
      if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == g_symbol_808) {
               l_datetime_28 = OrderOpenTime();
               if (l_datetime_20 < l_datetime_28) l_datetime_20 = l_datetime_28;
            }
         }
      }
   }
   if (l_datetime_20 >= li_4) return (TRUE);
   return (FALSE);
}



void Scalper() {
   double l_irsi_0;
   double l_irsi_8;
   double l_ima_16;
   int l_count_24;
   double l_ima_28;
   g_datetime_824 = TimeCurrent();
   if (PrintLogOnChart) {
      Comment("" 
         + "\n" 
         + "Scalper" 
         + "\n" 
         + "------------------------------------------------" 
         + "\n" 
         + "BROKER INFORMATION:" 
         + "\n" 
         + "Broker Company:      " + AccountCompany() 
         + "\n" 
         + "------------------------------------------------" 
         + "\n" 
         + "ACCOUNT INFORMATION:" 
         + "\n" 
         + "Account Name:          " + AccountName() 
         + "\n" 
         + "Account Number:       " + AccountNumber() 
         + "\n" 
         + "Account Leverage:     " + DoubleToStr(AccountLeverage(), 0) 
         + "\n" 
         + "Account Balance:       " + DoubleToStr(AccountBalance(), 2) 
         + "\n" 
         + "Account Currency:     " + AccountCurrency() 
         + "\n" 
         + "Account Equity:         " + DoubleToStr(AccountEquity(), 2) 
         + "\n" 
         + "------------------------------------------------" 
         + "\n" 
         + "MARGIN INFORMATION:" 
         + "\n" 
         + "Free Margin:              " + DoubleToStr(AccountFreeMargin(), 2) 
         + "\n" 
         + "Used Margin:              " + DoubleToStr(AccountMargin(), 2) 
         + "\n" 
         + "------------------------------------------------" 
         + "\n" 
         + "Actual Server Time     " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
         + "\n" 
      + "------------------------------------------------");
   }
   if (Scalper_StealthMode) WatchLevels();
   if (Scalper_UseCustomLevels) NoiseFilter();
   SetOrderLevels();
   if (TRUE) {
      if (Ask - Bid <= gd_996) {
         if (DayOfWeek() != 0) {
            if (!Scalper_TradeFriday)
               if (DayOfWeek() == 5) return;
            if (DayOfWeek() == 1 && Hour() < gi_924) return;
            if (Scalper_IsTradeTime()>0) {
               if (Scalper_RelaxHours > 0)
                  if (Scalper_IsRelaxHours()) return;
               if (Scalper_SimpleHeightFilter)
                  if (Scalper_CheckSimpleHeightFilter()) return;
               if (Scalper_TrendFilter)
                  if (Scalper_CheckTrendFilter()) return;
               if (Scalper_OneTrade != 0) {
                  if (Scalper_HaveTrade()) {
                     if (!(WriteDebugLog)) return;
                     Print("Already have one trade inside this interval of time.");
                     return;
                  }
               }
               HideTestIndicators(TRUE);
               l_irsi_0 = iRSI(NULL, 0, g_period_680, PRICE_CLOSE, 0);
               l_irsi_8 = iRSI(NULL, PERIOD_M1, g_period_688, PRICE_CLOSE, 0);
               l_ima_16 = iMA(NULL, 0, g_period_676, 0, MODE_SMA, PRICE_MEDIAN, 1);
               HideTestIndicators(FALSE);
               if (fun2(Ask + 0.0002, ExistPosition(), l_irsi_0, l_irsi_8, gi_692, gi_684, l_ima_16)) {
                  if (gi_816) {
                     if (!Scalper_UseFilterMA) l_count_24 = 0;
                     else {
                        l_ima_28 = iMA(NULL, 0, Scalper_PeriodFilterMA, 0, Scalper_MethodFilterMA, Scalper_PriceFilterMA, 0);
                        if (Close[0] <= l_ima_28) l_count_24++;
                     }
                     if (l_count_24 == 0) {
                        OpenPosition(OP_BUY, gi_852, gi_856);
                        gi_816 = FALSE;
                        gi_820 = TRUE;
                     }
                  }
               }
               if (fun3(Bid - 0.0002, ExistPosition(), l_irsi_0, l_irsi_8, gi_840, gi_836, l_ima_16)) {
                  if (gi_820) {
                     if (!Scalper_UseFilterMA) l_count_24 = 0;
                     else {
                        l_ima_28 = iMA(NULL, 0, Scalper_PeriodFilterMA, 0, Scalper_MethodFilterMA, Scalper_PriceFilterMA, 0);
                        if (Close[0] >= l_ima_28) l_count_24++;
                     }
                     if (l_count_24 == 0) {
                        OpenPosition(OP_SELL, gi_852, gi_856);
                        gi_820 = FALSE;
                        gi_816 = TRUE;
                     }
                  }
               }
               if (fun4(l_irsi_0, gi_844, gi_848)) {
                  gi_820 = TRUE;
                  gi_816 = TRUE;
               }
            }
         }
      }
   }
}

bool Scalper_IsRelaxHours() {
   int l_datetime_16;
   bool li_20;
   double ld_24;
   double ld_32;
   double ld_40;
   int l_datetime_52;
   int l_ticket_0 = -1;
   int li_4 = OrdersHistoryTotal() - 1;
   int l_datetime_8 = -2147483648;
   for (int l_pos_12 = li_4; l_pos_12 >= 0; l_pos_12--) {
      if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == g_symbol_808) {
               l_datetime_16 = OrderCloseTime();
               if (l_datetime_8 < l_datetime_16) {
                  l_datetime_8 = l_datetime_16;
                  l_ticket_0 = OrderTicket();
               }
            }
         }
      }
   }
   if (l_ticket_0 < 0) return (FALSE);
   if (OrderSelect(l_ticket_0, SELECT_BY_TICKET)) {
      li_20 = FALSE;
      ld_24 = NormalizeDouble(OrderOpenPrice(), gi_752);
      ld_32 = NormalizeDouble(OrderClosePrice(), gi_752);
      ld_40 = NormalizeDouble(OrderStopLoss(), gi_752);
      if (OrderType() == OP_BUY) {
         if (ld_32 <= ld_40 && ld_40 != 0.0) li_20 = TRUE;
         else
            if (ld_24 - ld_32 >= gd_1004) li_20 = TRUE;
      } else {
         if (ld_32 >= ld_40 && ld_40 != 0.0) li_20 = TRUE;
         else
            if (ld_32 - ld_24 >= gd_1004) li_20 = TRUE;
      }
   } else return (FALSE);
   if (!li_20) return (FALSE);
   int l_shift_48 = iBarShift(NULL, PERIOD_H1, l_datetime_8, FALSE);
   if (l_shift_48 < Scalper_RelaxHours) {
      l_datetime_52 = iTime(NULL, PERIOD_H1, 0);
      if (g_datetime_832 != l_datetime_52) {
         if (WriteLog) Print("Relax Hours Left = " + DoubleToStr(l_shift_48 - Scalper_RelaxHours, 0) + " (after StopLoss).");
         g_datetime_832 = l_datetime_52;
      }
      return (TRUE);
   }
   return (FALSE);
}

bool Scalper_CheckTrendFilter() {
   double ld_4;
   double ld_12;
   double ld_20;
   if (gi_712 <= 0) return (FALSE);
   for (int li_0 = 0; li_0 <= gi_716; li_0++) {
      ld_4 = NormalizeDouble(iMA(NULL, 0, g_period_700, 0, g_ma_method_708, g_applied_price_704, li_0), gi_752);
      ld_12 = NormalizeDouble(iMA(NULL, 0, g_period_700, 0, g_ma_method_708, g_applied_price_704, li_0 + gi_712), gi_752);
      ld_20 = 100.0 * MathAbs(ld_4 - ld_12) / ld_12;
      if (ld_20 > gd_932) break;
   }
   if (li_0 > gi_716) return (FALSE);
   if (WriteDebugLog) {
      Print("Today market is in risky conditions. Trading is forbidden by the filter TrendFilter.");
      if (li_0 != 0) Print("Relax Bars Left = " + DoubleToStr(gi_716 - li_0, 0) + " (after MaxPercentMove).");
   }
   return (TRUE);
}

bool Scalper_CheckSimpleHeightFilter() {
   int l_datetime_4;
   bool li_0 = FALSE;
   if (NormalizeDouble(iHigh(NULL, PERIOD_M15, 1) - iLow(NULL, PERIOD_M15, 1), gi_752) > gd_1012) li_0 = TRUE;
   if (NormalizeDouble(iHigh(NULL, PERIOD_M15, 2) - iLow(NULL, PERIOD_M15, 2), gi_752) > gd_1012) li_0 = TRUE;
   if (li_0) {
      l_datetime_4 = iTime(NULL, PERIOD_M15, 0);
      if (g_datetime_828 != l_datetime_4) {
         if (WriteLog) Print("Today market is in risky conditions. Trade is forbidden by the filter SimpleHeightFilter.");
         g_datetime_828 = l_datetime_4;
      }
      return (TRUE);
   }
   return (FALSE);
}

int Scalper_IsTradeTime() {
   int l_hour_0 = TimeHour(g_datetime_824);
   if (gi_924 < gi_928 && l_hour_0 < gi_924 || l_hour_0 >= gi_928) return (0);
   if (gi_924 > gi_928 && (l_hour_0 < gi_924 && l_hour_0 >= gi_928)) return (0);
   if (gi_928 == 0) gi_928 = 24;
   if (Hour() == gi_928 - 1 && Minute() >= gi_672) return (0);
   return (1);
}

int ExistPosition() {
   int l_ord_total_0 = OrdersTotal();
   for (int l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == g_symbol_808)
               if (OrderType() <= OP_SELL) return (1);
         }
      }
   }
   return (0);
}

int OpenPosition(int a_cmd_0, int ai_unused_4, int ai_unused_8) {
   double l_price_20;
   color l_color_28;
   string ls_36;
   double ld_12 = LotsOptimized();
   if (AccountFreeMarginCheck(g_symbol_808, a_cmd_0, ld_12) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) {
      Print("You don\'t have free margin.");
      Comment("You don\'t have free margin.");
      return (-1);
   }
   RefreshRates();
   if (a_cmd_0 == OP_BUY) {
      l_price_20 = Ask;
      l_color_28 = ColorBuy;
   } else {
      l_price_20 = Bid;
      l_color_28 = ColorSell;
   }
   int l_ticket_32 = OrderSend(g_symbol_808, a_cmd_0, ld_12, l_price_20, MarketInfo(g_symbol_808, MODE_SPREAD), 0, 0, Scalper_ExpertComment, MagicNumber, 0, l_color_28);
   if (l_ticket_32 < 0) {
      if (WriteDebugLog) {
         if (a_cmd_0 == OP_BUY) ls_36 = "OP_BUY";
         else ls_36 = "OP_SELL";
         Print("Open: OrderSend(", ls_36, ") error = ", GetLastError());
      }
   }
   return (l_ticket_32);
}

void NoiseFilter() {
   int li_12;
   double ld_16;
   double ld_24;
   int li_32;
   double ld_36;
   int l_spread_0 = MarketInfo(g_symbol_808, MODE_SPREAD);
   int li_4 = OrdersTotal() - 1;
   for (int l_pos_8 = li_4; l_pos_8 >= 0; l_pos_8--) {
      if (!OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES)) {
         if (WriteDebugLog) Print("NoiseFilter: OrderSelect() error = ", GetLastError());
      } else {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == g_symbol_808) {
                  li_12 = g_datetime_824 - OrderOpenTime();
                  if (li_12 > gi_904) {
                     ld_16 = NormalizeDouble(OrderClosePrice(), Digits);
                     ld_24 = NormalizeDouble(OrderOpenPrice(), Digits);
                     li_32 = 0;
                     if (OrderType() == OP_BUY) ld_36 = ld_16 - ld_24;
                     else ld_36 = ld_24 - ld_16;
                     if (li_12 < gi_908 && ld_36 >= gd_956) li_32 = 1;
                     else {
                        if (li_12 > gi_908 && li_12 < gi_912 && ld_36 >= gd_964) li_32 = 2;
                        else {
                           if (li_12 > gi_912 && li_12 < gi_916 && ld_36 >= gd_972) li_32 = 3;
                           else {
                              if (li_12 > gi_916 && li_12 < gi_920 && ld_36 >= gd_980) li_32 = 4;
                              else
                                 if (li_12 > gi_920 && ld_36 >= gd_988) li_32 = 5;
                           }
                        }
                     }
                     if (li_32 != 0) CloseOrder(OrderTicket(), OrderLots(), OrderType(), l_spread_0 + Scalper_SlipageInc);
                  }
               }
            }
         }
      }
   }
}

void WatchLevels() {
   double ld_12;
   double ld_20;
   double ld_28;
   if (gi_852 <= 0 && gi_856 <= 0) return;
   int l_spread_0 = MarketInfo(g_symbol_808, MODE_SPREAD);
   int li_4 = OrdersTotal() - 1;
   for (int l_pos_8 = li_4; l_pos_8 >= 0; l_pos_8--) {
      if (!OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES)) {
         if (WriteDebugLog) Print("WatchLevels: OrderSelect() error = ", GetLastError());
      } else {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == g_symbol_808) {
                  ld_12 = NormalizeDouble(OrderClosePrice(), Digits);
                  ld_20 = NormalizeDouble(OrderOpenPrice(), Digits);
                  if (OrderType() == OP_BUY) {
                     ld_28 = ld_12 - ld_20;
                     if ((gd_940 > 0.0 && ld_28 >= gd_940) || (gd_948 < 0.0 && ld_28 <= gd_948)) {
                        if (WriteDebugLog) Print("WatchLevels: level for close BUY");
                        CloseOrder(OrderTicket(), OrderLots(), 0, l_spread_0 + Scalper_SlipageInc);
                     }
                  } else {
                     ld_28 = ld_20 - ld_12;
                     if ((gd_940 > 0.0 && ld_28 >= gd_940) || (gd_948 < 0.0 && ld_28 <= gd_948)) {
                        if (WriteDebugLog) Print("WatchLevels: level for close SELL");
                        CloseOrder(OrderTicket(), OrderLots(), 1, l_spread_0 + Scalper_SlipageInc);
                     }
                  }
               }
            }
         }
      }
   }
}

double LotsOptimized() {
   if (!Scalper_UseMM) return (Scalper_Lots);
   double ld_0 = AccountFreeMargin() * gd_800 / 100.0;
   double ld_ret_8 = NormalizeDouble(MathFloor(ld_0 / gd_792) * g_lotstep_784, 2);
   if (ld_ret_8 < g_minlot_776) ld_ret_8 = g_minlot_776;
   if (ld_ret_8 > g_maxlot_768) ld_ret_8 = g_maxlot_768;
   if (ld_ret_8 > Scalper_MaxLots) ld_ret_8 = Scalper_MaxLots;
   return (ld_ret_8);
}

void SetOrderLevels() {
   double ld_16;
   double l_price_24;
   double ld_32;
   double ld_40;
   bool li_48;
   int li_52;
   int li_56;
   double l_price_60;
   double l_price_68;
   bool l_bool_76;
   double ld_0 = NormalizeDouble(MarketInfo(g_symbol_808, MODE_STOPLEVEL) * Point, Digits);
   int li_8 = OrdersTotal() - 1;
   for (int l_pos_12 = li_8; l_pos_12 >= 0; l_pos_12--) {
      if (!OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) {
         if (WriteDebugLog) Print("SetOrderLevels: OrderSelect() error = ", GetLastError());
      } else {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderType() <= OP_SELL) {
               if (OrderSymbol() == g_symbol_808) {
                  ld_16 = NormalizeDouble(OrderClosePrice(), gi_752);
                  l_price_24 = NormalizeDouble(OrderOpenPrice(), gi_752);
                  ld_32 = NormalizeDouble(OrderStopLoss(), gi_752);
                  ld_40 = NormalizeDouble(OrderTakeProfit(), gi_752);
                  li_48 = TRUE;
                  li_52 = 0;
                  li_56 = 0;
                  if (ld_32 == 0.0) {
                     if (Scalper_StealthMode) li_52 = gi_720 + MathRand() % gi_724;
                     else li_52 = gi_856;
                     if (li_52 != 0) {
                        if (OrderType() == OP_BUY) {
                           l_price_60 = NormalizeDouble(l_price_24 - li_52 * gd_760, gi_752);
                           if (ld_16 - l_price_60 <= ld_0) li_48 = FALSE;
                        } else {
                           l_price_60 = NormalizeDouble(l_price_24 + li_52 * gd_760, gi_752);
                           if (l_price_60 - ld_16 <= ld_0) li_48 = FALSE;
                        }
                     }
                  } else l_price_60 = ld_32;
                  if (ld_40 == 0.0) {
                     if (Scalper_StealthMode) li_56 = gi_728 + MathRand() % gi_732;
                     else li_56 = gi_852;
                     if (li_56 != 0) {
                        if (OrderType() == OP_BUY) {
                           l_price_68 = NormalizeDouble(l_price_24 + li_56 * gd_760, gi_752);
                           if (l_price_68 - ld_16 <= ld_0) li_48 = FALSE;
                        } else {
                           l_price_68 = NormalizeDouble(l_price_24 - li_56 * gd_760, gi_752);
                           if (ld_16 - l_price_68 <= ld_0) li_48 = FALSE;
                        }
                     }
                  } else l_price_68 = ld_40;
                  if (li_52 != 0 && li_56 != 0 && li_48) {
                     while (!IsTradeAllowed()) Sleep(1000);
                     l_bool_76 = OrderModify(OrderTicket(), l_price_24, l_price_60, l_price_68, 0, CLR_NONE);
                     if (!l_bool_76)
                        if (WriteDebugLog) Print("SetOrderLevels: OrderModify(OP_SELL) error = ", GetLastError());
                  }
               }
            }
         }
      }
   }
}

bool Scalper_HaveTrade() {
   int l_datetime_28;
   if (gi_664 == gi_668) return (FALSE);
   int l_datetime_0 = TimeCurrent();
   int li_4 = iTime(NULL, PERIOD_D1, 0);
   int l_hour_8 = TimeHour(l_datetime_0);
   int li_unused_12 = 0;
   if (gi_664 > gi_668)
      if (l_hour_8 < gi_664) li_4 -= 86400;
   li_4 += 3600 * gi_664;
   int li_16 = OrdersTotal() - 1;
   int l_datetime_20 = -2147483648;
   for (int l_pos_24 = li_16; l_pos_24 >= 0; l_pos_24--) {
      if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == g_symbol_808) {
               l_datetime_28 = OrderOpenTime();
               if (l_datetime_20 < l_datetime_28) l_datetime_20 = l_datetime_28;
            }
         }
      }
   }
   if (l_datetime_20 >= li_4) return (TRUE);
   li_16 = OrdersHistoryTotal() - 1;
   l_datetime_20 = -2147483648;
   for (l_pos_24 = li_16; l_pos_24 >= 0; l_pos_24--) {
      if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == g_symbol_808) {
               l_datetime_28 = OrderOpenTime();
               if (l_datetime_20 < l_datetime_28) l_datetime_20 = l_datetime_28;
            }
         }
      }
   }
   if (l_datetime_20 >= li_4) return (TRUE);
   return (FALSE);
}

int CloseOrder(int a_ticket_0, double a_lots_4, int ai_12, int a_slippage_16) {
   color l_color_20;
   double l_price_40;
   bool l_ord_close_48;
   int l_error_52;
   string ls_56;
   bool li_64;
   if (ai_12 == 0) l_color_20 = ColorBuy;
   else l_color_20 = ColorSell;
   int l_count_24 = 0;
   int l_count_28 = 0;
   int l_count_32 = 0;
   int l_count_36 = 0;
   while (true) {
      while (!IsTradeAllowed()) Sleep(1000);
      RefreshRates();
      if (ai_12 == 0) l_price_40 = Bid;
      else l_price_40 = Ask;
      l_ord_close_48 = OrderClose(a_ticket_0, a_lots_4, l_price_40, a_slippage_16, l_color_20);
      if (!(!l_ord_close_48)) break;
      l_error_52 = GetLastError();
      if (WriteDebugLog) {
         if (OrderType() == OP_BUY) ls_56 = "BUY";
         else ls_56 = "SELL";
         Print("OrderClose(", ls_56, ",", a_ticket_0, ") error = ", ErrorDescription(l_error_52));
      }
      li_64 = FALSE;
      
      switch (l_error_52) {
      case 0 :
         Sleep(10000);
         if (OrderSelect(a_ticket_0, SELECT_BY_TICKET)) 
            if (OrderCloseTime() == 0) 
               li_64 = TRUE;
               
               break;
            case 1/* NO_ERROR */: break;
            case 2/* COMMON_ERROR */: break;
            case 3/* INVALID_TRADE_PARAMETERS */: break;
            case 4/* SERVER_BUSY */: break;
            case 5/* OLD_VERSION */: break;
            case 6/* NO_CONNECTION */:
               Sleep(10000);
               if (IsConnected()) 
                  li_64 = TRUE;
                   break;
               case 7/* NOT_ENOUGH_RIGHTS */: break;
               case 8/* TOO_FREQUENT_REQUESTS */: break;
               case 9/* MALFUNCTIONAL_TRADE */: break;
               case 64/* ACCOUNT_DISABLED */: break;
               case 65/* INVALID_ACCOUNT */: break;
               case 128/* TRADE_TIMEOUT */:
                  Sleep(70000);
                  if (OrderSelect(a_ticket_0, SELECT_BY_TICKET)) 
                     if (OrderCloseTime() == 0) 
                        li_64 = TRUE;
                        break;
                     case 129/* INVALID_PRICE */:
                        Sleep(6000);
                        l_count_24++;
                        if (l_count_24 <= 3) 
                           li_64 = TRUE;
                           break;
                        case 130/* INVALID_STOPS */:
                           Sleep(6000);
                           l_count_28++;
                           if (l_count_28 <= 3) 
                              li_64 = TRUE;
                              break;
                           case 131/* INVALID_TRADE_VOLUME */: break;
                           case 132/* MARKET_CLOSED */: break;
                           case 133/* TRADE_DISABLED */: break;
                           case 134/* NOT_ENOUGH_MONEY */: break;
                           case 135/* PRICE_CHANGED */:
                              li_64 = TRUE;
                              break;
                           case 136/* OFF_QUOTES */:
                              Sleep(6000);
                              li_64 = TRUE;
                              break;
                           case 137/* BROKER_BUSY */:
                              Sleep(20000);
                              l_count_32++;
                              if (l_count_32 <= 3) 
                                 li_64 = TRUE;
                                 break;
                              case 138/* REQUOTE */:
                                 l_count_36++;
                                 if (l_count_36 <= 3) 
                                    li_64 = TRUE;
                                    break;
                                 case 139/* ORDER_LOCKED */: break;
                                 case 140/* LONG_POSITIONS_ONLY_ALLOWED */: break;
                                 case 141/* TOO_MANY_REQUESTS */: break;
                                 case 142:
                                    Sleep(70000);
                                    if (OrderSelect(a_ticket_0, SELECT_BY_TICKET)) 
                                       if (OrderCloseTime() == 0) 
                                          li_64 = TRUE;
                                          break;
                                       case 143:
                                          Sleep(70000);
                                          if (OrderSelect(a_ticket_0, SELECT_BY_TICKET)) 
                                             if (OrderCloseTime() == 0) 
                                                li_64 = TRUE;
                                                break;
                                             case 144: break;
                                             case 145/* TRADE_MODIFY_DENIED */:
                                                Sleep(20000);
                                                li_64 = TRUE;
                                                break;
                                             case 146/* TRADE_CONTEXT_BUSY */:
                                                while (IsTradeContextBusy()) Sleep(1000);
                                                li_64 = TRUE;
                                                break;
                                             case 147: break;
                                             case 148: break;
                                             case 4000/* NO_MQLERROR */:
                                                Sleep(10000);
                                                if (OrderSelect(a_ticket_0, SELECT_BY_TICKET))
                                                   if (OrderCloseTime() == 0) li_64 = TRUE;
                                                   break;
                                             case 4051/* INVALID_FUNCTION_PARAMETER_VALUE */: break;
                                             case 4062/* STRING_PARAMETER_EXPECTED */: break;
                                             case 4063/* INTEGER_PARAMETER_EXPECTED */: break;
                                             case 4064/* DOUBLE_PARAMETER_EXPECTED */: break;
                                             case 4105/* NO_ORDER_SELECTED */: break;
                                             case 4106/* UNKNOWN_SYMBOL */: break;
                                             case 4107/* INVALID_PRICE_PARAM */: break;
                                             case 4108/* INVALID_TICKET */: break;
                                             case 4109/* TRADE_NOT_ALLOWED */: break;
                                             case 4110/* LONGS__NOT_ALLOWED */: break;
                                             case 4111/* SHORTS_NOT_ALLOWED */: break;
                                                          if (li_64) continue;
                                                          return (l_ord_close_48);
                                                               }}}