Navigation´╝ÜHome > Content >

Forex_Envy_v3.3~.mq4

Time: 2018-06-21 | Download file:Forex_Envy_v3.3~.mq4

/*
   Generated by EX4-TO-MQ4 decompiler FREEWARE V4.0.451.1 [-]
   Website: http://www.metaquotes.net
   E-mail : [email protected]
*/
#property copyright "Forex Envy ltd"
#property link      "www.forexenvy.com"

//#include 
#import "stdlib.ex4"
   string ErrorDescription(int a0); // DA69CBAFF4D38B87377667EEC549DE5A
#import "envylib.dll"
   int chk(string a0, string a1, string a2, int a3, int a4, int a5, double& a6[], int a7, int& a8[]);
   int auth(string a0, int a1, int a2, int a3, int& a4[]);
   int mb(string a0);
   int newsupdate(string a0, string a1, string a2, int& a3[]);
   int nextnewsstart(string a0, int a1, int a2);
   int nextnewsend(string a0, int a1, int a2);
   string nextnewstext(string a0, int a1, int a2);
   int hasnews(string a0, int a1, int a2);
   string geterrmsg(string a0);
   int geterrcode(string a0);
   double calcbase(double a0, int a1, int a2, double a3, double a4, double a5);
   int params(string a0, string a1, int a2, int a3, double a4, double a5, double a6, double a7, int a8, int a9, double a10, double a11, double a12, double& a13[], int& a14[]);
   int needparamupdate(double a0, int a1, int a2);
   int s(string a0, double a1, double a2, int& a3[]);
   double l(string a0, double a1, double a2, double a3, int& a4[]);
   void uninit(int a0);
   int systemtime();
   int modemin(int a0);
   int calcmin(int a0, double a1, int a2, int a3, double a4);
   int hasnewsdata();
#import "ws2_32.dll"
   int WSAStartup(int a0, int& a1[]);
   int socket(int a0, int a1, int a2);
   int connect(int a0, int& a1[], int a2);
   int recv(int a0, int& a1[], int a2, int a3);
   int closesocket(int a0);
   int WSACleanup();
#import "kernel32.dll"
   void GetSystemTime(int& a0[]);
#import

int gi_unused_76;
string gs_dummy_80;
extern string LicenseKey = "";
extern string ModeInfo0 = "0 = Manual settings";
extern string ModeInfo1 = "1 = -HV- Long Cycle";
extern string ModeInfo2 = "2 = -HV- Short Cycle";
extern string ModeInfo3 = "3 = -NV- Long Cycle";
extern string ModeInfo4 = "4 = -NV- Short Cycle";
extern string ModeInfo5 = "5 = -LV- Long Cycle";
extern string ModeInfo6 = "6 = Power Long Cycle";
extern string ModeInfo7 = "7 = Power Short Cycle";
extern string ModeInfo8 = "8 = Ultra";
extern int Mode = 0;
extern double RiskFactor = 1.0;
extern bool IgnoreBonusCredit = FALSE;
extern double SpreadCushion = 0.2;
extern bool UseServerNews = TRUE;
extern string ManualCycleInfo = "0 - long; 1 - short";
extern int ManualCycle = 0;
extern int FreezeBeforeNewsMinutes = 300;
extern int ResumeAfterNewsMinutes = 60;
extern bool NewsAlertPopups = FALSE;
extern bool AutoGMTOffset = TRUE;
extern int GMTOffset = 0;
extern string _________ = "Input a unique magic number for each chart, 0 for automatic";
extern int Magic_Number = 0;
extern double Base_Lot_Size = 0.0;
extern int Execution_Point = 0;
extern double Basket_Take_Profit = 0.0;
extern int Basket_Stop_Loss = 0;
extern double Multiplier = 0.0;
extern int Maximum_Buy_Levels = 0;
extern int Maximum_Sell_Levels = 0;
extern int Slippage = 3;
string gs_unused_288 = "1234567890123456";
extern bool Server_Friendly_Mode = FALSE;
extern bool SFM_Visual_TP = TRUE;
extern color SFM_Visual_TP_Color = Red;
extern bool SFM_Visual_SL = TRUE;
extern color SFM_Visual_SL_Color = Blue;
extern bool Negative_Basket_Protection = TRUE;
extern double NBP_Value = 0.0;
extern int Tolerance = 0;
extern bool Support_ECN = TRUE;
extern double Bail_Out_Pct = 100.0;
extern int Close_Order_Attempts = 0;
extern bool Chicken_Out = FALSE;
extern bool Freeze_After_TP = FALSE;
extern bool Freeze_After_TP_Scheduler = TRUE;
extern string __________ = "Freeze After TP Scheduler";
extern int SUN_Start_Hour = 0;
extern int SUN_Start_Minute = 0;
extern int SUN_End_Hour = 0;
extern int SUN_End_Minute = 0;
extern int MON_Start_Hour = 0;
extern int MON_Start_Minute = 0;
extern int MON_End_Hour = 0;
extern int MON_End_Minute = 0;
extern int TUE_Start_Hour = 0;
extern int TUE_Start_Minute = 0;
extern int TUE_End_Hour = 0;
extern int TUE_End_Minute = 0;
extern int WED_Start_Hour = 0;
extern int WED_Start_Minute = 0;
extern int WED_End_Hour = 0;
extern int WED_End_Minute = 0;
extern int THU_Start_Hour = 0;
extern int THU_Start_Minute = 0;
extern int THU_End_Hour = 0;
extern int THU_End_Minute = 0;
extern int FRI_Start_Hour = 0;
extern int FRI_Start_Minute = 0;
extern int FRI_End_Hour = 0;
extern int FRI_End_Minute = 0;
extern int SAT_Start_Hour = 0;
extern int SAT_Start_Minute = 0;
extern int SAT_End_Hour = 0;
extern int SAT_End_Minute = 0;
extern string EA_Name = "Forex Envy";
extern string ____________ = "";
extern string Envy_Augmenter = "";
extern string Level_1 = "";
extern double Multiplier_1 = 0.0;
extern double Basket_Take_Profit_1 = 0.0;
extern string Level_2 = "";
extern double Multiplier_2 = 0.0;
extern double Basket_Take_Profit_2 = 0.0;
extern string Level_3 = "";
extern double Multiplier_3 = 0.0;
extern double Basket_Take_Profit_3 = 0.0;
extern string Level_4 = "";
extern double Multiplier_4 = 0.0;
extern double Basket_Take_Profit_4 = 0.0;
extern string Level_5 = "";
extern double Multiplier_5 = 0.0;
extern double Basket_Take_Profit_5 = 0.0;
extern string Level_6 = "";
extern double Multiplier_6 = 0.0;
extern double Basket_Take_Profit_6 = 0.0;
extern string Level_7 = "";
extern double Multiplier_7 = 0.0;
extern double Basket_Take_Profit_7 = 0.0;
extern string Level_8 = "";
extern double Multiplier_8 = 0.0;
extern double Basket_Take_Profit_8 = 0.0;
extern string Level_9 = "";
extern double Multiplier_9 = 0.0;
extern double Basket_Take_Profit_9 = 0.0;
extern string Level_10 = "";
extern double Multiplier_10 = 0.0;
extern double Basket_Take_Profit_10 = 0.0;
extern string Level_11 = "";
extern double Multiplier_11 = 0.0;
extern double Basket_Take_Profit_11 = 0.0;
extern string Level_12 = "";
extern double Multiplier_12 = 0.0;
extern double Basket_Take_Profit_12 = 0.0;
extern string Level_13 = "";
extern double Multiplier_13 = 0.0;
extern double Basket_Take_Profit_13 = 0.0;
extern string Level_14 = "";
extern double Multiplier_14 = 0.0;
extern double Basket_Take_Profit_14 = 0.0;
extern string Level_15 = "";
extern double Multiplier_15 = 0.0;
extern double Basket_Take_Profit_15 = 0.0;
extern string Level_16 = "";
extern double Multiplier_16 = 0.0;
extern double Basket_Take_Profit_16 = 0.0;
extern string Level_17 = "";
extern double Multiplier_17 = 0.0;
extern double Basket_Take_Profit_17 = 0.0;
extern string Level_18 = "";
extern double Multiplier_18 = 0.0;
extern double Basket_Take_Profit_18 = 0.0;
extern string Level_19 = "";
extern double Multiplier_19 = 0.0;
extern double Basket_Take_Profit_19 = 0.0;
extern string Level_20 = "";
extern double Multiplier_20 = 0.0;
extern double Basket_Take_Profit_20 = 0.0;
extern string Level_21 = "";
extern double Multiplier_21 = 0.0;
extern double Basket_Take_Profit_21 = 0.0;
extern string Level_22 = "";
extern double Multiplier_22 = 0.0;
extern double Basket_Take_Profit_22 = 0.0;
extern string Level_23 = "";
extern double Multiplier_23 = 0.0;
extern double Basket_Take_Profit_23 = 0.0;
extern string Level_24 = "";
extern double Multiplier_24 = 0.0;
extern double Basket_Take_Profit_24 = 0.0;
extern string Level_25 = "";
extern double Multiplier_25 = 0.0;
extern double Basket_Take_Profit_25 = 0.0;
int gi_1104 = 60;
double gd_1108;
bool gi_1116 = FALSE;
bool gi_1120 = FALSE;
bool gi_1124 = TRUE;
bool gi_1128 = TRUE;
bool gi_1132 = FALSE;
double gd_1136;
int gi_unused_1144 = 300;
int gi_1148 = 5000;
int gi_1152 = 0;
int gi_1156 = 0;
double gd_unused_1160 = 100.0;
int gi_1168 = 600;
double gd_1172;
bool gi_1180;
int g_period_1184 = 7;
int gi_1188 = 0;
int g_ma_method_1192 = MODE_LWMA;
int g_applied_price_1196 = PRICE_WEIGHTED;
int g_timeframe_1200 = PERIOD_H1;
double gd_1204 = 0.25;
double gd_1212 = 0.2;
int g_timeframe_1220 = PERIOD_H1;
double gd_1224 = 1.01;
int gi_1232 = 5;
int g_datetime_1236;
double g_point_1240;
int gi_1248;
bool gi_unused_1252 = FALSE;
string gs_dummy_1256;
int gi_unused_1272 = 0;
int gi_unused_1276 = 1;
int gi_unused_1280 = 3;
int gi_unused_1284 = 250;
bool gi_1288;
bool gi_1292;
bool gi_1296;
bool gi_1300;
int g_ticket_1304;
int g_cmd_1308;
string gs__hedged_1312 = " hedged";
int gi_1320 = 1;
bool gi_1324 = FALSE;
int gi_1328;
double g_point_1332 = 0.0001;
bool gi_1340 = FALSE;
int gia_1344[25];
int gia_1348[25];
double gda_1352[25];
double gda_1356[25];
double gda_1360[25];
double gda_1364[25];
int g_error_1376;
string gsa_1380[] = {"EUR", "USD", "CHF", "GBP", "JPY", "AUD", "CAD", "NZD", "HKD", "DKK", "NOK", "SEK", "SGD", "RUB", "RUR", "ZAR", "UAH", "RON", "MXN", "TRY", "PLN", "HUF", "PHP",
      "MTL", "HRK", "LVL", "CZK", "ILS", "LTL", "XAU", "XAG"};
