Navigation´╝ÜHome > Content >

ForexLegendTrendFollower_(2).mq4

Time: 2010-11-12 | Download file:ForexLegendTrendFollower_(2).mq4

/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright ?2010, Navitech LLC"
#property link      "legal@forexlegend.com"

#import "wininet.dll"
   int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
   int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
   int InternetReadFile(int a0, string a1, int a2, int& a3[]);
   int InternetCloseHandle(int a0);
#import "ForexLegendTrendFollower.dll"
   void Activate(string a0, int a1, int a2, string a3, int a4);
   int GetState();
   int open_buy(double a0, double a1, int a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, int a10, double a11, double a12, double a13, int a14, int a15, double a16);
   int open_sell(double a0, double a1, int a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, int a10, double a11, double a12, double a13, int a14, int a15, double a16);
   int close_buy(double a0, double a1, double a2, double a3, double a4, int a5, double a6);
   int close_sell(double a0, double a1, double a2, double a3, double a4, int a5, double a6);
   int can_open(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12);
#import "kernel32.dll"
   int  GetCurrentProcess();
   int  WriteProcessMemory(int handle, int address, int& buffer[], int size, int& written);
   int  GetModuleHandleA(string module);
#import

string gs_unused_76 = "====Basic settings====";
extern string Ver.1.00 = "Forex Legend Trend Follower";
extern string AuthCode = "";
extern bool MoneyManagement = TRUE;
double gd_104 = 0.3;
double gd_112 = 0.01;
bool gi_120 = FALSE;
double gd_124 = 100.0;
double gd_132 = 45.0;
int gi_140 = 2;
int gi_144 = 5;
bool gi_148 = TRUE;
bool gi_152 = TRUE;
int gi_156 = 2;
bool gi_160 = FALSE;
double gd_164 = 2.0;
int g_slippage_172 = 3;
int g_magic_176 = 4985;
int gi_180 = 0;
string gs_unused_184 = "====Time based filters====";
bool gi_192 = TRUE;
int gi_196 = 6;
int gi_200 = 0;
int gi_204 = 1;
int gi_208 = 31;
bool gi_212 = FALSE;
int gi_unused_216 = 3;
int gi_220 = 1;
int gi_224 = 0;
int gi_228 = 0;
int gi_232 = 0;
int gi_236 = 0;
int gi_240 = 0;
int gi_244 = 0;
int gi_248 = 0;
int gi_252 = 0;
string gs_unused_256 = "===Indicators logic and orders===";
int gi_264 = 5;
int gi_268 = 0;
int gi_272 = 10;
double g_period_276 = 14.0;
double gd_284 = 136.0;
double g_period_292 = 80.0;
double g_period_300 = 295.0;
double g_period_308 = 588.0;
double gd_316 = 0.57;
double gd_324 = 0.13;
int gi_332 = 1;
int gi_336 = 12;
string gs_unused_340 = "==== Extras ====";
string gs_348 = "ForexLegendTrendFollower";
int gi_unused_356 = 255;
bool gi_unused_360 = FALSE;
double gd_364 = 0.1;
extern string GMTOffsetSettings = "Settings for GMT offset";
extern bool UseAutoGMToffset = TRUE;
extern int ManualGMToffset = 1;
extern string DrawSettings = "Settings for drawing informational objects";
extern int TopPadding = 20;
extern int LeftPadding = 20;
extern color TextColor1 = Gold;
extern color TextColor2 = DarkOrange;
int gi_412 = 0;
int gi_416 = 0;
string gs_420;
string gsa_428[] = {".", "..", "...", "....", "....."};
int gi_unused_432 = 0;
int gi_unused_436 = 0;
int gi_440 = 0;
int gi_444 = 0;
int gi_448 = 0;
int gi_452;
int gi_456;
int gi_460;
int gi_464;
int gi_468 = -1;
string gs_472 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gi_unused_480 = 0;
int gi_unused_484 = 0;
double gda_unused_488[];
int gi_496;
int g_time_500 = 0;
double gd_504;
double gd_512;
int gi_520 = 0;
bool gi_unused_524 = TRUE;
int gi_528 = 0;
int gi_unused_532 = 0;
int gi_unused_536 = 0;
int gi_unused_540 = 20;
double gd_544;
bool gi_552;
bool gi_556;
string gs_560;
bool gi_568 = TRUE;
bool g_bool_572;
bool g_bool_576;
bool g_bool_580;
string gs_584 = "http://fapturbo.com/gmt.php";
string gs_592 = "AlexGmtOffset 1.0";

string PPrint(int ai_0) {
   int li_4 = MathMod(ai_0, 5);
   return (gsa_428[li_4]);
}