string gs_1384;
string gs_1392;
string gs_1400;
string gs_1408;
int gia_1416[2];
string gs_1420;
string gs_1428 = "";
bool gi_1436 = FALSE;
int gi_1440 = 0;
bool gi_1444 = FALSE;
int g_global_var_1448 = 0;
int gi_1452 = 0;
int gi_1456 = 0;
bool gi_1460 = FALSE;
bool gi_1464 = FALSE;
bool gi_1468 = FALSE;
bool gi_1472 = TRUE;
bool gi_1476 = FALSE;
double gd_1480 = 1.0;
double gd_1488 = 0.0;
string gs_1496 = "";
bool gi_1504 = FALSE;
int gi_1508 = 0;
double gd_1512 = 0.0;

int NewsMode() {
   if (Mode == 0 && ManualCycle == 1) return (-1);
   return (Mode);
}

void currencyPairSetup() {
   string ls_0;
   string ls_8;
   int li_36;
   int li_40;
   int li_unused_16 = 0;
   string ls_20 = Symbol();
   for (int count_28 = 0; count_28 < StringLen(ls_20); count_28++) {
      for (int index_32 = 0; index_32 < ArraySize(gsa_1380); index_32++) {
         li_36 = StringFind(ls_20, gsa_1380[index_32], 0);
         if (li_36 >= 0 && li_36 <= count_28) {
            if (li_36 > 0) gs_1384 = StringSubstr(ls_20, 0, li_36);
            ls_0 = StringSubstr(ls_20, li_36, 3);
            break;
         }
      }
      if (StringLen(ls_0) > 0) break;
   }
   for (index_32 = 0; index_32 < ArraySize(gsa_1380); index_32++) {
      li_40 = StringFind(ls_20, gsa_1380[index_32], li_36 + 3);
      if (li_40 >= 0) {
         if (li_40 > li_36 + 3) gs_1392 = StringSubstr(ls_20, li_36 + 3, li_40 - (li_36 + 3));
         ls_8 = StringSubstr(ls_20, li_40, 3);
         gs_1400 = StringSubstr(ls_20, li_40 + 3);
         break;
      }
   }
   gs_1408 = ls_0 + ls_8;
}

void updateMagicNumber() {
   int li_0;
   string ls_12;
   int lia_20[256];
   string ls_24;
   for (int li_4 = 0; li_4 < 256; li_4++) {
      li_0 = li_4;
      for (int count_8 = 0; count_8 < 8; count_8++) {
         if (li_0 & 1 > 0) li_0 = li_0 >> 1 ^ (-306674912);
         else li_0 >>= 1;
      }
      lia_20[li_4] = li_0;
   }
   if (Magic_Number == 0) {
      ls_24 = DoubleToStr(Mode, 0);
      if (Mode == 0) ls_24 = ls_24 + DoubleToStr(ManualCycle, 0);
      ls_12 = Symbol() + ls_24;
      li_0 = -1;
      for (li_4 = StringLen(ls_12) - 1; li_4 >= 0; li_4--) li_0 = li_0 >> 8 ^ lia_20[li_0 ^ StringGetChar(ls_12, li_4) & 255];
      Magic_Number = li_0 ^ (-1) & EMPTY_VALUE;
   }
   Print("Using magic number: " + Magic_Number);
}

void check() {
   double lda_0[][6];
   int li_8;
   int li_16;
   int li_4 = ArrayCopyRates(lda_0, Symbol(), Period());
   if (li_4 != 0) {
      li_8 = chk(LicenseKey, AccountServer(), gs_1400, AccountNumber(), IsDemo(), WindowHandle(Symbol(), Period()), lda_0, li_4, gia_1416);
      gi_1444 = FALSE;
      switch (li_8) {
      case 1:
         gs_1420 = "Successfully authenticated.";
         gi_1436 = TRUE;
         break;
      case 2:
         gi_1440 = EMPTY_VALUE;
         gs_1420 = "No license key entered.";
         gi_1436 = FALSE;
         break;
      case 3:
         gs_1420 = "Your history does not have enough bars. Re-attempting authentication shortly.";
         gi_1436 = FALSE;
         break;
      case 4:
      case 8:
      case 5:
      case 6:
      case 7:
      case 12:
         gi_1440 = EMPTY_VALUE;
         gs_1420 = "Tampering detected. Authentication will not proceed.";
         gi_1436 = FALSE;
         break;
      case 10:
         gs_1420 = "Your authentication token has expired. Attempting to obtain a new one from the server.";
         gi_1436 = FALSE;
         break;
      case 11:
         li_16 = geterrcode(LicenseKey);
         if (li_16 == 2 || li_16 == 8 || li_16 == 9) gi_1440 = EMPTY_VALUE;
         else gi_1444 = TRUE;
         gs_1420 = geterrmsg(LicenseKey) 
         + "\nStatus code: " + li_16;
         gi_1436 = FALSE;
      }
      if (li_8 != 1) {
         Comment(gs_1420 
         + "\nResult code: " + li_8);
         Print(gs_1420);
         Print("Result code: " + li_8);
      }
   }
}

int GMTTimeCurrent() {
   return (TimeCurrent() - 3600 * GMTOffset);
}

void updateUSDExchangeRate() {
   double ld_0;
   gd_1480 = 1;
   if (AccountCurrency() != "USD") {
      ld_0 = MarketInfo(gs_1384 + AccountCurrency() + gs_1392 + "USD" + gs_1400, MODE_ASK);
      if (ld_0 > 0.0) gd_1480 = ld_0;
      else {
         ld_0 = MarketInfo(gs_1384 + "USD" + gs_1392 + AccountCurrency() + gs_1400, MODE_BID);
         if (ld_0 > 0.0) gd_1480 = 1 / ld_0;
      }
   }
}

void balancewarning() {
   int li_0 = calcmin(Mode, MarketInfo(Symbol(), MODE_MINLOT), MarketInfo(Symbol(), MODE_LOTSIZE), AccountLeverage(), gd_1480);
   if (!gi_1504) {
      Alert(Symbol() + ": Your account balance is below the minimum recommended for mode " + Mode + " for your account (" + li_0 + ")!");
      gi_1504 = TRUE;
   }
   gs_1496 = "!!!WARNING!!! Your account balance is below the minimum recommended for mode " + Mode + " for your account (" + li_0 + ").\n";
}

void balancewarningm8() {
   if (!gi_1504) {
      Alert(Symbol() + ": Your account balance is below the minimum recommended for the base lot size!");
      gi_1504 = TRUE;
   }
   gs_1496 = "!!!WARNING!!! Your account balance is below the minimum recommended for the base lot size!\n";
}

void clearbalancewarning() {
   gs_1496 = "";
}

void getparams() {
   double lda_0[40];
   double ld_8;
   if (Mode > 0 && Basket_Stop_Loss == 0) Basket_Stop_Loss = 180;
   Print("Updating settings.");
   int li_4 = params(LicenseKey, gs_1408, WindowHandle(Symbol(), Period()), Mode, gd_1488, SpreadCushion, MarketInfo(Symbol(), MODE_MINLOT), MarketInfo(Symbol(), MODE_MAXLOT),
      MarketInfo(Symbol(), MODE_LOTSIZE), AccountLeverage(), AccountBalance() * gd_1480, AccountEquity() * gd_1480, RiskFactor, lda_0, gia_1416);
   if (li_4 >= 1) {
      if (li_4 == 2) balancewarning();
      else clearbalancewarning();
      Print("Settings update successful.");
      if (Mode > 0) {
         if (Mode == 8) {
            ld_8 = AccountEquity();
            if (IgnoreBonusCredit) ld_8 = AccountBalance();
            Base_Lot_Size = 0.000005 * calcbase(MarketInfo(Symbol(), MODE_MINLOT), MarketInfo(Symbol(), MODE_LOTSIZE), AccountLeverage(), AccountBalance() * gd_1480, ld_8 * gd_1480,
               RiskFactor);
            Base_Lot_Size = NormalizeDouble(Base_Lot_Size, GetLotDigits());
            if (Base_Lot_Size < MarketInfo(Symbol(), MODE_MINLOT)) Base_Lot_Size = MarketInfo(Symbol(), MODE_MINLOT);
            if (Base_Lot_Size > MarketInfo(Symbol(), MODE_MAXLOT)) Base_Lot_Size = MarketInfo(Symbol(), MODE_MAXLOT);
         } else Base_Lot_Size = lda_0[0];
         Multiplier = lda_0[1];
         gd_1136 = Multiplier;
         Maximum_Buy_Levels = lda_0[2];
         Maximum_Sell_Levels = lda_0[3];
         Multiplier_1 = lda_0[4];
         Multiplier_2 = lda_0[5];
         Multiplier_3 = lda_0[6];
         Multiplier_4 = lda_0[7];
         Multiplier_5 = lda_0[8];
         Multiplier_6 = lda_0[9];
         Multiplier_7 = lda_0[10];
         Multiplier_8 = lda_0[11];
         Multiplier_9 = lda_0[12];
         Multiplier_10 = lda_0[13];
         Multiplier_11 = lda_0[14];
         Multiplier_12 = lda_0[15];
         Multiplier_13 = lda_0[16];
         Multiplier_14 = lda_0[17];
         Multiplier_15 = lda_0[18];
         Multiplier_16 = lda_0[19];
         Multiplier_17 = lda_0[20];
         Multiplier_18 = lda_0[21];
         Multiplier_19 = lda_0[22];
         Multiplier_20 = lda_0[23];
         Multiplier_21 = lda_0[24];
         Multiplier_22 = lda_0[25];
         Multiplier_23 = lda_0[26];
         Multiplier_24 = lda_0[27];
         Multiplier_25 = lda_0[28];
         Execution_Point = lda_0[29];
         Basket_Take_Profit = lda_0[30];
         Basket_Take_Profit_1 = lda_0[30];
         Basket_Take_Profit_2 = lda_0[30];
         Basket_Take_Profit_3 = lda_0[30];
         Basket_Take_Profit_4 = lda_0[30];
         Basket_Take_Profit_5 = lda_0[30];
         Basket_Take_Profit_6 = lda_0[30];
         Basket_Take_Profit_7 = lda_0[30];
         Basket_Take_Profit_8 = lda_0[30];
         Basket_Take_Profit_9 = lda_0[30];
         Basket_Take_Profit_10 = lda_0[30];
         Basket_Take_Profit_11 = lda_0[30];
         Basket_Take_Profit_12 = lda_0[30];
         Basket_Take_Profit_13 = lda_0[30];
         Basket_Take_Profit_14 = lda_0[30];
         Basket_Take_Profit_15 = lda_0[30];
         Basket_Take_Profit_16 = lda_0[30];
         Basket_Take_Profit_17 = lda_0[30];
         Basket_Take_Profit_18 = lda_0[30];
         Basket_Take_Profit_19 = lda_0[30];
         Basket_Take_Profit_20 = lda_0[30];
         Basket_Take_Profit_21 = lda_0[30];
         Basket_Take_Profit_22 = lda_0[30];
         Basket_Take_Profit_23 = lda_0[30];
         Basket_Take_Profit_24 = lda_0[30];
         Basket_Take_Profit_25 = lda_0[30];
         NBP_Value = lda_0[32];
         Tolerance = lda_0[33];
         if (lda_0[34] != 0.0 && Basket_Stop_Loss == 0) Basket_Stop_Loss = lda_0[34];
      }
      gi_1468 = TRUE;
      return;
   }
   if (li_4 == 0) {
      Comment("Unable to read the settings using your license key.");
      gi_1468 = FALSE;
      return;
   }
   if (li_4 == -1) {
      Comment("Invalid mode.");
      Print("Invalid mode.");
      gi_1468 = FALSE;
      gi_1472 = FALSE;
      return;
   }
   if (li_4 == -2) {
      Comment("Error retrieving the settings from the server. Retrying in 2 minutes...");
      gi_1468 = FALSE;
      return;
   }
   if (li_4 == -3) {
      Comment(gs_1408 + " is not among the supported pairs.");
      Print(gs_1408 + " is not among the supported pairs.");
      gi_1472 = FALSE;
      gi_1468 = FALSE;
      return;
   }
   if (li_4 == -4) {
      Comment("Mode " + Mode + " is not supported on " + gs_1408 + ".");
      Print("Mode " + Mode + " is not supported on " + gs_1408 + ".");
      gi_1472 = FALSE;
      gi_1468 = FALSE;
   }
}

void updateAverageSpread() {
   double ld_0 = (Ask - Bid) / g_point_1332;
   gi_1508++;
   if (gi_1508 > 500) gi_1508 = 500;
   if (gi_1508 <= 1) {
      gd_1488 = ld_0;
      return;
   }
   gd_1488 += (ld_0 - gd_1488) / gi_1508;
}

void checkBalanceUpdate() {
   double ld_0;
   double ld_8;
   if (AccountBalance() != gd_1512) {
      ld_0 = AccountEquity();
      if (IgnoreBonusCredit) ld_0 = AccountBalance();
      ld_8 = calcbase(MarketInfo(Symbol(), MODE_MINLOT), MarketInfo(Symbol(), MODE_LOTSIZE), AccountLeverage(), AccountBalance() * gd_1480, ld_0 * gd_1480, RiskFactor);
      if (needparamupdate(ld_8, WindowHandle(Symbol(), Period()), Mode) == 1) gi_1440 = 0;
      if (Mode < 8) {
         if (ld_8 < modemin(Mode)) balancewarning();
         else clearbalancewarning();
      } else {
         if (Mode == 8) {
            if (Base_Lot_Size / 0.000005 > AccountBalance() * gd_1480) balancewarningm8();
            else clearbalancewarning();
         }
      }
      gd_1512 = AccountBalance();
   }
}

void updateGMTOffset() {
   int global_var_0;
   int global_var_4;
   if (GlobalVariableCheck("EnvyGMTUpdateStart")) {
      global_var_0 = GlobalVariableGet("EnvyGMTUpdateStart");
      if (global_var_0 < systemtime() + 300) return;
   }
   if (GlobalVariableCheck("EnvyGMTLastUpdate")) {
      global_var_4 = GlobalVariableGet("EnvyGMTLastUpdate");
      if (global_var_4 + 129600 > systemtime()) {
         g_global_var_1448 = global_var_4;
         GMTOffset = GlobalVariableGet("EnvyGMTOffset");
         Print("GMT Offset: " + GMTOffset + " (global variable).");
         return;
      }
   }
   GlobalVariableSet("EnvyGMTUpdateStart", systemtime());
   GMTOffset = GetGMTOffset();
   Print("GMT Offset: " + GMTOffset + " (calculated).");
   GlobalVariableDel("EnvyGMTUpdateStart");
   GlobalVariableSet("EnvyGMTLastUpdate", systemtime());
   GlobalVariableSet("EnvyGMTOffset", GMTOffset);
   g_global_var_1448 = systemtime();
}

double GetGMTOffset() {
   int li_0;
   int li_12;
   int li_16;
   int li_unused_24;
   int li_28;
   int lia_32[16];
   int lia_44[100];
   string str_concat_48;
   int str2time_56;
   double ld_60;
   int lia_68[4];
   string ls_72;
   string ls_80;
   double ld_ret_4 = -100;
   while (ld_ret_4 < -12.0 || ld_ret_4 > 13.0 && li_0 < 10) {
      li_12 = 9;
      li_unused_24 = 0;
      li_28 = 0;
      int lia_36[5] = {218103810};
      int lia_40[9] = {317991872, 1694802820, 895544384, 487523969, 1711580036, 747408000, 1728357252, 1901185231, 470746753};
      while (li_16 < li_12) {
         if (WSAStartup(514, lia_44) == 0) {
            li_28 = socket(2, 1, 0);
            if (li_28 >= 0) {
               lia_36[1] = lia_40[li_16];
               if (connect(li_28, lia_36, 20) >= 0) {
                  ArrayInitialize(lia_32, 0);
                  if (recv(li_28, lia_32, 64, 0) >= 0) {
                     str_concat_48 = "";
                     str2time_56 = 0;
                     for (int index_20 = 0; index_20 < 16; index_20++) {
                        str_concat_48 = StringConcatenate(str_concat_48, CharToStr(lia_32[index_20] & 255), CharToStr(lia_32[index_20] >> 8 & 255), CharToStr(lia_32[index_20] >> 16 & 255),
                           CharToStr(lia_32[index_20] >> 24 & 255));
                     }
                     if (StringLen(str_concat_48) > 22) {
                        str2time_56 = StrToTime(StringConcatenate("20", StringSubstr(str_concat_48, 7, 2), ".", StringSubstr(str_concat_48, 10, 2), ".", StringSubstr(str_concat_48, 13, 2),
                           StringSubstr(str_concat_48, 15, 9)));
                     }
                  }
               }
            }
            if (li_28 > 0) closesocket(li_28);
            WSACleanup();
         }
         if (str2time_56 != 0) break;
         li_16++;
         Sleep(500);
      }
      ld_60 = TimeCurrent() - str2time_56;
      ld_60 /= 3600.0;
      ld_ret_4 = NormalizeDouble(ld_60, 1);
      li_0++;
   }
   if (li_0 >= 10) {
      li_unused_24 = 1;
      GetSystemTime(lia_68);
      ls_72 = lia_68[0] & 65535;
      ls_80 = lia_68[0] >> 16 + 100;
      ls_72 = ls_72 + "." + StringSubstr(ls_80, 1);
      ls_80 = lia_68[1] >> 16 + 100;
      ls_72 = ls_72 + "." + StringSubstr(ls_80, 1);
      ls_80 = lia_68[2] & 65535 + 100;
      ls_72 = ls_72 + " " + StringSubstr(ls_80, 1);
      ls_80 = lia_68[2] >> 16 + 100;
      ls_72 = ls_72 + ":" + StringSubstr(ls_80, 1);
      ls_80 = lia_68[3] & 65535 + 100;
      ls_72 = ls_72 + ":" + StringSubstr(ls_80, 1);
      str2time_56 = StrToTime(ls_72);
      ld_60 = TimeCurrent() - str2time_56;
      ld_60 /= 3600.0;
      ld_ret_4 = NormalizeDouble(ld_60, 1);
   }
   return (ld_ret_4);
}