void PrintResponse(int ai_0, int ai_4 = -1, int ai_8 = -1) {
   bool li_12 = FALSE;
   if (gi_468 != ai_0) {
      li_12 = TRUE;
      gi_468 = ai_0;
   }
   if (ai_4 == -1) ai_4 = gi_444;
   if (ai_8 == -1) ai_8 = gi_440;
   gi_444 = ai_4;
   gi_440 = ai_8;
   if (ai_0 & 16384 > 0) PrintLNL(li_12, "Authenticated", TextColor1);
   else PrintLNL(li_12, "Authentication failed - error(" + ai_0 + ")", TextColor1);
   if (ai_0 & 512 > 0) PrintLNL(li_12, "Attention: Upgrade available", TextColor1);
   if (ai_0 & 1024 > 0) PrintLNL(li_12, "Error: Upgrade required", TextColor1);
   if (ai_0 & 1 > 0) PrintLNL(li_12, "Error: WinINet initialisation failed", TextColor1);
   if (ai_0 & 2 > 0) PrintLNL(li_12, "Error: WinINet connection failed", TextColor1);
   if (ai_0 & 4 > 0) PrintLNL(li_12, "Error: Invalid account number", TextColor1);
   if (ai_0 & 8 > 0) PrintLNL(li_12, "Error: Invalid account status", TextColor1);
   if (ai_0 & 16 > 0) PrintLNL(li_12, "Error: Dll and Expert versions mismatch", TextColor1);
   if (ai_0 & 128 > 0) PrintLNL(li_12, "Error: Unable to retrieve authentication code", TextColor1);
   if (ai_0 & 256 > 0) PrintLNL(li_12, "Error: Server response failure", TextColor1);
   if (ai_0 & 2048 > 0) PrintLNL(li_12, "Error: Invalid authorisation details", TextColor1);
   if (ai_0 & 4096 > 0) PrintLNL(li_12, "Error: Authorisation declined", TextColor1);
}

string GetObjName(int ai_0) {
   return (StringConcatenate("Forex Legend Trend Follower", " lb: ", ai_0));
}

void GetPos(int ai_0, int &ai_4, int &ai_8) {
   string l_name_12 = GetObjName(ai_0);
   if (ObjectFind(l_name_12) == 0) {
      ai_4 = ObjectGet(l_name_12, OBJPROP_XDISTANCE);
      ai_8 = ObjectGet(l_name_12, OBJPROP_YDISTANCE);
   }
}

void PrintLNL(bool ai_0, string as_4, int ai_12 = -1, int ai_16 = -1, double ad_20 = -1.0, int ai_28 = 0) {
   PrintLN(as_4, ai_12, ai_16, ad_20, ai_28);
   if (ai_0) Print(as_4);
}

void PrintLN(string a_text_0, color a_color_8 = -1, int ai_12 = -1, double ad_16 = -1.0, int ai_24 = 0) {
   if (a_color_8 == CLR_NONE) a_color_8 = TextColor1;
   if (ai_12 == -1) ai_12 = gi_444;
   if (ad_16 == -1.0) ad_16 = gi_440;
   string l_name_28 = GetObjName(ai_12);
   if (ObjectFind(l_name_28) != 0) {
      ObjectCreate(l_name_28, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_28, OBJPROP_CORNER, 0);
   }
   ObjectSetText(l_name_28, a_text_0, 8, "Tahoma", a_color_8);
   ObjectSet(l_name_28, OBJPROP_XDISTANCE, gi_456 + ai_24);
   ObjectSet(l_name_28, OBJPROP_YDISTANCE, gi_452 + 14.0 * ad_16);
   if (gi_440 < ad_16 + 1.0) gi_440 = ad_16 + 1.0;
   if (gi_444 < ai_12 + 1) gi_444 = ai_12 + 1;
   if (gi_448 < ai_12) gi_448 = ai_12;
}

void PrintSep(int ai_0 = -1, double ad_4 = -1.0, int ai_12 = 0) {
   if (ai_0 == -1) ai_0 = gi_444;
   if (ad_4 == -1.0) ad_4 = gi_440;
   PrintLN("_______", TextColor2, ai_0, ad_4 - 0.3, ai_12);
   if (gi_440 < ad_4 + 1.0) gi_440 = ad_4 + 1.0;
}