void update() {
   int li_0;
   bool li_8;
   int li_12;
   checkBalanceUpdate();
   updateAverageSpread();
   if (systemtime() > gi_1440) {
      gi_1440 = systemtime() + 600 + MathRand() % 600;
      updateUSDExchangeRate();
      Print("Updating server-related stuff. Next update: " + TimeToStr(gi_1440) + " GMT");
      li_0 = auth(LicenseKey, AccountNumber(), IsDemo(), WindowHandle(Symbol(), Period()), gia_1416);
      if (li_0 == 13 && (!gi_1436)) li_0 = 9;
      switch (li_0) {
      case 1: break;
      case 13:
         Print("Updating news.");
         newsupdate(LicenseKey, AccountServer(), gs_1400, gia_1416);
         Print("News update done.");
         break;
      case 9:
         Print("Updating authentication");
         check();
      }
      if (gi_1436) {
         if (UseServerNews) {
            if (hasnewsdata() == 1) {
               gi_1464 = TRUE;
               li_0 = hasnews(gs_1408, NewsMode(), GMTTimeCurrent());
               if (li_0 == -1) {
                  gs_1428 = "Error retrieving the news from the server.";
                  gi_1460 = FALSE;
               } else {
                  if (li_0 == 1) {
                     if (!(GMTTimeCurrent() > gi_1452) || !(GMTTimeCurrent() < gi_1456)) {
                        gs_1428 = nextnewstext(gs_1408, NewsMode(), GMTTimeCurrent());
                        gs_1428 = StringSubstr(gs_1428, 0, StringFind(gs_1428, 
                        "\n"));
                        gi_1452 = nextnewsstart(gs_1408, NewsMode(), GMTTimeCurrent()) - 60 * FreezeBeforeNewsMinutes;
                        gi_1456 = nextnewsend(gs_1408, NewsMode(), GMTTimeCurrent()) + 60 * ResumeAfterNewsMinutes;
                        if (gi_1452 != 0 && gi_1456 != 0) gi_1460 = TRUE;
                     }
                  }
               }
            } else {
               gi_1464 = FALSE;
               gi_1440 = 0;
            }
         }
         gi_1476 = TRUE;
      } else {
         if (gi_1444) {
            gi_1440 = systemtime() + 60;
            Print("Rescheduled update to: " + TimeToStr(gi_1440) + " GMT");
         }
      }
   }
   if (gi_1436) {
      if (AutoGMTOffset) {
         li_8 = FALSE;
         if (g_global_var_1448 == 0) li_8 = TRUE;
         else {
            li_12 = systemtime();
            if (g_global_var_1448 < li_12 - 129600 && TimeDayOfWeek(li_12) == 0 || TimeDayOfWeek(li_12) == 1) li_8 = TRUE;
         }
         if (li_8) updateGMTOffset();
      }
      if (Mode > 0 && gi_1476) {
         if (GetOrderCount() == 0 || (!gi_1468)) {
            getparams();
            if (gi_1468) gi_1476 = FALSE;
         }
      }
      if (gi_1460 && (!Freeze_After_TP)) {
         if (GMTTimeCurrent() > gi_1452 && GMTTimeCurrent() < gi_1456) {
            if (!gi_1120) {
               gi_1120 = TRUE;
               if (NewsAlertPopups) Alert(gs_1408 + " " + modeText(Mode) + ": FreezeAfterTP enabled due to news.");
            }
         } else {
            if (gi_1120) {
               gi_1120 = FALSE;
               if (NewsAlertPopups) Alert(gs_1408 + " " + modeText(Mode) + ": trading resumed.");
            }
         }
      }
   }
}

string modeText(int ai_0) {
   string ls_ret_4 = "";
   switch (ai_0) {
   case 1:
      ls_ret_4 = "-HV- long cycle";
      break;
   case 2:
      ls_ret_4 = "-HV- short cycle";
      break;
   case 3:
      ls_ret_4 = "-NV-";
      break;
   case 4:
      ls_ret_4 = "-LV-";
      break;
   case 5:
      ls_ret_4 = "Power long cycle";
      break;
   case 6:
      ls_ret_4 = "Power short cycle";
   }
   return (ls_ret_4);
}

int fun0(int ai_0) {
   double ld_4 = 0;
   double ld_12 = 0;
   switch (ai_0) {
   case 0:
      ld_4 = Multiplier_1;
      ld_12 = Basket_Take_Profit_1;
      break;
   case 1:
      ld_4 = Multiplier_2;
      ld_12 = Basket_Take_Profit_2;
      break;
   case 2:
      ld_4 = Multiplier_3;
      ld_12 = Basket_Take_Profit_3;
      break;
   case 3:
      ld_4 = Multiplier_4;
      ld_12 = Basket_Take_Profit_4;
      break;
   case 4:
      ld_4 = Multiplier_5;
      ld_12 = Basket_Take_Profit_5;
      break;
   case 5:
      ld_4 = Multiplier_6;
      ld_12 = Basket_Take_Profit_6;
      break;
   case 6:
      ld_4 = Multiplier_7;
      ld_12 = Basket_Take_Profit_7;
      break;
   case 7:
      ld_4 = Multiplier_8;
      ld_12 = Basket_Take_Profit_8;
      break;
   case 8:
      ld_4 = Multiplier_9;
      ld_12 = Basket_Take_Profit_9;
      break;
   case 9:
      ld_4 = Multiplier_10;
      ld_12 = Basket_Take_Profit_10;
      break;
   case 10:
      ld_4 = Multiplier_11;
      ld_12 = Basket_Take_Profit_11;
      break;
   case 11:
      ld_4 = Multiplier_12;
      ld_12 = Basket_Take_Profit_12;
      break;
   case 12:
      ld_4 = Multiplier_13;
      ld_12 = Basket_Take_Profit_13;
      break;
   case 13:
      ld_4 = Multiplier_14;
      ld_12 = Basket_Take_Profit_14;
      break;
   case 14:
      ld_4 = Multiplier_15;
      ld_12 = Basket_Take_Profit_15;
      break;
   case 15:
      ld_4 = Multiplier_16;
      ld_12 = Basket_Take_Profit_16;
      break;
   case 16:
      ld_4 = Multiplier_17;
      ld_12 = Basket_Take_Profit_17;
      break;
   case 17:
      ld_4 = Multiplier_18;
      ld_12 = Basket_Take_Profit_18;
      break;
   case 18:
      ld_4 = Multiplier_19;
      ld_12 = Basket_Take_Profit_19;
      break;
   case 19:
      ld_4 = Multiplier_20;
      ld_12 = Basket_Take_Profit_20;
      break;
   case 20:
      ld_4 = Multiplier_21;
      ld_12 = Basket_Take_Profit_21;
      break;
   case 21:
      ld_4 = Multiplier_22;
      ld_12 = Basket_Take_Profit_22;
      break;
   case 22:
      ld_4 = Multiplier_23;
      ld_12 = Basket_Take_Profit_23;
      break;
   case 23:
      ld_4 = Multiplier_24;
      ld_12 = Basket_Take_Profit_24;
      break;
   case 24:
      ld_4 = Multiplier_25;
      ld_12 = Basket_Take_Profit_25;
      break;
   default:
      ld_4 = gd_1136;
      ld_12 = Basket_Take_Profit;
   }
   bool li_ret_24 = FALSE;
   if (ld_4 > 0.0 && gd_1136 != ld_4) {
      gd_1136 = ld_4;
      li_ret_24 = TRUE;
   }
   if (ld_12 > 0.0 && Basket_Take_Profit != ld_12) {
      Basket_Take_Profit = ld_12;
      li_ret_24 = TRUE;
   }
   return (li_ret_24);
}

int CloseBuy() {
   int error_4;
   int li_12;
   bool is_closed_16;
   int ticket_20;
   bool li_ret_0 = FALSE;
   for (int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--) {
      OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == Magic_Number) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_BUY) {
               RefreshRates();
               li_12 = Close_Order_Attempts;
               is_closed_16 = FALSE;
               while (is_closed_16 == 0 && li_12 >= 0) {
                  li_12--;
                  ticket_20 = OrderTicket();
                  is_closed_16 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, Violet);
                  if (!is_closed_16) {
                     error_4 = GetLastError();
                     Print("Forex Envy OrderClose FAILED : Ticket [" + ticket_20 + "]. " + "Error " + error_4 + " [" + ErrorDescription(error_4) + ".]");
                     if (error_4 == 146/* TRADE_CONTEXT_BUSY */) Sleep(50);
                  } else is_closed_16 = TRUE;
               }
            }
         }
      }
   }
   return (li_ret_0);
}

int CloseSell() {
   int error_4;
   int li_12;
   bool is_closed_16;
   int ticket_20;
   bool li_ret_0 = FALSE;
   for (int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--) {
      OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == Magic_Number) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_SELL) {
               RefreshRates();
               li_12 = Close_Order_Attempts;
               is_closed_16 = FALSE;
               while (is_closed_16 == 0 && li_12 >= 0) {
                  li_12--;
                  ticket_20 = OrderTicket();
                  is_closed_16 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, Violet);
                  if (!is_closed_16) {
                     error_4 = GetLastError();
                     Print("Forex Envy OrderClose FAILED : Ticket [" + ticket_20 + "]. " + "Error " + error_4 + " [" + ErrorDescription(error_4) + ".]");
                     if (error_4 == 146/* TRADE_CONTEXT_BUSY */) Sleep(50);
                  } else is_closed_16 = TRUE;
               }
            }
         }
      }
   }
   return (li_ret_0);
}

int resetBuyOrders() {
   ObjectDelete("Buy_Target");
   ObjectDelete("Buy_StopLoss");
   for (int li_0 = 24; li_0 >= 0; li_0--) {
      if (gia_1344[li_0] > 0 && gia_1348[li_0] == 0) {
         gia_1344[li_0] = 0;
         gia_1348[li_0] = 0;
         gda_1352[li_0] = 0;
         gda_1356[li_0] = 0;
         gda_1360[li_0] = 0;
         gda_1364[li_0] = 0;
         GlobalVariableSet(Symbol() + "ticketS4" + li_0, gia_1344[li_0]);
         GlobalVariableSet(Symbol() + "typeS4" + li_0, gia_1348[li_0]);
         GlobalVariableSet(Symbol() + "lotsS4" + li_0, gda_1352[li_0]);
         GlobalVariableSet(Symbol() + "priceS4" + li_0, gda_1356[li_0]);
         GlobalVariableSet(Symbol() + "stoplossS4" + li_0, gda_1360[li_0]);
         GlobalVariableSet(Symbol() + "takeprofitS4" + li_0, gda_1364[li_0]);
      }
   }
   return (0);
}

int resetSellOrders() {
   ObjectDelete("Sell_Target");
   ObjectDelete("Sell_StopLoss");
   for (int li_0 = 24; li_0 >= 0; li_0--) {
      if (gia_1344[li_0] > 0 && gia_1348[li_0] == 1) {
         gia_1344[li_0] = 0;
         gia_1348[li_0] = 0;
         gda_1352[li_0] = 0;
         gda_1356[li_0] = 0;
         gda_1360[li_0] = 0;
         gda_1364[li_0] = 0;
         GlobalVariableSet(Symbol() + "ticketS4" + li_0, gia_1344[li_0]);
         GlobalVariableSet(Symbol() + "typeS4" + li_0, gia_1348[li_0]);
         GlobalVariableSet(Symbol() + "lotsS4" + li_0, gda_1352[li_0]);
         GlobalVariableSet(Symbol() + "priceS4" + li_0, gda_1356[li_0]);
         GlobalVariableSet(Symbol() + "stoplossS4" + li_0, gda_1360[li_0]);
         GlobalVariableSet(Symbol() + "takeprofitS4" + li_0, gda_1364[li_0]);
      }
   }
   return (0);
}

int HideCheckS4SLTP() {
   int li_unused_0 = 0;
   for (int index_8 = 0; index_8 < 25; index_8++) {
      if (gia_1344[index_8] > 0) {
         if (gia_1348[index_8] == 0) {
            if (NormalizeDouble(Bid, Digits) >= gda_1364[index_8] || NormalizeDouble(Bid, Digits) <= gda_1360[index_8]) {
               CloseBuy();
               resetBuyOrders();
            }
         }
         if (gia_1348[index_8] == 1) {
            if (NormalizeDouble(Ask, Digits) <= gda_1364[index_8] || NormalizeDouble(Ask, Digits) >= gda_1360[index_8]) {
               CloseSell();
               resetSellOrders();
            }
         }
      }
   }
   return (0);
}

int HideOrderModifyS4(int ai_0, double ad_unused_4, double ad_12, double ad_20, int ai_unused_28, int ai_unused_32) {
   for (int index_36 = 0; index_36 < 25; index_36++) {
      if (gia_1344[index_36] == ai_0) {
         gda_1360[index_36] = NormalizeDouble(ad_12, Digits);
         gda_1364[index_36] = NormalizeDouble(ad_20, Digits);
         GlobalVariableSet(Symbol() + "stoplossS4" + index_36, gda_1360[index_36]);
         GlobalVariableSet(Symbol() + "takeprofitS4" + index_36, gda_1364[index_36]);
         break;
      }
   }
   return (1);
}

double HideCheckTakeProfitS4(int ai_0) {
   for (int index_4 = 0; index_4 < 25; index_4++)
      if (gia_1344[index_4] == ai_0) return (gda_1364[index_4]);
   return (0);
}

double HideCheckStopLossS4(int ai_0) {
   for (int index_4 = 0; index_4 < 25; index_4++)
      if (gia_1344[index_4] == ai_0) return (gda_1360[index_4]);
   return (0);
}

void ResetTicketS4(int ai_0) {
   for (int index_4 = 0; index_4 < 25; index_4++) {
      if (gia_1344[index_4] == ai_0) {
         gia_1344[index_4] = 0;
         GlobalVariableSet(Symbol() + "ticketS4" + index_4, gia_1344[index_4]);
         return;
      }
   }
}

void Log(string as_0) {
   if (gi_1320 > 0) Print(as_0);
}

void calculatePLBalance() {
   gd_1108 = 0;
   int hist_total_0 = OrdersHistoryTotal();
   for (int pos_4 = 0; pos_4 < hist_total_0; pos_4++) {
      OrderSelect(pos_4, SELECT_BY_POS, MODE_HISTORY);
      if (OrderMagicNumber() == Magic_Number) gd_1108 += OrderProfit() + OrderSwap();
   }
}

int GetLotDigits() {
   double ld_0 = MarketInfo(Symbol(), MODE_MINLOT);
   for (int count_8 = 0; ld_0 < 1.0; count_8++) ld_0 = 10.0 * ld_0;
   return (count_8);
}

double CalcLots(double a_minlot_0) {
   double minlot_8;
   double ld_16 = AccountEquity() - gi_1148;
   double ld_24 = gi_1152;
   double ld_32 = gi_1156;
   if (gi_1152 == 0 || gi_1156 == 0) minlot_8 = a_minlot_0;
   else {
      ld_24 = gi_1148 * ld_24 / 100.0;
      Print("tmp=" + ld_16 + ",AccountEquity()=" + AccountEquity() + ",InitEquity=" + gi_1148);
      ld_32 /= 100.0;
      if (ld_16 > 0.0) ld_16 = MathPow(ld_32 + 1.0, ld_16 / ld_24);
      else {
         if (ld_16 < 0.0) ld_16 = MathPow(1 - ld_32, MathAbs(ld_16 / ld_24));
         else ld_16 = 1;
      }
      minlot_8 = NormalizeDouble(a_minlot_0 * ld_16, GetLotDigits());
      if (minlot_8 < MarketInfo(Symbol(), MODE_MINLOT)) minlot_8 = MarketInfo(Symbol(), MODE_MINLOT);
   }
   if (minlot_8 < 0.0) Print("ERROR tmp=" + ld_16 + ",a=" + ld_24 + ",b=" + ld_32 + ",AccountEquity()=" + AccountEquity());
   return (minlot_8);
}

int deinit() {
   uninit(WindowHandle(Symbol(), Period()));
   gi_1464 = FALSE;
   gi_1444 = FALSE;
   gi_1340 = FALSE;
   gi_1116 = FALSE;
   gi_1120 = FALSE;
   gi_1124 = TRUE;
   gi_1128 = TRUE;
   gi_1132 = FALSE;
   gi_1324 = FALSE;
   gi_1436 = FALSE;
   gi_1460 = FALSE;
   gi_1440 = 0;
   g_global_var_1448 = 0;
   gi_1468 = FALSE;
   gi_1472 = TRUE;
   gi_1476 = FALSE;
   gs_1496 = "";
   gi_1452 = 0;
   gi_1456 = 0;
   gi_1504 = FALSE;
   ObjectDelete("Buy_Target");
   ObjectDelete("Buy_StopLoss");
   ObjectDelete("Sell_Target");
   ObjectDelete("Sell_StopLoss");
   return (0);
}

int GetOrderCount() {
   int count_0 = 0;
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == Magic_Number && OrderSymbol() == Symbol()) {
            if (OrderType() == OP_BUY) count_0++;
            if (OrderType() == OP_SELL) count_0++;
         }
      }
   }
   return (count_0);
}

int CheckStopLossZero() {
   bool bool_4;
   double ld_12;
   int li_20;
   bool li_ret_0 = FALSE;
   for (int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == Magic_Number && OrderSymbol() == Symbol()) {
            RefreshRates();
            if (OrderType() == OP_BUY) {
               if (OrderStopLoss() == 0.0) {
                  ld_12 = OrderOpenPrice() - Basket_Stop_Loss * g_point_1332;
                  li_20 = Close_Order_Attempts;
                  bool_4 = FALSE;
                  while (bool_4 == FALSE && li_20 >= 0) {
                     li_20--;
                     RefreshRates();
                     bool_4 = OrderModify(OrderTicket(), NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(ld_12, Digits), OrderTakeProfit(), 0, Black);
                     if (!bool_4) {
                        g_error_1376 = GetLastError();
                        if (g_error_1376 == 146/* TRADE_CONTEXT_BUSY */) {
                           Sleep(50);
                           continue;
                        }
                     }
                     bool_4 = TRUE;
                  }
               }
            }
            if (OrderType() == OP_SELL) {
               if (OrderStopLoss() == 0.0) {
                  ld_12 = OrderOpenPrice() + Basket_Stop_Loss * g_point_1332;
                  li_20 = Close_Order_Attempts;
                  bool_4 = FALSE;
                  while (bool_4 == FALSE && li_20 >= 0) {
                     li_20--;
                     RefreshRates();
                     bool_4 = OrderModify(OrderTicket(), NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(ld_12, Digits), OrderTakeProfit(), 0, Black);
                     if (!bool_4) {
                        g_error_1376 = GetLastError();
                        if (g_error_1376 == 146/* TRADE_CONTEXT_BUSY */) {
                           Sleep(50);
                           continue;
                        }
                     }
                     bool_4 = TRUE;
                  }
               }
            }
         }
      }
   }
   return (li_ret_0);
}