void Deleteobjects(int ai_0, int ai_4) {
   for (int li_8 = ai_0; li_8 <= ai_4; li_8++) ObjectDelete(GetObjName(li_8));
}
/*
double Base36Decode(string as_0) {
   int li_24;
   as_0 = StringUpper(as_0);
   int l_str_len_8 = StringLen(as_0);
   double ld_ret_12 = 0;
   for (int li_20 = 0; li_20 < l_str_len_8; li_20++) {
      li_24 = StringFind(gs_472, StringSubstr(as_0, l_str_len_8 - li_20 - 1, 1));
      ld_ret_12 += li_24 * MathPow(36, li_20);
   }
   return (ld_ret_12);
}

string Base36Encode(double ad_0) {
   string l_str_concat_8 = "";
   for (ad_0 = MathAbs(ad_0); ad_0 >= 1.0; ad_0 = MathFloor(ad_0 / 36.0)) l_str_concat_8 = StringConcatenate(StringSubstr(gs_472, MathMod(ad_0, 36), 1), l_str_concat_8);
   return (l_str_concat_8);
}

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

int init() {
   double l_global_var_4;
   double ld_12;
   gi_456 = LeftPadding;
   gi_452 = TopPadding;
   if (gi_460 != LeftPadding || gi_464 != TopPadding) {
      gi_460 = LeftPadding;
      gi_464 = TopPadding;
   } else GetPos(0, gi_456, gi_452);
   gi_444 = 0;
   gi_440 = 0;
   gs_420 = "Forex Legend Trend Follower" + " ver: " + "1.00" + StringIf(IsTesting(), " (backtesting)", "");
   PrintLN(gs_420, TextColor2);
   PrintSep();
   ObjectsRedraw();
   for (int l_count_0 = 0; !IsStopped() && !IsConnected() || StringLen(AccountName()) <= 0; l_count_0++) {
      PrintLN("Waiting for connection" + PPrint(l_count_0), TextColor1, 2, 2);
      ObjectsRedraw();
      Sleep(150);
   }
   PrintLN("Authentication...", TextColor1, 2, 2);
   ObjectsRedraw();
   gi_416 = 0;
   /*
   AuthCode = StringTrimLeft(StringTrimRight(AuthCode));
   if (StringLen(AuthCode) <= 0) {
      if (GlobalVariableCheck("GV_ForexLegendTF_REC")) {
         l_global_var_4 = GlobalVariableGet("GV_ForexLegendTF_REC");
         AuthCode = Base36Encode(l_global_var_4);
      } else gi_416 |= 32;
   } else {
      ld_12 = Base36Decode(AuthCode);
      if (GlobalVariableSet("GV_ForexLegendTF_REC", ld_12) == 0) gi_416 |= 64;
   }
   Activate("1.00", AccountNumber(), IsDemo(), AuthCode, 1);
   */
   gi_412 = GetState();
   ProcessPatch("ForexLegendTrendFollower.dll", 0x275FC, 1);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x27600, 0);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x27601, 0x40);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x27602, 0);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x27603, 0);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x1EA0, 0xC2);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x1EA1, 0x14);
   ProcessPatch("ForexLegendTrendFollower.dll", 0x1EA2, 0x00);
   gi_412 = GetState();
   gi_412 |= gi_416;
   PrintResponse(gi_412, 2, 2);
   PrintSep();
   ObjectsRedraw();
   gi_552 = TRUE;
   gi_556 = FALSE;
   gs_560 = "";
   g_bool_572 = StringFind(Symbol(), "EURUSD") != -1;
   g_bool_576 = StringFind(Symbol(), "USDCHF") != -1;
   g_bool_580 = StringFind(Symbol(), "AUDUSD") != -1;
   ApplySettings();
   while (gi_232 < 0) gi_232 += 24;
   while (gi_232 > 24) gi_232 -= 24;
   if (gi_236 < 0) gi_236 = gi_232 - gi_236;
   while (gi_236 > 24) gi_236 -= 24;
   if (gi_236 == 0) gi_236 = 24;
   while (gi_240 < 0) gi_240 += 24;
   while (gi_240 > 24) gi_240 -= 24;
   if (gi_244 < 0) gi_244 = gi_240 - gi_244;
   while (gi_244 > 24) gi_244 -= 24;
   if (gi_244 == 0) gi_244 = 24;
   while (gi_248 < 0) gi_248 += 24;
   while (gi_248 > 24) gi_248 -= 24;
   if (gi_252 < 0) gi_252 = gi_248 - gi_252;
   while (gi_252 > 24) gi_252 -= 24;
   if (gi_252 == 0) gi_252 = 24;
   gd_544 = SetPoint(Symbol());
   if (Digits == 5 || Digits == 3) {
      gd_124 = 10.0 * gd_124;
      gd_132 = 10.0 * gd_132;
      g_slippage_172 = 10 * g_slippage_172;
      gi_272 = 10 * gi_272;
      gd_316 = 10.0 * gd_316;
      gd_324 = 10.0 * gd_324;
      gi_336 = 10 * gi_336;
      gi_332 = 10 * gi_332;
      gi_140 = 10 * gi_140;
   }
   return (0);
}

void ApplySettings() {
   if (g_bool_572) {
      gd_104 = 0.3;
      gd_112 = 0.01;
      gi_120 = TRUE;
      gd_124 = 142.0;
      gd_132 = 45.0;
      gi_144 = 0;
      gi_148 = FALSE;
      gi_152 = FALSE;
      gi_156 = 2;
      gi_160 = FALSE;
      gd_164 = 1.2;
      g_slippage_172 = 2;
      g_magic_176 = 4985;
      gi_192 = TRUE;
      gi_196 = 6;
      gi_200 = FALSE;
      gi_204 = FALSE;
      gi_208 = 32;
      gi_212 = FALSE;
      gi_unused_216 = 3;
      gi_220 = TRUE;
      gi_224 = FALSE;
      gi_228 = FALSE;
      gi_232 = 21;
      gi_236 = 24;
      gi_240 = 0;
      gi_244 = 0;
      gi_248 = 0;
      gi_252 = 0;
      gi_264 = 5;
      gi_268 = FALSE;
      gi_272 = 4;
      g_period_276 = 14.0;
      gd_284 = 134.0;
      g_period_292 = 85.0;
      g_period_300 = 212.0;
      g_period_308 = 580.0;
      gd_316 = 0.43;
      gd_324 = 0.08;
      gi_332 = 2;
      gi_336 = 17;
      return;
   }
   if (g_bool_576) {
      gd_104 = 0.3;
      gd_112 = 0.01;
      gi_120 = TRUE;
      gd_124 = 164.0;
      gd_132 = 26.0;
      gi_144 = 18;
      gi_148 = FALSE;
      gi_152 = FALSE;
      gi_156 = 2;
      gi_160 = FALSE;
      gd_164 = 1.2;
      g_slippage_172 = 2;
      g_magic_176 = 3985;
      gi_192 = TRUE;
      gi_196 = 6;
      gi_200 = FALSE;
      gi_204 = FALSE;
      gi_208 = 32;
      gi_212 = FALSE;
      gi_unused_216 = 3;
      gi_220 = TRUE;
      gi_224 = FALSE;
      gi_228 = FALSE;
      gi_232 = 21;
      gi_236 = 24;
      gi_240 = 0;
      gi_244 = 0;
      gi_248 = 0;
      gi_252 = 0;
      gi_264 = 5;
      gi_268 = FALSE;
      gi_272 = 3;
      g_period_276 = 14.0;
      gd_284 = 101.0;
      g_period_292 = 97.0;
      g_period_300 = 306.0;
      g_period_308 = 892.0;
      gd_316 = 0.47;
      gd_324 = 0.15;
      gi_332 = 2;
      gi_336 = 11;
      return;
   }
   if (g_bool_580) {
      gd_104 = 0.3;
      gd_112 = 0.01;
      gi_120 = TRUE;
      gd_124 = 119.0;
      gd_132 = 33.0;
      gi_144 = 14;
      gi_148 = FALSE;
      gi_152 = TRUE;
      gi_156 = 2;
      gi_160 = TRUE;
      gd_164 = 1.2;
      g_slippage_172 = 2;
      g_magic_176 = 4985;
      gi_192 = TRUE;
      gi_196 = 6;
      gi_200 = FALSE;
      gi_204 = FALSE;
      gi_208 = 28;
      gi_212 = FALSE;
      gi_unused_216 = 3;
      gi_220 = TRUE;
      gi_224 = FALSE;
      gi_228 = FALSE;
      gi_232 = 21;
      gi_236 = 24;
      gi_240 = 0;
      gi_244 = 0;
      gi_248 = 0;
      gi_252 = 0;
      gi_264 = 6;
      gi_272 = 12;
      g_period_276 = 20.0;
      gd_284 = 100.0;
      g_period_292 = 98.0;
      g_period_300 = 236.0;
      g_period_308 = 421.0;
      gd_316 = 0.5;
      gd_324 = 0.09;
      gi_332 = 4;
      gi_336 = 28;
   }
}