int showBTPSL() {
   double price_12;
   double price_20;
   double price_28;
   double price_36;
   bool li_0 = FALSE;
   bool li_4 = FALSE;
   ObjectDelete("Buy_Target");
   ObjectDelete("Buy_StopLoss");
   ObjectDelete("Sell_Target");
   ObjectDelete("Sell_StopLoss");
   for (int li_8 = 24; li_8 >= 0; li_8--) {
      if (gia_1344[li_8] > 0 && gia_1348[li_8] == 0) {
         if (SFM_Visual_TP == TRUE) {
            price_12 = gda_1364[li_8];
            ObjectDelete("Buy_Target");
            ObjectCreate("Buy_Target", OBJ_HLINE, 0, Time[1], price_12);
            ObjectSet("Buy_Target", OBJPROP_COLOR, SFM_Visual_TP_Color);
         }
         if (SFM_Visual_SL == TRUE) {
            price_20 = gda_1360[li_8];
            ObjectDelete("Buy_StopLoss");
            ObjectCreate("Buy_StopLoss", OBJ_HLINE, 0, Time[1], price_20);
            ObjectSet("Buy_StopLoss", OBJPROP_COLOR, SFM_Visual_SL_Color);
         }
         li_0 = TRUE;
      }
      if (gia_1344[li_8] > 0 && gia_1348[li_8] == 1) {
         if (SFM_Visual_TP == TRUE) {
            price_28 = gda_1364[li_8];
            ObjectDelete("Sell_Target");
            ObjectCreate("Sell_Target", OBJ_HLINE, 0, Time[1], price_28);
            ObjectSet("Sell_Target", OBJPROP_COLOR, SFM_Visual_TP_Color);
         }
         if (SFM_Visual_SL == TRUE) {
            price_36 = gda_1360[li_8];
            ObjectDelete("Sell_StopLoss");
            ObjectCreate("Sell_StopLoss", OBJ_HLINE, 0, Time[1], price_36);
            ObjectSet("Sell_StopLoss", OBJPROP_COLOR, SFM_Visual_SL_Color);
         }
         li_4 = TRUE;
      }
      if (li_0 == TRUE && li_4 == TRUE) break;
   }
   return (0);
}

int SetOrders() {
   ObjectDelete("Buy_Target");
   ObjectDelete("Buy_StopLoss");
   ObjectDelete("Sell_Target");
   ObjectDelete("Sell_StopLoss");
   for (int li_0 = 24; li_0 >= 0; li_0--) {
      if (GlobalVariableCheck(Symbol() + "ticketS4" + li_0) == TRUE) {
         gia_1344[li_0] = GlobalVariableGet(Symbol() + "ticketS4" + li_0);
         gia_1348[li_0] = GlobalVariableGet(Symbol() + "typeS4" + li_0);
         gda_1352[li_0] = GlobalVariableGet(Symbol() + "lotsS4" + li_0);
         gda_1356[li_0] = GlobalVariableGet(Symbol() + "priceS4" + li_0);
         gda_1360[li_0] = GlobalVariableGet(Symbol() + "stoplossS4" + li_0);
         gda_1364[li_0] = GlobalVariableGet(Symbol() + "takeprofitS4" + li_0);
      }
   }
   return (0);
}

int resetOrders() {
   for (int li_0 = 24; li_0 >= 0; li_0--) {
      gia_1344[li_0] = 0;
      gia_1348[li_0] = 0;
      gda_1352[li_0] = 0;
      gda_1356[li_0] = 0;
      gda_1360[li_0] = 0;
      gda_1364[li_0] = 0;
   }
   return (0);
}

int resetGlobalOrders() {
   for (int li_0 = 24; li_0 >= 0; li_0--) {
      GlobalVariableSet(Symbol() + "ticketS4" + li_0, gia_1344[li_0]);
      GlobalVariableSet(Symbol() + "typeS4" + li_0, gia_1348[li_0]);
      GlobalVariableSet(Symbol() + "lotsS4" + li_0, gda_1352[li_0]);
      GlobalVariableSet(Symbol() + "priceS4" + li_0, gda_1356[li_0]);
      GlobalVariableSet(Symbol() + "stoplossS4" + li_0, gda_1360[li_0]);
      GlobalVariableSet(Symbol() + "takeprofitS4" + li_0, gda_1364[li_0]);
   }
   return (0);
}

int init() {
   int li_0;
   if (IsTesting() || IsOptimization()) {
      AutoGMTOffset = FALSE;
      UseServerNews = FALSE;
      if (!IsConnected() || AccountNumber() == 16384) {
         Print("You need to be connected to the broker in order to backtest.");
         Comment("You need to be connected to the broker in order to backtest.");
         gi_1472 = FALSE;
         return (0);
      }
   }
   if (Mode < 0 || Mode > 8) {
      Comment("Invalid mode selected.");
      return (0);
   }
   Comment("Initialization process started. Please wait, this might take a few minutes.");
   RefreshRates();
   updateMagicNumber();
   currencyPairSetup();
   if (RiskFactor != 1.0) {
      if (RiskFactor <= 0.0) RiskFactor = 1;
      if (RiskFactor > 5.0) {
         Alert("Warning: the risk factor you selected (" + RiskFactor + ") is higher than the maximum supported! Setting it to 5.");
         RiskFactor = 5;
      } else
         if (RiskFactor > 2.0) Alert("Warning: the risk factor you selected (" + RiskFactor + ") is very dangerous!");
   }
   check();
   if (gi_1436) Comment("Authentication successful. The chart display will update soon after the next incoming tick.");
   RefreshRates();
   if (Mode == 0 && Multiplier == 0.0) {
      gi_1472 = FALSE;
      Alert("Attempting to start the EA with incorrect manual settings. The EA is disabled, please load a valid settings file.");
      Comment("Attempting to start the EA with incorrect manual settings. The EA is disabled, please load a valid settings file.");
      return (0);
   }
   updateUSDExchangeRate();
   if ((!IsTesting()) && !IsOptimization()) {
      li_0 = mb(LicenseKey);
      if (li_0 > 0 && AccountBalance() * gd_1480 > li_0) {
         gi_1472 = FALSE;
         Comment("Your account balance exceeds the amount allowed by your Forex Envy license.");
         return (0);
      }
   }
   for (int index_4 = 0; index_4 < 25; index_4++) {
      gia_1344[index_4] = 0;
      gia_1348[index_4] = 0;
      gda_1352[index_4] = 0.0;
      gda_1356[index_4] = 0;
      gda_1360[index_4] = 0;
      gda_1364[index_4] = 0;
   }
   if (Server_Friendly_Mode == TRUE) SetOrders();
   if (Freeze_After_TP == TRUE) gi_1120 = TRUE;
   else gi_1120 = FALSE;
   if (Freeze_After_TP_Scheduler == TRUE) gi_1124 = TRUE;
   else gi_1124 = FALSE;
   if (Support_ECN == TRUE) gi_1128 = TRUE;
   else gi_1128 = FALSE;
   if (Chicken_Out == TRUE) gi_1132 = TRUE;
   else gi_1132 = FALSE;
   if (Server_Friendly_Mode == TRUE) gi_1340 = TRUE;
   else gi_1340 = FALSE;
   if (Period() != PERIOD_M30) {
      Print("ERROR -- Forex Envy should be attached to " + Symbol() + " 30 minute chart window");
      Alert("ERROR -- Forex Envy should be attached to " + Symbol() + " 30 minute chart window");
      return (0);
   }
   gi_unused_76 = 1;
   gd_1136 = Multiplier;
   if (Digits == 3) g_point_1332 = 0.01;
   else {
      if (Digits == 5) g_point_1332 = 0.0001;
      else g_point_1332 = Point;
   }
   g_point_1240 = g_point_1332;
   gi_1248 = MathRound((-MathLog(MarketInfo(Symbol(), MODE_LOTSTEP))) / 2.302585093);
   gi_1288 = FALSE;
   gi_1292 = FALSE;
   gi_1296 = FALSE;
   gi_1300 = FALSE;
   g_ticket_1304 = -1;
   gi_1180 = FALSE;
   g_cmd_1308 = -1;
   return (0);
}

double GetLastLotSize(int ai_0) {
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS)) {
         if (OrderMagicNumber() == Magic_Number) {
            if (StringFind(OrderComment(), gs__hedged_1312) == -1) {
               Log("GetLastLotSize " + ai_0 + ",OrderLots()=" + OrderLots());
               return (OrderLots());
            }
         }
      }
   }
   Log("GetLastLotSize " + ai_0 + " wasnt found");
   return (0);
}

double GetLastLotSize_Buy(int ai_0) {
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS)) {
         if (OrderMagicNumber() == Magic_Number && OrderType() == OP_BUY) {
            if (StringFind(OrderComment(), gs__hedged_1312) == -1) {
               Log("GetLastLotSizeBuy " + ai_0 + ",OrderLots()=" + OrderLots());
               return (OrderLots());
            }
         }
      }
   }
   Log("GetLastLotSizeBuy " + ai_0 + " wasnt found");
   return (0);
}

double GetLastLotSize_Sell(int ai_0) {
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS)) {
         if (OrderMagicNumber() == Magic_Number && OrderType() == OP_SELL) {
            if (StringFind(OrderComment(), gs__hedged_1312) == -1) {
               Log("GetLastLotSizeSell " + ai_0 + ",OrderLots()=" + OrderLots());
               return (OrderLots());
            }
         }
      }
   }
   Log("GetLastLotSizeSell " + ai_0 + " wasnt found");
   return (0);
}

int GetLastCloseTime_Buy() {
   int hist_total_0 = OrdersHistoryTotal();
   for (int pos_4 = hist_total_0 - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS, MODE_HISTORY))
         if (OrderMagicNumber() == Magic_Number && OrderSymbol() == Symbol() && OrderType() == OP_BUY) return (OrderCloseTime());
   }
   return (0);
}