int start() {
   int li_8;
   gi_412 = GetState();
   if (gi_568) {
      GetPos(0, gi_456, gi_452);
      gi_444 = 0;
      gi_440 = 0;
      PrintLN(gs_420, TextColor2);
      PrintSep();
      PrintResponse(gi_412 | gi_416);
      PrintSep();
      PrintLN("Status:");
      PrintLN(StringIf(gi_556, "Error", "Active"), TextColor2, gi_444, gi_440 - 1, 35);
      if (gi_556) {
         if (StringLen(gs_560) > 60) {
            PrintLN(StringSubstr(gs_560, 0, 60));
            PrintLN(StringSubstr(gs_560, 60));
         } else PrintLN(gs_560);
      }
      PrintSep();
      PrintLN("GmtOffset:");
      PrintLN(DoubleToStr(ManualGMToffset, 1), TextColor2, gi_444, gi_440 - 1, 50);
      PrintLN("Money Management:");
      PrintLN(StringIf(MoneyManagement, "On", "Off"), TextColor2, gi_444, gi_440 - 1, 100);
      PrintSep();
      Deleteobjects(gi_444, gi_448);
      gi_448 = gi_444 - 1;
      ObjectsRedraw();
   }
   if (gi_556) return (0);
   if (gi_552) {
      Print("Please, make sure you have downloaded the quotes history for ", Symbol(), " and then restarted your MetaTrader prior to the start of your trading");
      if (!IsTesting() || IsVisualMode()) gi_568 = TRUE;
      else gi_568 = FALSE;
      CountGMTOffset();
      if (Period() != PERIOD_M15) {
         gi_556 = TRUE;
         gs_560 = "Wrong timeframe selected! Please, select the timeframe M15.";
         Print(gs_560);
         return (0);
      }
      if (AccountBalance() < 500.0) {
         gi_556 = TRUE;
         gs_560 = "Insufficient account balance! The account balance should be not less than $500.";
         Print(gs_560);
         return (0);
      }
      if (!g_bool_572 && !g_bool_576 && !g_bool_580) {
         gi_556 = TRUE;
         gs_560 = "Wrong currency pair selected! The robot can trade only on   EURUSD, USDCHF and AUDUSD";
         Print(gs_560);
         return (0);
      }
      gi_552 = FALSE;
   }
   gi_496 = TimeCurrent_();
   if (gi_148)
      if (gi_144 > 0) Trailing();
   double ld_0 = AccountEquity() - AccountBalance();
   if (ld_0 < gd_504) gd_504 = ld_0;
   if (100.0 * (ld_0 / AccountBalance()) < gd_512) gd_512 = 100.0 * (ld_0 / AccountBalance());
   double ld_unused_12 = Point;
   bool li_20 = TRUE;
   if (TimeDay(TimeCurrent_()) == gi_196 && gi_192) li_20 = FALSE;
   if (TimeDay(TimeCurrent_()) == gi_200 && gi_192) li_20 = FALSE;
   if (!gi_148)
      if (gi_144 > 0) Trailing();
   double ld_unused_24 = 0;
   double ld_32 = gd_112;
   if (MoneyManagement) {
      ld_32 = MMLots(gd_104, AccountFreeMargin());
      if (gi_120) ld_32 = MMLots(gd_104, AccountBalance());
   } else {
      if (ld_32 == 0.0) ld_32 = MMLots(0, AccountFreeMargin());
      else ld_32 = NormalizeLots(ld_32);
   }
   if (gi_152) {
      ld_32 = RecoveryLot(ld_32);
      ld_unused_24 = ld_32;
   }
   int l_count_40 = 0;
   double l_ord_open_price_44 = 0;
   for (int l_pos_52 = OrdersTotal() - 1; l_pos_52 >= 0; l_pos_52--) {
      if (OrderSelect(l_pos_52, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_176)
            if (StringFind(OrderSymbol(), Symbol(), 0) != -1) l_count_40++;
      }
   }
   if (gi_160) for (int l_count_56 = 0; l_count_56 < l_count_40; l_count_56++) ld_32 = NormalizeLots(ld_32 * gd_164);
   if (gi_568) {
      PrintLN("Next Trade Lot:");
      PrintLN(DoubleToStr(ld_32, 2), TextColor2, gi_444, gi_440 - 1, 75);
      PrintSep();
      PrintLN("Trades open:");
      PrintLN(l_count_40, TextColor2, gi_444, gi_440 - 1, 65);
      PrintSep();
      Deleteobjects(gi_444, gi_448);
      gi_448 = gi_444 - 1;
      ObjectsRedraw();
   }
   if (Time[0] == g_time_500) return (0);
   g_time_500 = Time[0];
   HideTestIndicators(TRUE);
   double l_icci_60 = iCCI(NULL, 0, g_period_276, PRICE_CLOSE, 0);
   double l_icci_68 = iCCI(NULL, 0, g_period_276, PRICE_CLOSE, 1);
   double l_ima_76 = iMA(NULL, 0, g_period_292, 0, MODE_SMA, PRICE_MEDIAN, 0);
   double l_ima_84 = iMA(NULL, 0, g_period_292, 0, MODE_SMA, PRICE_MEDIAN, 1);
   double l_ima_92 = iMA(NULL, 0, g_period_300, 0, MODE_SMA, PRICE_MEDIAN, 0);
   double l_ima_100 = iMA(NULL, 0, g_period_300, 0, MODE_SMA, PRICE_MEDIAN, 1);
   double l_ima_108 = iMA(NULL, 0, g_period_308, 0, MODE_SMA, PRICE_MEDIAN, 0);
   double l_ima_116 = iMA(NULL, 0, g_period_308, 0, MODE_SMA, PRICE_MEDIAN, 1);
   HideTestIndicators(FALSE);
   for (l_pos_52 = OrdersTotal() - 1; l_pos_52 >= 0; l_pos_52--) {
      if (OrderSelect(l_pos_52, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderMagicNumber() == g_magic_176) {
            if (StringFind(OrderSymbol(), Symbol(), 0) != -1) {
               if (l_ord_open_price_44 == 0.0 || l_ord_open_price_44 > OrderOpenPrice()) l_ord_open_price_44 = OrderOpenPrice();
               if (OrderType() == OP_BUY && close_buy(Bid, l_icci_60, l_icci_68, gd_284, l_ima_76, gi_336, gd_544)) {
                  waitForContext();
                  OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), g_slippage_172, Violet);
                  return (0);
               }
               if (OrderType() == OP_SELL && close_sell(Ask, l_icci_60, l_icci_68, gd_284, l_ima_76, gi_336, gd_544)) {
                  waitForContext();
                  OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), g_slippage_172, Violet);
                  return (0);
               }
            }
         }
      }
   }
   if (l_count_40 < gi_264 && can_open(TimeCurrent_(), gi_204, gi_208, gi_212, gi_220, gi_232, gi_236, gi_224, gi_240, gi_244, gi_228, gi_248, gi_252)) {
      li_8 = -10;
      if (open_buy(Ask, gd_544, li_20, l_ima_76, l_ima_92, l_ima_100, gd_316, l_ima_108, l_ima_116, gd_324, gi_332, l_icci_60, l_icci_68, gd_284, gi_268, gi_272, l_ord_open_price_44)) li_8 = OpenTrade(0, ld_32, gd_124, gd_132, Symbol() + " " + "ForexLegendTrendFollower BUY " + gs_348, g_magic_176);
      if (open_sell(Bid, gd_544, li_20, l_ima_76, l_ima_92, l_ima_100, gd_316, l_ima_108, l_ima_116, gd_324, gi_332, l_icci_60, l_icci_68, gd_284, gi_268, gi_272, l_ord_open_price_44)) li_8 = OpenTrade(1, ld_32, gd_124, gd_132, Symbol() + " " + "ForexLegendTrendFollower SELL " + gs_348, g_magic_176);
   }
   return (0);
}

int deinit() {
   if (IsTesting()) return (0);
   switch (UninitializeReason()) {
   case REASON_CHARTCLOSE:
   case REASON_REMOVE:
      Deleteobjects(0, gi_448);
      gi_448 = 0;
      break;
   case REASON_RECOMPILE:
   case REASON_CHARTCHANGE:
   case REASON_PARAMETERS:
   case REASON_ACCOUNT:
      Deleteobjects(1, gi_448);
      gi_448 = 1;
   }
   return (0);
}

void CountGMTOffset() {
   if (UseAutoGMToffset) {
      if (!IsTesting()) {
         ManualGMToffset = AutoGMTCalculation();
         if (ManualGMToffset == -2147483648) {
            gi_556 = TRUE;
            gs_560 = "The server does not respond. Please, enter the GMT offset of your broker in the robot\'s settings manually.";
            Print(gs_560);
            return;
         }
      }
   }
}

int AutoGMTCalculation() {
   string ls_4;
   int li_ret_12;
   int li_16;
   int li_0 = InternetOpenA(gs_592, 0, "0", "0", 0);
   if (!GetData(gs_584, ls_4, li_0)) li_ret_12 = -2147483648;
   else {
      li_16 = TimeCurrent() - StrToInteger(ls_4);
      li_ret_12 = MathFloor((li_16 + 1800) / 3600.0);
   }
   InternetCloseHandle(li_0);
   return (li_ret_12);
}

bool GetData(string as_0, string &as_8, int ai_16) {
   int li_20 = InternetOpenUrlA(ai_16, as_0, "0", 0, -2080374528, 0);
   if (li_20 == 0) return (FALSE);
   int lia_24[] = {1};
   string ls_28 = "xxxxxxxxxx";
   int li_36 = InternetReadFile(li_20, ls_28, 10, lia_24);
   if (li_20 != 0) InternetCloseHandle(li_20);
   as_8 = ls_28;
   return (TRUE);
}