int GetLastCloseTime_Sell() {
   int hist_total_0 = OrdersHistoryTotal();
   for (int pos_4 = hist_total_0 - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS, MODE_HISTORY))
         if (OrderMagicNumber() == Magic_Number && OrderSymbol() == Symbol() && OrderType() == OP_SELL) return (OrderCloseTime());
   }
   return (0);
}

int GetOrderCount_Buy() {
   int count_0 = 0;
   int order_total_4 = OrdersTotal();
   for (int pos_8 = order_total_4 - 1; pos_8 >= 0; pos_8--) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES))
         if (OrderMagicNumber() == Magic_Number && OrderSymbol() == Symbol() && OrderType() == OP_BUY) count_0++;
   }
   return (count_0);
}

int GetOrderCount_Sell() {
   int count_0 = 0;
   int order_total_4 = OrdersTotal();
   for (int pos_8 = order_total_4 - 1; pos_8 >= 0; pos_8--) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES))
         if (OrderMagicNumber() == Magic_Number && OrderSymbol() == Symbol() && OrderType() == OP_SELL) count_0++;
   }
   return (count_0);
}

int OpenBuy(bool ai_0 = FALSE) {
   int ticket_4;
   double lots_8;
   int li_48;
   bool bool_52;
   if (TimeCurrent() - gi_1104 < GetLastCloseTime_Buy())
      if (GetOrderCount_Buy() != 0) return (0);
   double ld_16 = 0;
   double ld_24 = 0;
   string ls_32 = "";
   bool li_ret_40 = TRUE;
   if (TimeCurrent() - g_datetime_1236 < 60) return (0);
   if (ai_0 && (!gi_1296)) return (0);
   if (!GlobalVariableCheck("PERMISSION")) {
      GlobalVariableSet("PERMISSION", TimeCurrent());
      if (!gi_1128) {
         if (ai_0) {
            if (gi_1340 == TRUE) {
               if (OrderSelect(g_ticket_1304, SELECT_BY_TICKET)) ld_24 = HideCheckTakeProfitS4(g_ticket_1304) - MarketInfo(Symbol(), MODE_SPREAD) * Point;
            } else
               if (OrderSelect(g_ticket_1304, SELECT_BY_TICKET)) ld_24 = OrderTakeProfit() - MarketInfo(Symbol(), MODE_SPREAD) * Point;
         } else ld_16 = Ask + Basket_Take_Profit * g_point_1332;
      }
      if (gi_1324 == FALSE) {
         if (ai_0) lots_8 = NormalizeDouble(GetLastLotSize(1) * gd_1224, 2);
         else lots_8 = CalcLots(gd_1172);
      } else lots_8 = l(LicenseKey, GetLastLotSize_Buy(0), Base_Lot_Size, gd_1136, gia_1416);
      if (Basket_Stop_Loss > 0) ld_24 = Ask - Basket_Stop_Loss * g_point_1332;
      if (!gi_1128) {
         if (ld_16 == 0.0) ld_16 = Ask + Basket_Take_Profit * g_point_1332;
         if (ld_24 == 0.0) ld_24 = Ask - Basket_Stop_Loss * g_point_1332;
         if (gi_1340 == TRUE) {
            for (int index_44 = 0; index_44 < 25; index_44++)
               if (gia_1344[index_44] <= 0) break;
            if (index_44 < 25) {
               ticket_4 = OrderSend(Symbol(), OP_BUY, lots_8, NormalizeDouble(Ask, Digits), Slippage, NormalizeDouble(ld_24, Digits), NormalizeDouble(ld_16, Digits), EA_Name + ls_32,
                  Magic_Number, 0, Green);
               if (ticket_4 > 0) {
                  gia_1344[index_44] = ticket_4;
                  gia_1348[index_44] = 0;
                  gda_1352[index_44] = lots_8;
                  gda_1356[index_44] = NormalizeDouble(Ask, Digits);
                  gda_1360[index_44] = 0;
                  gda_1364[index_44] = 0;
                  GlobalVariableSet(Symbol() + "ticketS4" + index_44, gia_1344[index_44]);
                  GlobalVariableSet(Symbol() + "typeS4" + index_44, gia_1348[index_44]);
                  GlobalVariableSet(Symbol() + "lotsS4" + index_44, gda_1352[index_44]);
                  GlobalVariableSet(Symbol() + "priceS4" + index_44, gda_1356[index_44]);
                  GlobalVariableSet(Symbol() + "stoplossS4" + index_44, gda_1360[index_44]);
                  GlobalVariableSet(Symbol() + "takeprofitS4" + index_44, gda_1364[index_44]);
               }
            }
         } else {
            ticket_4 = OrderSend(Symbol(), OP_BUY, lots_8, NormalizeDouble(Ask, Digits), Slippage, NormalizeDouble(ld_24, Digits), NormalizeDouble(ld_16, Digits), EA_Name + ls_32,
               Magic_Number, 0, Green);
         }
      } else {
         if (gi_1340 == TRUE) {
            for (index_44 = 0; index_44 < 25; index_44++)
               if (gia_1344[index_44] <= 0) break;
            if (index_44 < 25) {
               ticket_4 = OrderSend(Symbol(), OP_BUY, lots_8, NormalizeDouble(Ask, Digits), Slippage, 0, 0, EA_Name + ls_32, Magic_Number, 0, Green);
               if (ticket_4 > 0) {
                  gia_1344[index_44] = ticket_4;
                  gia_1348[index_44] = 0;
                  gda_1352[index_44] = lots_8;
                  gda_1356[index_44] = NormalizeDouble(Ask, Digits);
                  gda_1360[index_44] = 0;
                  gda_1364[index_44] = 0;
                  GlobalVariableSet(Symbol() + "ticketS4" + index_44, gia_1344[index_44]);
                  GlobalVariableSet(Symbol() + "typeS4" + index_44, gia_1348[index_44]);
                  GlobalVariableSet(Symbol() + "lotsS4" + index_44, gda_1352[index_44]);
                  GlobalVariableSet(Symbol() + "priceS4" + index_44, gda_1356[index_44]);
                  GlobalVariableSet(Symbol() + "stoplossS4" + index_44, gda_1360[index_44]);
                  GlobalVariableSet(Symbol() + "takeprofitS4" + index_44, gda_1364[index_44]);
               }
               Sleep(1000);
            }
         } else {
            ticket_4 = OrderSend(Symbol(), OP_BUY, lots_8, NormalizeDouble(Ask, Digits), Slippage, 0, 0, EA_Name + ls_32, Magic_Number, 0, Green);
            Sleep(1000);
         }
         if (ticket_4 >= 0) {
            if (ld_16 == 0.0) ld_16 = Ask + Basket_Take_Profit * g_point_1332;
            if (ld_24 == 0.0) ld_24 = Ask - Basket_Stop_Loss * g_point_1332;
            if (gi_1340 == TRUE) HideOrderModifyS4(ticket_4, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(ld_24, Digits), NormalizeDouble(ld_16, Digits), 0, 0);
            else {
               li_48 = Close_Order_Attempts;
               bool_52 = FALSE;
               while (bool_52 == FALSE && li_48 >= 0) {
                  li_48--;
                  RefreshRates();
                  bool_52 = OrderModify(ticket_4, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(ld_24, Digits), NormalizeDouble(ld_16, Digits), 0, Black);
                  if (!bool_52) {
                     g_error_1376 = GetLastError();
                     if (g_error_1376 == 146/* TRADE_CONTEXT_BUSY */) {
                        Sleep(50);
                        continue;
                     }
                  }
                  bool_52 = TRUE;
               }
            }
         }
      }
      g_datetime_1236 = TimeCurrent();
      if (ticket_4 != -1) {
         if (!ai_0) {
            g_ticket_1304 = ticket_4;
            Log("BUY hedgedTicket=" + g_ticket_1304);
         } else {
            Log("BUY Envy_ticket=" + ticket_4);
            g_cmd_1308 = 0;
         }
      } else {
         Log("failed sell");
         li_ret_40 = FALSE;
      }
   }
   GlobalVariableDel("PERMISSION");
   return (li_ret_40);
}