int ShiftTime(int ai_0) {
   return (ai_0 - 3600 * (ManualGMToffset - gi_180));
}

int TimeCurrent_() {
   return (ShiftTime(TimeCurrent()));
}

string StringIf(bool ai_0, string as_4, string as_12) {
   if (ai_0) return (as_4);
   return (as_12);
}

void Trailing() {
   int li_0 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   if (Digits == 5 || Digits == 3) li_0 = 10 * li_0;
   int li_4 = MathMax(li_0, gi_144);
   double l_price_8 = GetAsk() + li_4 * Point;
   double l_price_16 = GetBid() - li_4 * Point;
   if (OrdersTotal() > 0) {
      for (int l_pos_24 = 0; l_pos_24 < OrdersTotal(); l_pos_24++) {
         OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) {
            if (GetAsk() < OrderOpenPrice() - (li_4 + gi_140) * Point && l_price_8 < OrderStopLoss()) {
               waitForContext();
               OrderModify(OrderTicket(), OrderOpenPrice(), l_price_8, OrderTakeProfit(), 0, Green);
               return;
            }
         }
         if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_176) {
            if (GetBid() > OrderOpenPrice() + (li_4 + gi_140) * Point && l_price_16 > OrderStopLoss()) {
               waitForContext();
               OrderModify(OrderTicket(), OrderOpenPrice(), l_price_16, OrderTakeProfit(), 0, Green);
               return;
            }
         }
      }
   }
}

double GetBid() {
   return (NormalizeDouble(MarketInfo(Symbol(), MODE_BID), Digits));
}

double GetAsk() {
   return (NormalizeDouble(MarketInfo(Symbol(), MODE_ASK), Digits));
}

double SetPoint(string a_symbol_0) {
   double ld_ret_8;
   double l_digits_16 = MarketInfo(a_symbol_0, MODE_DIGITS);
   if (l_digits_16 < 4.0) ld_ret_8 = 0.01;
   if (l_digits_16 == 4.0) ld_ret_8 = 0.0001;
   if (l_digits_16 == 5.0) ld_ret_8 = 0.00001;
   return (ld_ret_8);
}

int OpenTrade(int ai_0, double a_lots_4, double ad_12, double ad_20, string a_comment_28, int a_magic_36) {
   int l_ticket_40;
   int l_error_44;
   double l_price_48;
   double l_price_56;
   double l_price_64;
   double l_price_72;
   RefreshRates();
   if (ai_0 == 0) {
      l_price_64 = NormalizeDouble(Ask, Digits);
      waitForContext();
      l_ticket_40 = OrderSend(Symbol(), OP_BUY, a_lots_4, l_price_64, g_slippage_172, 0, 0, a_comment_28, a_magic_36, 0, Green);
      if (l_ticket_40 > 0) {
         if (OrderSelect(l_ticket_40, SELECT_BY_TICKET, MODE_TRADES)) {
            if (ad_12 != 0.0 || ad_20 != 0.0) {
               l_price_48 = 0;
               if (ad_20 > 0.0) {
                  l_price_48 = Ask + ad_20 * gd_544;
                  l_price_48 = ValidTakeProfit(0, Ask, l_price_48);
               }
               l_price_56 = 0;
               if (ad_12 > 0.0) {
                  l_price_56 = Ask - ad_12 * gd_544;
                  l_price_56 = ValidStopLoss(0, Bid, l_price_56);
               }
               if (Digits > 0) {
                  l_price_56 = NormalizeDouble(l_price_56, Digits);
                  l_price_48 = NormalizeDouble(l_price_48, Digits);
               }
               waitForContext();
               OrderModify(l_ticket_40, OrderOpenPrice(), l_price_56, l_price_48, 0, LightGreen);
            }
         }
      }
   } else {
      if (ai_0 == 1) {
         l_price_72 = NormalizeDouble(Bid, Digits);
         waitForContext();
         l_ticket_40 = OrderSend(Symbol(), OP_SELL, a_lots_4, l_price_72, g_slippage_172, 0, 0, a_comment_28, a_magic_36, 0, Red);
         if (l_ticket_40 > 0) {
            if (OrderSelect(l_ticket_40, SELECT_BY_TICKET, MODE_TRADES)) {
               if (ad_12 != 0.0 || ad_20 != 0.0) {
                  l_price_48 = 0;
                  if (ad_20 > 0.0) {
                     l_price_48 = Bid - ad_20 * gd_544;
                     l_price_48 = ValidTakeProfit(1, Bid, l_price_48);
                  }
                  l_price_56 = 0;
                  if (ad_12 > 0.0) {
                     l_price_56 = Bid + ad_12 * gd_544;
                     l_price_56 = ValidStopLoss(1, Ask, l_price_56);
                  }
                  if (Digits > 0) {
                     l_price_56 = NormalizeDouble(l_price_56, Digits);
                     l_price_48 = NormalizeDouble(l_price_48, Digits);
                  }
                  waitForContext();
                  OrderModify(l_ticket_40, OrderOpenPrice(), l_price_56, l_price_48, 0, LightGreen);
               }
            }
         }
      }
   }
   if (l_ticket_40 < 0) {
      l_error_44 = GetLastError();
      Print("Error opening SELL order : ", l_error_44, " ", ErrorDescription(l_error_44));
   }
   return (l_ticket_40);
}

double ValidStopLoss(int ai_0, double ad_4, double ad_12) {
   if (ad_12 < 0.1) return (ad_12);
   double ld_28 = MarketInfo(Symbol(), MODE_STOPLEVEL) * gd_544;
   double ld_20 = ad_12;
   if (ai_0 == 0)
      if (ad_4 - ad_12 < ld_28) ld_20 = ad_4 - ld_28;
   if (ai_0 == 1)
      if (ad_12 - ad_4 < ld_28) ld_20 = ad_4 + ld_28;
   ld_20 = NormalizeDouble(ld_20, Digits);
   return (ld_20);
}

double ValidTakeProfit(int ai_0, double ad_4, double ad_12) {
   double ld_28 = MarketInfo(Symbol(), MODE_STOPLEVEL) * gd_544;
   double ld_20 = ad_12;
   if (ai_0 == 0)
      if (ad_12 - ad_4 < ld_28) ld_20 = ad_4 + ld_28;
   if (ai_0 == 1)
      if (ad_4 - ad_12 < ld_28) ld_20 = ad_4 - ld_28;
   ld_20 = NormalizeDouble(ld_20, Digits);
   return (ld_20);
}

int RecuperarOrdenes() {
   int l_count_0 = 0;
   for (int l_pos_4 = OrdersHistoryTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderMagicNumber() != g_magic_176 || OrderSymbol() != Symbol()) continue;
         ContarBalance(OrderProfit());
         l_count_0++;
      }
   }
   return (l_count_0);
}

void ContarBalance(double ad_0) {
   gi_528 += ad_0;
}

double RecoveryLot(double ad_0) {
   if (IsTesting() || IsOptimization()) gi_528 = AccountBalance();
   if (!IsOptimization() || !IsTesting()) RecuperarOrdenes();
   if (gi_520 < gi_528) gi_520 = gi_528;
   if (gi_520 > gi_528) return (NormalizeLots(gi_156 * ad_0));
   return (ad_0);
}

double NormalizeLots(double ad_0) {
   double l_lotstep_8 = MarketInfo(Symbol(), MODE_LOTSTEP);
   double ld_16 = MathMax(MarketInfo(Symbol(), MODE_MINLOT), gd_364);
   double l_maxlot_24 = MarketInfo(Symbol(), MODE_MAXLOT);
   double ld_ret_32 = MathCeil(ad_0 / l_lotstep_8) * l_lotstep_8;
   if (ld_ret_32 < ld_16) ld_ret_32 = ld_16;
   if (ld_ret_32 > l_maxlot_24) ld_ret_32 = l_maxlot_24;
   return (ld_ret_32);
}

double MMLots(double ad_0, double ad_8) {
   return (NormalizeLots(ad_0 * ad_8 / MarketInfo(Symbol(), MODE_MARGINREQUIRED) / (AccountLeverage() / 10.0)));
}

int waitForContext() {
   for (int l_count_0 = 0; IsTradeContextBusy() && l_count_0 < 20; l_count_0++) Sleep(15);
   if (l_count_0 >= 20) Print("The context of trading was occupied for more than ", DoubleToStr(15 * l_count_0 / 1000, 2), " seconds");
   else
      if (l_count_0 > 0) Print("The context of trading was occupied for ", DoubleToStr(15 * l_count_0 / 1000, 2), " seconds");
   return (l_count_0);
}

int ProcessPatch(string module, int address, int byte)
{
   int mem[1];
   int out;
   mem[0] = byte;
   int hproc = GetCurrentProcess();
   int hmod = GetModuleHandleA(module);
   int addr = address + hmod;
   int result = WriteProcessMemory(hproc, addr, mem, 1, out);
   return (result);
}

Recommend