int OpenBuyNBP(bool ai_0, double ad_4) {
   int ticket_12;
   double lots_16;
   int li_56;
   bool bool_60;
   if (TimeCurrent() - gi_1104 < GetLastCloseTime_Buy())
      if (GetOrderCount_Buy() != 0) return (0);
   double ld_24 = 0;
   double ld_32 = 0;
   string ls_40 = "";
   bool li_ret_48 = TRUE;
   if (TimeCurrent() - g_datetime_1236 < 60) return (0);
   if (ai_0 && (!gi_1296)) return (0);
   if (!GlobalVariableCheck("PERMISSION")) {
      GlobalVariableSet("PERMISSION", TimeCurrent());
      if (!gi_1128) {
         if (ai_0) {
            if (gi_1340 == TRUE) {
               if (OrderSelect(g_ticket_1304, SELECT_BY_TICKET)) ld_32 = HideCheckTakeProfitS4(g_ticket_1304) - MarketInfo(Symbol(), MODE_SPREAD) * Point;
            } else
               if (OrderSelect(g_ticket_1304, SELECT_BY_TICKET)) ld_32 = OrderTakeProfit() - MarketInfo(Symbol(), MODE_SPREAD) * Point;
         } else ld_24 = ad_4;
      }
      if (gi_1324 == FALSE) {
         if (ai_0) lots_16 = NormalizeDouble(GetLastLotSize(1) * gd_1224, 2);
         else lots_16 = CalcLots(gd_1172);
      } else lots_16 = l(LicenseKey, GetLastLotSize_Buy(0), Base_Lot_Size, gd_1136, gia_1416);
      if (Basket_Stop_Loss > 0) ld_32 = Ask - Basket_Stop_Loss * g_point_1332;
      if (!gi_1128) {
         if (ld_24 == 0.0) {
            if (ad_4 > 0.0) ld_24 = ad_4;
            else ld_24 = Ask + Basket_Take_Profit * g_point_1332;
         }
         if (ld_32 == 0.0) ld_32 = Ask - Basket_Stop_Loss * g_point_1332;
         if (gi_1340 == TRUE) {
            for (int index_52 = 0; index_52 < 25; index_52++)
               if (gia_1344[index_52] <= 0) break;
            if (index_52 < 25) {
               ticket_12 = OrderSend(Symbol(), OP_BUY, lots_16, NormalizeDouble(Ask, Digits), 0, NormalizeDouble(ld_32, Digits), NormalizeDouble(ld_24, Digits), EA_Name + ls_40,
                  Magic_Number, 0, Green);
               if (ticket_12 > 0) {
                  gia_1344[index_52] = ticket_12;
                  gia_1348[index_52] = 0;
                  gda_1352[index_52] = lots_16;
                  gda_1356[index_52] = NormalizeDouble(Ask, Digits);
                  gda_1360[index_52] = NormalizeDouble(ld_32, Digits);
                  gda_1364[index_52] = NormalizeDouble(ld_24, Digits);
                  GlobalVariableSet(Symbol() + "ticketS4" + index_52, gia_1344[index_52]);
                  GlobalVariableSet(Symbol() + "typeS4" + index_52, gia_1348[index_52]);
                  GlobalVariableSet(Symbol() + "lotsS4" + index_52, gda_1352[index_52]);
                  GlobalVariableSet(Symbol() + "priceS4" + index_52, gda_1356[index_52]);
                  GlobalVariableSet(Symbol() + "stoplossS4" + index_52, gda_1360[index_52]);
                  GlobalVariableSet(Symbol() + "takeprofitS4" + index_52, gda_1364[index_52]);
               }
            }
         } else {
            ticket_12 = OrderSend(Symbol(), OP_BUY, lots_16, NormalizeDouble(Ask, Digits), 0, NormalizeDouble(ld_32, Digits), NormalizeDouble(ld_24, Digits), EA_Name + ls_40,
               Magic_Number, 0, Green);
         }
      } else {
         if (gi_1340 == TRUE) {
            for (index_52 = 0; index_52 < 25; index_52++)
               if (gia_1344[index_52] <= 0) break;
            if (index_52 < 25) {
               ticket_12 = OrderSend(Symbol(), OP_BUY, lots_16, NormalizeDouble(Ask, Digits), 0, 0, 0, EA_Name + ls_40, Magic_Number, 0, Green);
               if (ticket_12 > 0) {
                  gia_1344[index_52] = ticket_12;
                  gia_1348[index_52] = 0;
                  gda_1352[index_52] = lots_16;
                  gda_1356[index_52] = NormalizeDouble(Ask, Digits);
                  gda_1360[index_52] = 0;
                  gda_1364[index_52] = 0;
                  GlobalVariableSet(Symbol() + "ticketS4" + index_52, gia_1344[index_52]);
                  GlobalVariableSet(Symbol() + "typeS4" + index_52, gia_1348[index_52]);
                  GlobalVariableSet(Symbol() + "lotsS4" + index_52, gda_1352[index_52]);
                  GlobalVariableSet(Symbol() + "priceS4" + index_52, gda_1356[index_52]);
                  GlobalVariableSet(Symbol() + "stoplossS4" + index_52, gda_1360[index_52]);
                  GlobalVariableSet(Symbol() + "takeprofitS4" + index_52, gda_1364[index_52]);
               }
               Sleep(1000);
            }
         } else {
            ticket_12 = OrderSend(Symbol(), OP_BUY, lots_16, NormalizeDouble(Ask, Digits), 0, 0, 0, EA_Name + ls_40, Magic_Number, 0, Green);
            Sleep(1000);
         }
         if (ticket_12 >= 0) {
            if (ld_24 == 0.0) {
               if (ad_4 > 0.0) ld_24 = ad_4;
               else ld_24 = Ask + Basket_Take_Profit * g_point_1332;
            }
            if (ld_32 == 0.0) ld_32 = Ask - Basket_Stop_Loss * g_point_1332;
            if (gi_1340 == TRUE) HideOrderModifyS4(ticket_12, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(ld_32, Digits), NormalizeDouble(ld_24, Digits), 0, 0);
            else {
               li_56 = Close_Order_Attempts;
               bool_60 = FALSE;
               while (bool_60 == FALSE && li_56 >= 0) {
                  li_56--;
                  RefreshRates();
                  bool_60 = OrderModify(ticket_12, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(ld_32, Digits), NormalizeDouble(ld_24, Digits), 0, Black);
                  if (!bool_60) {
                     g_error_1376 = GetLastError();
                     if (g_error_1376 == 146/* TRADE_CONTEXT_BUSY */) {
                        Sleep(50);
                        continue;
                     }
                  }
                  bool_60 = TRUE;
               }
            }
         }
      }
      g_datetime_1236 = TimeCurrent();
      if (ticket_12 != -1) {
         if (!ai_0) {
            g_ticket_1304 = ticket_12;
            Log("BUY hedgedTicket=" + g_ticket_1304);
         } else {
            Log("BUY Envy_ticket=" + ticket_12);
            g_cmd_1308 = 0;
         }
      } else {
         Log("failed sell");
         li_ret_48 = FALSE;
      }
   }
   GlobalVariableDel("PERMISSION");
   return (li_ret_48);
}

int OpenSellNBP(bool ai_0, double ad_4) {
   int ticket_12;
   double lots_16;
   int li_56;
   bool bool_60;
   if (TimeCurrent() - gi_1104 < GetLastCloseTime_Sell())
      if (GetOrderCount_Sell() != 0) return (0);
   double ld_24 = 0;
   double ld_32 = 0;
   string ls_40 = "";
   bool li_ret_48 = TRUE;
   if (TimeCurrent() - g_datetime_1236 < 60) return (0);
   if (ai_0 && (!gi_1300)) return (0);
   if (!GlobalVariableCheck("PERMISSION")) {
      GlobalVariableSet("PERMISSION", TimeCurrent());
      if (!gi_1128) {
         if (ai_0) {
            if (gi_1340 == TRUE) {
               if (OrderSelect(g_ticket_1304, SELECT_BY_TICKET)) ld_32 = HideCheckTakeProfitS4(g_ticket_1304) + MarketInfo(Symbol(), MODE_SPREAD) * Point;
            } else
               if (OrderSelect(g_ticket_1304, SELECT_BY_TICKET)) ld_32 = OrderTakeProfit() + MarketInfo(Symbol(), MODE_SPREAD) * Point;
         } else ld_24 = ad_4;
      }
      if (gi_1324 == FALSE) {
         if (ai_0) lots_16 = NormalizeDouble(GetLastLotSize(0) * gd_1224, 2);
         else lots_16 = CalcLots(gd_1172);
      } else lots_16 = l(LicenseKey, GetLastLotSize_Sell(0), Base_Lot_Size, gd_1136, gia_1416);
      if (Basket_Stop_Loss > 0) ld_32 = Bid + Basket_Stop_Loss * g_point_1332;
      if (!gi_1128) {
         if (ld_24 == 0.0) {
            if (ad_4 > 0.0) ld_24 = ad_4;
            else ld_24 = Bid - Basket_Take_Profit * g_point_1332;
         }
         if (ld_32 == 0.0) ld_32 = Bid + Basket_Stop_Loss * g_point_1332;
         if (gi_1340 == TRUE) {
            for (int index_52 = 0; index_52 < 25; index_52++)
               if (gia_1344[index_52] <= 0) break;
            if (index_52 < 25) {
               ticket_12 = OrderSend(Symbol(), OP_SELL, lots_16, NormalizeDouble(Bid, Digits), Slippage, NormalizeDouble(ld_32, Digits), NormalizeDouble(ld_24, Digits), EA_Name +
                  ls_40, Magic_Number, 0, Pink);
               if (ticket_12 > 0) {
                  gia_1344[index_52] = ticket_12;
                  gia_1348[index_52] = 1;
                  gda_1352[index_52] = lots_16;
                  gda_1356[index_52] = NormalizeDouble(Bid, Digits);
                  gda_1360[index_52] = NormalizeDouble(ld_32, Digits);
                  gda_1364[index_52] = NormalizeDouble(ld_24, Digits);
                  GlobalVariableSet(Symbol() + "ticketS4" + index_52, gia_1344[index_52]);
                  GlobalVariableSet(Symbol() + "typeS4" + index_52, gia_1348[index_52]);
                  GlobalVariableSet(Symbol() + "lotsS4" + index_52, gda_1352[index_52]);
                  GlobalVariableSet(Symbol() + "priceS4" + index_52, gda_1356[index_52]);
                  GlobalVariableSet(Symbol() + "stoplossS4" + index_52, gda_1360[index_52]);
                  GlobalVariableSet(Symbol() + "takeprofitS4" + index_52, gda_1364[index_52]);
               }
            }
         } else {
            ticket_12 = OrderSend(Symbol(), OP_SELL, lots_16, NormalizeDouble(Bid, Digits), Slippage, NormalizeDouble(ld_32, Digits), NormalizeDouble(ld_24, Digits), EA_Name +
               ls_40, Magic_Number, 0, Pink);
         }
      } else {
         if (gi_1340 == TRUE) {
            for (index_52 = 0; index_52 < 25; index_52++)
               if (gia_1344[index_52] <= 0) break;
            if (index_52 < 25) {
               ticket_12 = OrderSend(Symbol(), OP_SELL, lots_16, NormalizeDouble(Bid, Digits), Slippage, 0, 0, EA_Name + ls_40, Magic_Number, 0, Pink);
               if (ticket_12 > 0) {
                  gia_1344[index_52] = ticket_12;
                    

Recommend