//+------------------------------------------------------------------+
//| Signaux donnés sur Gold Cup / Telegram                           |
//+------------------------------------------------------------------+
#define o_FHn     n
#define PAUSE      100
#import "shell32.dll"
 int ShellExecuteW(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import
#include <stdlib.mqh>
#ifdef o_FHn
#include <Telegram_Gold-Cup_VPS.mqh>
#ifdef o_FH2
#include <Telegram_Gold-Cup-2.mqh>
#endif
#ifdef o_FH4
#include <Telegram_Gold-Cup-4.mqh>
#endif
#ifdef o_FH5
#include <Telegram_Gold-Cup-5.mqh>
#endif
#ifdef o_FH6
#include <Telegram_Gold-Cup-6.mqh>
#endif
#ifdef o_FH7
#include <Telegram_Gold-Cup-7.mqh>
#endif
#ifndef o_FH46
/*extern */bool EA_20pips = true;
#endif
#else
extern bool EA_20pips = true;
#endif
int slip#ifdef o_FHn, tickt_[2], tickt_b[2], EA_n_TP=EA_nb_TP, t_web=-1#endif, t1_rep, t2_rep, tsh;       double lot=_lot, pips2dbl#ifdef o_FHn, LM_#endif;
string Symb_, Op_20pips, Op_Symbs, Lm_Symbs, Op_Symb2s, terminal=arr_Terms[Terminal], admin=arr_Admins[Terminal];       bool Del_Reps=false, port;

int OnInit() { EventSetTimer(5);
   if (FileIsExist(".\\Op_Symbs_List.txt")) { int handle = FileOpen(".\\Op_Symbs_List.txt", FILE_TXT|FILE_READ);
         if (handle != INVALID_HANDLE) { Op_Symbs = FileReadString(handle);      Sleep(PAUSE);     FileClose(handle);
            Alert("******* File Op_Symbs_List.txt contains: " + Op_Symbs + " *******"); }
         else Alert("*** (1) File Op_Symbs_List.txt not found, the last error is ", GetLastError() + " ***"); }
   if (FileIsExist(".\\Op_Symb2s_List.txt")) { handle = FileOpen(".\\Op_Symb2s_List.txt", FILE_TXT|FILE_READ);
         if (handle != INVALID_HANDLE) { Op_Symb2s = FileReadString(handle);     Sleep(PAUSE);     FileClose(handle);
            Alert("******* File Op_Symb2s_List.txt contains: " + Op_Symb2s + " *******"); }
         else Alert("*** (1) File Op_Symb2s_List.txt not found, the last error is ", GetLastError() + " ***"); }
   if (FileIsExist(".\\Lm_Symbs_List.txt")) { handle = FileOpen(".\\Lm_Symbs_List.txt", FILE_TXT|FILE_READ);
         if (handle != INVALID_HANDLE) { Lm_Symbs = FileReadString(handle);      Sleep(PAUSE);     FileClose(handle);
            Alert("******* File Lm_Symbs_List.txt contains: " + Lm_Symbs + " *******"); }
         else Alert("*** (1) File Lm_Symbs_List.txt not found, the last error is ", GetLastError() + " ***"); }
   return(INIT_SUCCEEDED); }

void OnTick() {
 if (FileIsExist(".\\Telegram\\Copy_Trade_On.txt", 0) || FileIsExist(".\\Telegram\\Copy_Trade_Off.txt", 0)) {
   if (FileIsExist(".\\Telegram\\Copy_Trade_On.txt", 0)) FileMove(".\\Telegram\\Copy_Trade_On.txt", 0, ".\\Telegram\\Copy_Trade_Off.txt", 0);
   int nf, _nrep=1, nrep_=1, n_rep=1, nLines=0, row=0, cpt=0;        string filename;       // B3511AE7AE29D20268E67E28E5D8DF10 (FH4)
   while(FileIsExist(".\\Telegram_copied ("+IntegerToString(nrep_)+")\\Copy_Trade_Off.txt",0) || FileIsExist(".\\Telegram_copied ("+IntegerToString(nrep_)+")\\Copy_Trade_Bat_On.txt",0)) nrep_ ++;
   int ts=ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
      "date_time.bat", ">>logs\\Copy_Trade_All.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
#ifdef o_FHn   Sleep(PAUSE/2);   while(cpt < 23 && ((ts=#else   ts =#endif ShellExecuteW(0,"open","C:\\Users\\Administra" + admin +
      "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+"Copy_Trade_All.bat", IntegerToString(nrep_)+" >>logs\\Copy_Trade_All.txt", "C:\\Users\\Administra"+admin+
      "\\AppData\\Roaming\\MetaQuotes\\Terminal\\"+terminal+"\\MQL4\\Files\\Telegram", 2)#ifdef o_FHn)!=42 || (!FileIsExist(".\\Telegram_copied ("+IntegerToString(nrep_)+")\\Copy_Trade_Off.txt",0) &&
      ! FileIsExist(".\\Telegram_copied (" + IntegerToString(nrep_) + ")\\Copy_Trade_Bat_On.txt",0)))) {
Print("******* (1) ts = " + IntegerToString(ts) + (ts == 2? " - " + "C:\\Users\\Administra"+admin+"\\AppData\\Roaming\\MetaQuotes\\Terminal\\"+terminal+"\\MQL4\\Files\\Telegram\\"+
         "Copy_Trade_All.bat": "") + " - " + cpt + " *******");         if (cpt) Sleep(PAUSE/2);         cpt ++; }      cpt = 0;#else;#endif
   Sleep(5 * PAUSE);         #ifdef o_FHn while(cpt < 23 && FileIsExist(".\\Telegram\\Copy_Trade_Bat_On.txt", 0)) { Sleep(PAUSE);
Print("******* (1) cpt = " + IntegerToString(cpt) + " *******");            cpt ++; }
   Sleep(PAUSE);              if (FileIsExist(".\\Telegram\\Copy_Trade_Bat_On.txt", 0)) {// FileDelete(".\\Telegram\\Copy_Trade_Off.txt", 0);
Print("******* (2) cpt = " + IntegerToString(cpt) + " *******");         return; }#endif         nf = 1;
   while((filename=File_Next(0, nf, 0)) != "last_file" && filename != "") if (StringSubstr(filename, StringLen(filename)-4, 4) != ".bat" &&
     #ifdef o_FHn filename != "Copy_Trade_Bat_Off.txt" &&#endif filename != "Copy_Trade_Off.txt") FileDelete("Telegram\\"+filename, 0);            else  nf ++;
   ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
      "date_time.bat", ">>logs\\Del_Trade_Dskt.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
#ifdef o_FH6   Sleep(PAUSE/2);#endif   ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
      "Del_Trade_Dskt.bat", ">>logs\\Del_Trade_Dskt.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
   Sleep(5 * PAUSE);          FileDelete(".\\Telegram\\Copy_Trade_Off.txt", 0);#ifdef o_FHn           cpt = 0;#endif

   while(!FileIsExist(".\\Telegram_copied ("+IntegerToString(nrep_)+")\\Copy_Trade_Off.txt",0) && !FileIsExist(".\\Telegram_copied ("+IntegerToString(nrep_)+")\\Copy_Trade_Bat_On.txt",0) && cpt < 17) {
      Sleep(PAUSE/2);         cpt ++; }      if (cpt == 17) Alert("******* ATTENTION : ERREUR sur le répertoire .\\Telegram_copied ("+IntegerToString(nrep_)+") *******");          cpt = 0;
   while(FileIsExist(".\\Telegram_copied ("+IntegerToString(n_rep)+")\\Copy_Trade_Off.txt",0) || FileIsExist(".\\Telegram_copied ("+IntegerToString(n_rep)+")\\Copy_Trade_Bat_On.txt",0)) n_rep ++;
   n_rep --;   while(_nrep <= n_rep) { nf = 1;   while((filename=File_Next(1, nf, _nrep)) != "last_file" && filename != "") {
      if (StringSubstr(filename, StringLen(filename)-4, 4) != ".bat" &&#ifdef o_FHn filename != "Copy_Trade_Bat_Off.txt" &&
      filename != "Copy_Trade_Bat_On.txt" &&#endif filename != "Copy_Trade_Off.txt") {
         int handle=FileOpen("Telegram_copied ("+IntegerToString(_nrep)+")\\"+filename, FILE_TXT|FILE_READ);
         string line;    if (handle != INVALID_HANDLE) { while(true) { line = "";    line = FileReadString(handle);
            if (FileIsLineEnding(handle)) nLines ++;           if (FileIsEnding(handle)) break; }        nLines ++;
            FileClose(handle);      Print("******* File "+filename+" contains "+nLines+" line"+(nLines > 1? "s": "")+" *******"); }
         else Alert("*** (1) File "+filename+" not found, the last error is ", GetLastError() + " ***"); }
         nLines ++;     nf ++; }   _nrep ++; }#ifdef o_FHn           Sleep(PAUSE);#endif
   if (line_read[0][0] != "") while(row < nLines + 1 && row < ArraySize(line_read) / 8 && line_read[row][0] != "- - -") {
      line_read[row][0] = "";       line_read[row][1] = "";       line_read[row][2] = "";       line_read[row][3] = "";
      line_read[row][4] = "";       line_read[row][5] = "";       line_read[row][6] = "";       line_read[row][7] = "";#ifdef o_FH46
      line_read[row][8] = "";       line_read[row][9] = "";       line_read[row][10] = "";#endif #ifdef o_FH4
      line_read[row][11] = "";      line_read[row][12] = "";      line_read[row][13] = "";      line_read[row][14] = "";#endif   row ++; }
   ArrayResize(line_read, nLines + 1, 1);       _nrep = 1;        row = 0;          int row_;
   while(_nrep <= n_rep) { row_ = row;          while(row_ == row && cpt < 3) {
         nf = 1;        while((filename=File_Next(1, nf, _nrep)) != "last_file" && filename != "") {
            if (StringSubstr(filename, StringLen(filename)-4, 4) != ".bat" &&#ifdef o_FHn filename != "Copy_Trade_Bat_Off.txt" &&
            filename != "Copy_Trade_Bat_On.txt" &&#endif filename != "Copy_Trade_Off.txt") {
               line_read[row][0] = "--- " + filename + " ---------------------------------";       row ++;
               row = CSV_FILE_READ(row, _nrep, filename);            Sleep(2 * PAUSE); }           nf ++; }
         if (row_ == row) Sleep(2 * PAUSE);        cpt ++; }#ifdef o_FHn            cpt = 0;#endif
/* #ifdef o_FH5      handle = FileOpen("Telegram\\logs\\Copy_Trade_All_b.txt", FILE_TXT|FILE_READ);
      if (handle == INVALID_HANDLE) {
         ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
            "date_time.bat", ">>logs\\Copy_Trade_All_b3.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
         ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\logs\\"+
            "Copy_Trade_All_b1.bat", ">>Copy_Trade_All_b3.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\logs", 2);
         filename = "Copy_Trade_All_b2.txt"; }           else { filename = "Copy_Trade_All_b.txt";          FileClose(handle); }          Sleep(2 * PAUSE);#endif */
      t1_rep = 1;       while(FileIsExist(".\\Telegram_copied ("+IntegerToString(_nrep)+") copie("+IntegerToString(t1_rep)+")\\Copy_Trade_Bat_On.txt",0)) t1_rep ++;
      t2_rep = _nrep;      ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
         "date_time.bat", ">>logs\\Copy_Trade_All_b.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
#ifdef o_FHn   Sleep(PAUSE/2);   while(cpt < 23 && (ts=#else   ts =#endif ShellExecuteW(0,"open","C:\\Users\\Administra"+admin+"\\AppData\\Roaming\\MetaQuotes\\Terminal\\"+terminal+"\\MQL4\\Files\\Telegram\\"+
         "Copy_Trade_All_b.bat", IntegerToString(t1_rep) + " \"..\\Telegram_copied ("+IntegerToString(_nrep)+")\" >>logs\\Copy_Trade_All_b.txt", "C:\\Users\\Administra" + admin +
         "\\AppData\\Roaming\\MetaQuotes\\Terminal" + "\\" + terminal + "\\MQL4\\Files\\Telegram", 2)#ifdef o_FHn) != 42) {
Print("******* (2) ts = " + IntegerToString(ts) + " *******");         if (cpt) Sleep(PAUSE);        cpt ++; }      cpt = 0;#else;#endif           Sleep(t_vps * PAUSE);
/* #ifdef o_FH5      if (filename == "Copy_Trade_All_b2.txt")
         ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\logs\\"+
            "Copy_Trade_All_b2.bat", ">>Copy_Trade_All_b3.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\logs", 2);#endif */
      FileMove(".\\Telegram\\Del_Trade_All.ba_", 0, ".\\Telegram\\Del_Trade_All.bat", 0);
#ifdef o_FHn      while(cpt < 23 && FileIsExist(".\\Telegram\\Copy_Trade_Bat_On.txt", 0)) { Sleep(PAUSE);         cpt ++; }/*      if (cpt) Sleep(PAUSE);*/#endif
      ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
         "date_time.bat", ">>logs\\Del_Trade_All.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
      ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
         "Del_Trade_All.bat", "\"..\\Telegram_copied ("+IntegerToString(_nrep)+")\" >>logs\\Del_Trade_All.txt", 
         "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
      Sleep(2 * PAUSE);    FileMove(".\\Telegram\\Del_Trade_All.bat", 0, ".\\Telegram\\Del_Trade_All.ba_", 0);    _nrep ++; }       line_read[row][0] = "- - -";

   int col=0;        row = 0;          string temp=TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS);
   while(row < ArraySize(line_read) / 8 && line_read[row][0] != "- - -") {
      temp += (row? "\r\n": " ") + line_read[row][col] + " " + line_read[row][col+1] + " " + line_read[row][col+2] + " " + line_read[row][col+3] + " " +
         line_read[row][col+4] + " " + line_read[row][col+5] + " " + line_read[row][col+6] + " " + line_read[row][col+7];        row ++; }
   temp += "\r\n--------------------------------------------------------------------------------";             copy_file(0, temp);

   int type, ticket;       bool t_close;        row = 0;     col = 0;      cpt = 0;#ifdef o_FH6    t_limit = false;#endif
   while(row < ArraySize(line_read) / 8 && line_read[row][0] != "- - -") {
Print("*****1* "+IntegerToString(row)+" - "+line_read[row][0]+" *******");
      type = 0;   ticket = 0;    slip = 2;      port = true;         //      if (line_read[row][0] == "Share") type = 0;
#ifdef o_FH2      int itm1=2, itm2=0;        bool moon=false, virg=false;
      while(itm1 < 15 && ! moon) { moon = (StringSubstr(line_read[row-itm1][0], 0, 4) == "ＭＯＯＮ");        itm1 ++; }        if (moon) { itm1 --;
         while(itm2 < 8 && ! virg) { virg = (StringSubstr(line_read[row-itm1][itm2], StringLen(line_read[row-itm1][itm2]) - 1) == ",");      itm2 ++; } }
      if ((StringSubstr(line_read[row-itm1][0], 0, 4) == "ＭＯＯＮ" && StringSubstr(line_read[row-itm1][itm2], 0, 1) == "[" && StringSubstr(line_read[row-itm1][itm2], 3, 1) == "/" &&
      (Day() != StrToInteger(StringSubstr(line_read[row-itm1][itm2], 1, 2)) || Hour() - StrToInteger(StringSubstr(line_read[row-itm1][itm2+1], 0, 2)) > (Minute()? 1: 2) ||
      Minute() - StrToInteger(StringSubstr(line_read[row-itm1][itm2+1], 3, 2)) > 0)) && moon) {
Print("*****1b* "+IntegerToString(row)+" - "+line_read[row-itm1][0]+" - "+line_read[row-itm1][1]+" - "+line_read[row-itm1][2]+" - "+line_read[row-itm1][3]+" - "+line_read[row-itm1][4]+" - "+
   StringSubstr(line_read[row-itm1][4], 0, 2) + " - " + StringSubstr(line_read[row-itm1][4], 3, 2) + " *******");
#endif
#ifdef o_FH4
      if (((StringSubstr(line_read[row-3][1],0,1) == "[" && StrToInteger(StringSubstr(line_read[row-3][2],0,2)) && StrToInteger(StringSubstr(line_read[row-3][2],3,2)) && (Day() !=
      StrToInteger(StringSubstr(line_read[row-3][1],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-3][2],0,2)) > 1 || Minute()-StrToInteger(StringSubstr(line_read[row-3][2],3,2)) > 17)) ||
      (StringSubstr(line_read[row-1][1],0,1) == "[" && StrToInteger(StringSubstr(line_read[row-1][2],0,2)) && StrToInteger(StringSubstr(line_read[row-1][2],3,2)) && (Day() !=
      StrToInteger(StringSubstr(line_read[row-1][1],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-1][2],0,2)) > 1 || Minute()-StrToInteger(StringSubstr(line_read[row-1][2],3,2)) > 17))) &&
      StringSubstr(line_read[row-3][0], StringLen(line_read[row-3][0]) - 1) == ",") {
Print("*****1b* "+IntegerToString(row)+" - "+line_read[row-3][0]+" - "+line_read[row-3][1]+" - "+line_read[row-3][2]+" - "+line_read[row-3][3]+" - "+line_read[row-3][4]+" - "+
   StringSubstr(line_read[row-3][4], 0, 2) + " - " + StringSubstr(line_read[row-3][4], 3, 2)+" | "+line_read[row-1][0]+" - "+line_read[row-1][1]+" - "+line_read[row-1][2]+" - "+
   line_read[row-1][3]+" - "+line_read[row-1][4]+" - "+StringSubstr(line_read[row-1][4], 0, 2)+" - " + StringSubstr(line_read[row-1][4], 3, 2)+" *******");
#endif
#ifdef o_FH5
      if ((line_read[row-3][0] == "Professor" && StringSubstr(line_read[row-3][1],0,3) == "VIP" && line_read[row-3][2] == "(yearly)," && (Day() !=
      StrToInteger(StringSubstr(line_read[row-3][3],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-3][4],0,2))>(Minute()?1:2) || Minute()-StrToInteger(StringSubstr(line_read[row-3][4],3,2)) > 17)) ||
      (line_read[row-1][0] == "Professor" && StringSubstr(line_read[row-1][1],0,3) == "VIP" && line_read[row-1][2] == "(yearly)," && (Day() !=
      StrToInteger(StringSubstr(line_read[row-1][3],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-1][4],0,2))>(Minute()?1:2) || Minute()-StrToInteger(StringSubstr(line_read[row-1][4],3,2)) > 17)) ||
      (line_read[row-15][0] == "Professor" && StringSubstr(line_read[row-15][1],0,3) == "VIP" && line_read[row-15][2] == "(yearly)," && (Day() !=
      StrToInteger(StringSubstr(line_read[row-15][3],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-15][4],0,2))>(Minute()?1:2) || Minute()-StrToInteger(StringSubstr(line_read[row-15][4],3,2)) > 17)) ||
      (line_read[row-14][0] == "Professor" && StringSubstr(line_read[row-14][1],0,3) == "VIP" && line_read[row-14][2] == "(yearly)," && (Day() !=
      StrToInteger(StringSubstr(line_read[row-14][3],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-14][4],0,2))>(Minute()?1:2) || Minute()-StrToInteger(StringSubstr(line_read[row-14][4],3,2)) > 17))) {
Print("*****1b* "+IntegerToString(row)+" - "+line_read[row-3][0]+" - "+line_read[row-3][1]+" - "+line_read[row-3][2]+" - "+line_read[row-3][3]+" - "+line_read[row-3][4]+" - "+
   StringSubstr(line_read[row-3][4], 0, 2) + " - " + StringSubstr(line_read[row-3][4], 3, 2)+" | "+line_read[row-1][0]+" - "+line_read[row-1][1]+" - "+line_read[row-1][2]+" - "+
   line_read[row-1][3]+" - "+line_read[row-1][4]+" - "+StringSubstr(line_read[row-1][4], 0, 2)+" - " + StringSubstr(line_read[row-1][4], 3, 2)+" | "+line_read[row-15][0]+
   " - "+line_read[row-15][1]+" - "+line_read[row-15][2]+" - "+line_read[row-15][3]+" - "+line_read[row-15][4]+" - "+StringSubstr(line_read[row-15][3], 1, 2)+" - "+StringSubstr(line_read[row-15][4],
   0, 2)+" - "+StringSubstr(line_read[row-15][4], 3, 2)+" | "+line_read[row-14][0]+" - "+line_read[row-14][1]+" - "+line_read[row-14][2]+" - "+line_read[row-14][3]+" - "+line_read[row-14][4]+" - "+
   StringSubstr(line_read[row-14][3], 1, 2)+" - "+StringSubstr(line_read[row-14][4], 0, 2)+" - "+StringSubstr(line_read[row-14][4], 3, 2)+" *******");
#endif
#ifdef o_FH6      int itm1=2, itm2=0;        bool moon=false, virg=false;
      while(itm1 < 15 && ! moon) { moon = (StringSubstr(line_read[row-itm1][0], 0, 4) == "ＭＯＯＮ");        itm1 ++; }        if (moon) { itm1 --;
         while(itm2 < 8 && ! virg) { virg = (StringSubstr(line_read[row-itm1][itm2], StringLen(line_read[row-itm1][itm2]) - 1) == ",");      itm2 ++; } }
      if ((StringSubstr(line_read[row-itm1][0], 0, 4) == "ＭＯＯＮ" && StringSubstr(line_read[row-itm1][itm2], 0, 1) == "[" && StringSubstr(line_read[row-itm1][itm2], 3, 1) == "/" &&
      (Day() != StrToInteger(StringSubstr(line_read[row-itm1][itm2], 1, 2)) || Hour() - StrToInteger(StringSubstr(line_read[row-itm1][itm2+1], 0, 2)) > (Minute()? 1: 2) ||
      Minute() - StrToInteger(StringSubstr(line_read[row-itm1][itm2+1], 3, 2)) > 0)) && moon) {
Print("*****1b* "+IntegerToString(row)+" - "+line_read[row-itm1][0]+" - "+line_read[row-itm1][1]+" - "+line_read[row-itm1][2]+" - "+line_read[row-itm1][3]+" - "+line_read[row-itm1][4]+" - "+
   StringSubstr(line_read[row-itm1][4], 0, 2) + " - " + StringSubstr(line_read[row-itm1][4], 3, 2) + " *******");
#endif
#ifdef o_FH7
      if (((StringSubstr(line_read[row-3][1],0,1) == "[" && StrToInteger(StringSubstr(line_read[row-3][2],0,2)) && StrToInteger(StringSubstr(line_read[row-3][2],3,2)) && (Day() !=
      StrToInteger(StringSubstr(line_read[row-3][1],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-3][2],0,2)) > 1 || Minute()-StrToInteger(StringSubstr(line_read[row-3][2],3,2)) > 17)) ||
      (StringSubstr(line_read[row-1][1],0,1) == "[" && StrToInteger(StringSubstr(line_read[row-1][2],0,2)) && StrToInteger(StringSubstr(line_read[row-1][2],3,2)) && (Day() !=
      StrToInteger(StringSubstr(line_read[row-1][1],1,2)) || Hour()-StrToInteger(StringSubstr(line_read[row-1][2],0,2)) > 1 || Minute()-StrToInteger(StringSubstr(line_read[row-1][2],3,2)) > 17))) &&
      StringSubstr(line_read[row-3][0], StringLen(line_read[row-3][0]) - 1) == ",") {
Print("*****1b* "+IntegerToString(row)+" - "+line_read[row-3][0]+" - "+line_read[row-3][1]+" - "+line_read[row-3][2]+" - "+line_read[row-3][3]+" - "+line_read[row-3][4]+" - "+
   StringSubstr(line_read[row-3][4], 0, 2) + " - " + StringSubstr(line_read[row-3][4], 3, 2)+" | "+line_read[row-1][0]+" - "+line_read[row-1][1]+" - "+line_read[row-1][2]+" - "+
   line_read[row-1][3]+" - "+line_read[row-1][4]+" - "+StringSubstr(line_read[row-1][4], 0, 2)+" - " + StringSubstr(line_read[row-1][4], 3, 2)+" *******");
#endif
         row ++;        continue; }
#ifdef o_FH2
      if (moon) port = false;
#endif
#ifdef o_FH5 
      if (line_read[row-3][0] == "Professor" || line_read[row-1][0] == "Professor" || line_read[row-15][0] == "Professor" || line_read[row-14][0] == "Professor") port = false;
#endif
#ifdef o_FH46
      if (StringSubstr(line_read[row-3][0], StringLen(line_read[row-3][0]) - 1) == ",") port = false;
#endif
#ifdef o_FHn 
      type = line_read_type(row);         string Symb;         double LM;
      while((! ticket || ticket == -1) && cpt < 9) { int icase=line_read_switch(type, row);
         ticket = tickt_[0];        Symb = Symb_;        LM = LM_;         if (ticket > 0 && tsh) tsh --;
         if (type == 2 && ticket) { tickt_b[0] = tickt_[0];       tickt_b[1] = tickt_[1]; }        // else tickt_b = 0;
#else
      if ((line_read[row][0] == "Sell" || line_read[row][0] == "Buy") && line_read[row][1] == "again") type = 1;
      else if ((line_read[row][0] == "Sell" || line_read[row][0] == "Buy") && line_read[row][1] == "limit") type = 2;
      else if ((line_read[row][0] == "TP" || line_read[row][0] == "TO") && line_read[row-1][0] == "SL" && (row+2 > ArraySize(line_read)/8-1 ||
         (StringSubstr(line_read[row+2][0], 3, 4) != "pips" && line_read[row+2][1] != "profit," && line_read[row+2][1] != "again"))) type = 3;
//      if (line_read[row][0] == "GOLD" && line_read[row][1] == "CUP") type = 4;
      else if ((line_read[row][0] == "join" || line_read[row][0] == "@iml_goldcup") && (line_read[row-2][0] == "TP" || line_read[row-2][0] == "TO")) type = 4;
      else if (StringSubstr(line_read[row][0], 3, 4) == "pips" && line_read[row][1] == "profit,") type = 5;
      else if (StringSubstr(line_read[row][0], 2, 4) == "pips" && line_read[row][1] == "profit,") type = 6;
      else if (line_read[row][0] == "CLOSE" || line_read[row][0] == "close") type = 7;
      else if (line_read[row][0] == "DAILY" && line_read[row][1] == "STATS") type = 8;
      else if (line_read[row][0] == "Sell" || line_read[row][0] == "sell" || line_read[row][0] == "Buy" || line_read[row][0] == "buy") type = 9;

      while((! ticket || ticket == -1) && cpt < 9) { switch(type) {
         case 1  :
Alert("*****2-1* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row-2][1]+" - "+line_read[row-3][1]+" - "+line_read[row-4][2]+" - "+line_read[row-4][1]+" - "+line_read[row-4][0]+" *******");
            double TP=StrToDouble(line_read[row-2][1]), SL=StrToDouble(line_read[row-3][1]), LM=StrToDouble(line_read[row-4][2]);
            string Symb=line_read[row-4][0];          int icase=0;
            ResetLastError();    if (StringFind(Symb, "/") > 0) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));
            if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
// . . .
         break;
         case 2  :
Alert("*****2-2* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row-2][1]+" - "+line_read[row-3][1]+" - "+line_read[row-4][2]+" - "+line_read[row-4][1]+" - "+line_read[row-4][0]+" *******");
            LM = StrToDouble(line_read[row][4]);         Symb = line_read[row][2];         ticket = 0;       icase = 0;
            SL = line_read[row+2][0] == "TP"? StrToDouble(line_read[row+3][1]): StrToDouble(line_read[row+2][1]);
            TP = line_read[row+2][0] == "TP"? fabs(LM - StrToDouble(line_read[row+2][1])) > fabs(LM - StrToDouble(line_read[row+1][1]))? 
               StrToDouble(line_read[row+2][1]): StrToDouble(line_read[row+1][1]): StrToDouble(line_read[row+1][1]);
            Bull = line_read[row][0] == "BUY" || line_read[row][0] == "Buy" || line_read[row][0] == "buy";
            ResetLastError();    if (StringFind(Symb, "/") > 0) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));
            if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
// . . .
         break;
         case 3  :
Alert("*****2-3* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row][1]+" - "+line_read[row-1][1]+" - "+line_read[row-2][2]+" - "+line_read[row-2][1]+" - "+line_read[row-2][0]+" *******");
            TP = StrToDouble(line_read[row][1]);      SL = StrToDouble(line_read[row-1][1]);    LM = StrToDouble(line_read[row-2][2]);
            Bull = line_read[row-2][1] == "BUY";      Symb = line_read[row-2][0];         ticket = 0;       icase = 0;
            ResetLastError();    if (StringFind(Symb, "/") > 0) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));
            if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
// . . .
         break;
         case 4  :
Alert("*****2-4* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row-2][1]+" - "+line_read[row-3][1]+" - "+line_read[row-4][2]+" - "+line_read[row-4][1]+" - "+line_read[row-4][0]+" *******");
            TP = StrToDouble(line_read[row-2][1]);    SL = StrToDouble(line_read[row-3][1]);    LM = StrToDouble(line_read[row-4][2]);
            Bull = line_read[row-4][1] == "BUY";      Symb = line_read[row-4][0];         ticket = 0;       icase = 0;
            ResetLastError();    if (StringFind(Symb, "/") > 0) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));
            if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
// . . .
         break;
         case 7  :
Alert("*****2-7* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row][1]+" *******");
            Symb = line_read[row][1];                 ResetLastError();
            if (StringFind(Symb, "/") > 0) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));
            if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
// . . .
         break;
         case 9  :
Alert("*****2-9* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row][1]+" *******");
            TP = StrToDouble(line_read[row+2][1]);       SL = StrToDouble(line_read[row+1][1]);
            Symb = line_read[row][1];        ResetLastError();       ticket = 0;       icase = 0;
            Bull = line_read[row][0] == "Buy" || line_read[row][0] == "buy";
            if (Symb == "GOLD" || Symb == "gold") Symb = "XAUUSD";
            if (StringFind(Symb, "/") > 0) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));
            if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
// . . .
         break;
         default :
Print("*****2-0* "+IntegerToString(row)+" - "+line_read[row][0]+" - "+line_read[row][1]+" *******"); }
#endif
if (icase) Print("******* "+IntegerToString(icase)+" - "+DoubleToStr(MarketInfo(Symb,MODE_BID), MarketInfo(Symb, MODE_DIGITS))+" - "+DoubleToStr(MarketInfo(Symb,MODE_ASK), MarketInfo(Symb, MODE_DIGITS))+" - "+
   DoubleToStr(iCustom(Symb, PERIOD_M30, "New folder\\ADX.ex4", 1, 14), 2)+" - "+DoubleToStr(iCustom(Symb, PERIOD_M30, "New folder\\ADX.ex4", 1, 7), 2)+" - "+IntegerToString(ticket)+" - "+GetLastError()+" *******");
#ifdef o_FHn
if (line_read[row-3][2] == "(yearly),") Print("*****1c* "+IntegerToString(row)+" - "+line_read[row-3][0]+" - "+line_read[row-3][1]+" - "+line_read[row-3][2]+" - "+line_read[row-3][3]+" - "+line_read[row-3][4]+" - "+
#else
if (StrToInteger(StringSubstr(line_read[row-3][1], 1, 2)) == Day() || icase)
   Print("*****1c* "+IntegerToString(row) + " - " + line_read[row-3][0] + " - " + line_read[row-3][1] + " - " + line_read[row-3][2] + " - " + line_read[row-3][3] + " - " + line_read[row-3][4] + " - " +
#endif
   StringSubstr(line_read[row-3][2], 0, 2) + " - " + StringSubstr(line_read[row-3][2], 3, 2) + " - " + StringSubstr(line_read[row-3][0], 0, 4) + " - " + StringSubstr(line_read[row-3][0], 4, 3) + " - " +
   StringLen(line_read[row-3][0])+ " *******");
      if ((! ticket || ticket == -1) && iCustom(Symb, PERIOD_M30, "New folder\\ADX.ex4", 1, 7) < 47) { if (slip == 2) slip = 5;     else cpt = 9; }      else cpt = 9; }
      cpt = 0;          row ++; } }

  else { _nrep = 1;  while(FileIsExist(".\\Telegram_copied ("+IntegerToString(_nrep)+")\\Copy_Trade_Off.txt",0) || FileIsExist(".\\Telegram_copied ("+IntegerToString(_nrep)+")\\Copy_Trade_Bat_On.txt",0)) {
      nrep_ = 1;        while(FileIsExist(".\\Telegram_copied ("+IntegerToString(_nrep)+") copie("+IntegerToString(nrep_)+")\\Copy_Trade_Bat_On.txt",0)) nrep_ ++;
      ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
         "date_time.bat", ">>logs\\Copy_Trade_All_b.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
#ifdef o_FHn   Sleep(PAUSE/2);   while(cpt < 23 && (ts=#else   ts =#endif ShellExecuteW(0,"open","C:\\Users\\Administra"+admin+"\\AppData\\Roaming\\MetaQuotes\\Terminal\\"+terminal+"\\MQL4\\Files\\Telegram\\"+
         "Copy_Trade_All_b.bat", IntegerToString(_nrep != t2_rep? nrep_: t1_rep) + " \"..\\Telegram_copied ("+IntegerToString(_nrep)+")\" >>logs\\Copy_Trade_All_b.txt", "C:\\Users\\Administra" + admin +
         "\\AppData\\Roaming\\MetaQuotes\\Terminal" + "\\" + terminal + "\\MQL4\\Files\\Telegram", 2)#ifdef o_FHn) != 42) {
Alert("******* (3) ts = " + IntegerToString(ts) + " *******");         if (cpt) Sleep(PAUSE);        cpt ++; }      cpt = 0;#else;#endif           Sleep(t_vps * PAUSE);
#ifdef o_FHn      while(cpt < 23 && FileIsExist(".\\Telegram\\Copy_Trade_Bat_On.txt", 0)) { Sleep(PAUSE);         cpt ++; }/*      if (cpt) Sleep(PAUSE);*/#endif
      while(FileIsExist(".\\Telegram_copied ("+IntegerToString(_nrep)+")\\Copy_Trade_Off.txt",0) || FileIsExist(".\\Telegram_copied ("+IntegerToString(_nrep)+")\\Copy_Trade_Bat_On.txt",0)) {
         ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
            "date_time.bat", ">>logs\\Del_Trade_All.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
         ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
            "Del_Trade_All.bat", "\"..\\Telegram_copied ("+IntegerToString(_nrep)+")\" >>logs\\Del_Trade_All.txt", 
            "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);       Sleep(PAUSE / 2); }     _nrep ++; } }

   int total=OrdersTotal(), itmp#ifdef o_FHn, n_tcks#endif;      bool tst;      double ordprof, dtmp;
   for (int pos=0; pos < total; pos ++) { slip = 2;
      if (! OrderSelect(pos, SELECT_BY_POS) || (OrderMagicNumber() != mgc_num && OrderTakeProfit() > 0.0)) continue;       ticket = OrderTicket();       //BrokerDigitAdjust(OrderSymbol());
if (FileIsExist(".\\Telegram\\Copy_Trade_On.txt", 0)) 
Print("*****1* OrderSelect: "+IntegerToString(pos)+" - "+IntegerToString(total)+" - "+OrderSelect(pos, SELECT_BY_POS)+" - "+IntegerToString(OrderTicket())+" *******");
#ifdef o_FHn      n_tcks = OrderSymbol() == "XAUUSD"+_p? 237: OrderSymbol() == "US30"? 2370: 187;           int ticket_;   // déplacer le paramétrage de n_tcks
      if (OrderStopLoss() == 0.0 && OrderTakeProfit() == 0.0) { tst = OrderDelete(ticket, clrNONE);         continue; }#endif
      if (StringFind(OrderComment(), "|") > 0 || StringFind(OrderComment(), "-") > 0) {
         if (StringFind(OrderComment(), "|") > 0) LM = StrToDouble(StringSubstr(OrderComment(), 0, StringFind(OrderComment(), "|") - 1));
         if (StringFind(OrderComment(), "-") > 0) LM = StrToDouble(StringSubstr(OrderComment(), StrToInteger(StringSubstr(OrderComment(), 0, 1))? 0: 1, 
            StringFind(OrderComment(), "-") - (StrToInteger(StringSubstr(OrderComment(), 0, 1))? 1: 2)));      //int(pips2dbl / MarketInfo(OrderSymbol(),MODE_POINT))
         if (StringFind(DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS)), ".") == -1 ||
         (StringFind(DoubleToStr(LM,MarketInfo(OrderSymbol(),MODE_DIGITS)),".") != StringFind(DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),".") &&
         StrToInteger(StringSubstr(DoubleToStr(LM,MarketInfo(OrderSymbol(),MODE_DIGITS)),StringFind(DoubleToStr(LM,MarketInfo(OrderSymbol(),MODE_DIGITS)),".")+1)) == 0))
            LM = LM * MarketInfo(OrderSymbol(), MODE_TICKVALUE);
         ordprof = LM > 0.0? OrderProfit() + ((OrderType()? 1: -1) * (LM - OrderOpenPrice()) / MarketInfo(OrderSymbol(), MODE_TICKSIZE) - 10) *
            MarketInfo(OrderSymbol(), MODE_TICKVALUE) * lot: OrderProfit(); }          else { ordprof = OrderProfit();        LM = 0.0; }    // ^ rapport à 197 ticks
#ifdef o_FHn
      if (! EA_20pips && (! GlobalVariableCheck(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP1") ||
      GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP1") == 0.0 ||
      ! GlobalVariableCheck(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP2") ||
      GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP2") == 0.0)) continue;
#else
      if (! EA_20pips && StringFind(Op_20pips, OrderSymbol()) == -1) continue;
#endif
#ifdef o_FHn                                                                           // * le cas du mOrdersTotal(OrderSymbol(), OrderStopLoss()) == 3 n'est pas traité correctement *
/*      if (EA_TP_secure && (OrderSymbol() == "XAUUSD" || OrderSymbol() == "DJ30") && AccountBalance() < 200.0 * lot / 0.01 && (mOrdersTotal(OrderSymbol(), OrderStopLoss()) % 2) > 0) EA_n_TP = 1;
      else EA_n_TP = EA_nb_TP; */        switch(EA_n_TP) {
         case 0  :
#endif
      if (round(ordprof*100.0)/100.0 > (dtmp=(n_tcks * lot * MarketInfo(OrderSymbol(), MODE_TICKVALUE))) && OrderType() < 2 && !((itmp=mOrdersTotal(OrderSymbol(), OrderStopLoss())) % 2)) {
         t_close = false;        cpt = 0;          tst = OrderSelect(ticket, SELECT_BY_TICKET);
         while (! t_close && (cpt < 4 || slip == 2)) { t_close = OrderClose(ticket, lot, OrderType()? MarketInfo(OrderSymbol(),MODE_ASK): MarketInfo(OrderSymbol(),MODE_BID), slip, clrNONE);
            if (cpt) { Sleep(5 * PAUSE);        RefreshRates(); }          cpt ++;
            if (slip == 2 && cpt == 4) { slip = 5;       cpt = 0; } }
         if (! t_close) Alert("***** Ticket NOT CLOSED! (2) " + ticket + " - " + GetLastError() + " *****");
         else { Sleep(2 * PAUSE);         pos --;
            if (OrderSelect(mOrderSelect(1, OrderSymbol(), !OrderType()), SELECT_BY_POS)) { ticket = OrderTicket();
               tst = OrderModify(ticket, OrderOpenPrice(), (OrderType() && LM < OrderOpenPrice() && LM > 0.0) || 
                  (! OrderType() && LM > OrderOpenPrice()) ? LM : OrderOpenPrice(), OrderTakeProfit(), 0, clrNONE);
Print("*****2* (0) OrderSelect: "+IntegerToString(tst)+" - "+IntegerToString(ticket)+" - "+OrderCloseTime()+" - "+IntegerToString(OrderTicket())+" - "+DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS))+" *******");
             }// }
else Print("*****3* (0) OrderSelect: " + IntegerToString(ticket) + " - " + OrderCloseTime() + " - " + mOrderSelect(1, OrderSymbol(), !OrderType()) + " - " + IntegerToString(OrderTicket()) + " - " +
   DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS)) + " *******"); }
if (FileIsExist(".\\Telegram\\Copy_Trade_On.txt", 0)) 
Print("******* (0) +20pips: "+OrderTicket()+" - "+OrderSymbol()+" - "+OrderProfit()+" - "+DoubleToStr(MarketInfo(OrderSymbol(), MODE_TICKVALUE), MarketInfo(OrderSymbol(), MODE_DIGITS))+" - "+
   DoubleToStr(200 * MarketInfo(OrderSymbol(), MODE_TICKVALUE), MarketInfo(OrderSymbol(), MODE_DIGITS))+" - "+DoubleToStr(200.0 * MarketInfo(OrderSymbol(), MODE_TICKVALUE), MarketInfo(
   OrderSymbol(), MODE_DIGITS))+" - "+DoubleToStr(MarketInfo(OrderSymbol(), MODE_TICKSIZE), MarketInfo(OrderSymbol(), MODE_DIGITS))+" - "+DoubleToStr(200 * MarketInfo(OrderSymbol(), 
   MODE_TICKSIZE), MarketInfo(OrderSymbol(), MODE_DIGITS))+" - "+DoubleToStr(200.0 * MarketInfo(OrderSymbol(), MODE_TICKSIZE), MarketInfo(OrderSymbol(), MODE_DIGITS))+" - "+
   mOrdersTotal(OrderSymbol(), OrderStopLoss())+" | "+IntegerToString(pos)+" - "+IntegerToString(total)+" - "+OrderSelect(pos, SELECT_BY_POS)+" *******"); }
#ifdef o_FHn
         break;
         case 1  :      double TP1=GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(ticket), StringLen(IntegerToString(ticket)) - 4) + "_TP1");
     #ifdef o_FH46 if (EA_20pips)#endif if (fabs(OrderStopLoss() - OrderOpenPrice()) > n_tcks * 2.0 / 3.0 * MarketInfo(OrderSymbol(), MODE_TICKSIZE) &&
      ((((OrderType()%2>0 && OrderStopLoss() > OrderOpenPrice()) || (!(OrderType()%2) && OrderStopLoss() < OrderOpenPrice())) &&
      round(ordprof*100.0)/100.0 > (dtmp=(n_tcks * lot * MarketInfo(OrderSymbol(), MODE_TICKVALUE)))) ||          // pour l'instant que dans l'option EA_nb_TP = 1
      (OrderType()%2>0 && MarketInfo(OrderSymbol(), MODE_BID) < TP1) || (!(OrderType()%2) && MarketInfo(OrderSymbol(), MODE_ASK) > TP1 && TP1 > 0.0))) {
//         if (OrderSelect(mOrderSelect(1, OrderSymbol(), !OrderType()), SELECT_BY_POS)) { ticket = OrderTicket();
         if (OrderType() < 2) tst = OrderModify(ticket, OrderOpenPrice(), (OrderType() && LM < OrderOpenPrice() && LM > 0.0) || 
            (! OrderType() && LM > OrderOpenPrice()) ? LM : OrderOpenPrice(), OrderTakeProfit(), 0, clrNONE);              else tst = OrderDelete(ticket, clrNONE);
Print("*****2* (1) OrderSelect: "+IntegerToString(tst)+" - "+IntegerToString(ticket)+" - "+OrderCloseTime()+" - "+IntegerToString(OrderTicket())+" - "+DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS))+" *******");
             }// }
else if (fabs(OrderStopLoss() - OrderOpenPrice()) > n_tcks * 2.0 / 3.0 * MarketInfo(OrderSymbol(), MODE_TICKSIZE) &&
   ((OrderType() && OrderStopLoss() > OrderOpenPrice()) || (! OrderType() && OrderStopLoss() < OrderOpenPrice())) &&
   ((OrderType() && OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK) > n_tcks * 4.0 / 5.0 * MarketInfo(OrderSymbol(), MODE_TICKSIZE)) ||
   (! OrderType() && MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice() > n_tcks * 4.0 / 5.0 * MarketInfo(OrderSymbol(), MODE_TICKSIZE))))
Print("*****3* (1) OrderSelect: " + IntegerToString(ticket) + " - " + OrderCloseTime() + " - " + mOrderSelect(1, OrderSymbol(), !OrderType()) + " - " + IntegerToString(OrderTicket()) + " - " +
   DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - " + DoubleToStr(TP1, MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - " + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(), MODE_DIGITS)) +
   " - " + DoubleToStr(OrderStopLoss(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - " + IntegerToString(n_tcks) + " - " +
   DoubleToStr(MarketInfo(OrderSymbol(), MODE_BID), MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - " + DoubleToStr(MarketInfo(OrderSymbol(), MODE_ASK), MarketInfo(OrderSymbol(), MODE_DIGITS)) +" *******");
         break;
         case 2  :      double TP2=GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP2"),
            TP3=GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP3");
      if (round(ordprof*100.0)/100.0 > (dtmp=(n_tcks * lot * MarketInfo(OrderSymbol(), MODE_TICKVALUE))) && OrderType() < 2 && !((itmp=mOrdersTotal(OrderSymbol(), OrderStopLoss())) % 2)) {
         t_close = false;        cpt = 0;          tst = OrderSelect(ticket, SELECT_BY_TICKET);
         while (! t_close && (cpt < 4 || slip == 2)) { t_close = OrderClose(ticket, lot, OrderType()? MarketInfo(OrderSymbol(),MODE_ASK): MarketInfo(OrderSymbol(),MODE_BID), slip, clrNONE);
            if (cpt) { Sleep(5 * PAUSE);        RefreshRates(); }          cpt ++;
            if (slip == 2 && cpt == 4) { slip = 5;       cpt = 0; } }
         if (! t_close) Alert("***** Ticket NOT CLOSED! (2) " + ticket + " - " + GetLastError() + " *****");
         else { Sleep(2 * PAUSE);         pos --;        ticket = 0;
            if (OrderSelect(mOrderSelect(1, OrderSymbol(), !OrderType()), SELECT_BY_POS)) { ticket = OrderTicket();
               tst = OrderModify(ticket, OrderOpenPrice(), (OrderType() && LM < OrderOpenPrice() && LM > 0.0) || 
                  (! OrderType() && LM > OrderOpenPrice()) ? LM : OrderOpenPrice(), TP3, 0, clrNONE);
Print("*****2* (2) OrderSelect: "+IntegerToString(tst)+" - "+IntegerToString(ticket)+" - "+OrderCloseTime()+" - "+IntegerToString(OrderTicket())+" - "+DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS))+" *******");
             }// }
else Print("*****3* (2) OrderSelect: " + IntegerToString(ticket) + " - " + OrderCloseTime() + " - " + mOrderSelect(1, OrderSymbol(), !OrderType()) + " - " + IntegerToString(OrderTicket()) + " - " +
   DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS))+" *******"); } }
      TP1 = ticket? GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(ticket), StringLen(IntegerToString(ticket)) - 4) + "_TP1"): 0.0;
      if (((OrderType() && MarketInfo(OrderSymbol(), MODE_BID) < TP2) || (! OrderType() && MarketInfo(OrderSymbol(), MODE_ASK) > TP2)) && ticket &&
      (OrderTakeProfit() != TP3 || OrderStopLoss() != TP1)) tst = OrderModify(ticket, OrderOpenPrice(), TP1, TP3, 0, clrNONE);
         break;
         case 3  :      TP2 = GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP2");
            TP3 = GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP3");
      if (round(ordprof*100.0)/100.0 > (dtmp=(n_tcks * lot * MarketInfo(OrderSymbol(), MODE_TICKVALUE))) && OrderType() < 2 && !((itmp=mOrdersTotal(OrderSymbol(), OrderStopLoss())) % 2) &&
      OrderTakeProfit() != TP3) { bool done=GlobalVariableCheck(OrderSymbol() + "_" + DoubleToStr(OrderStopLoss()/MarketInfo(OrderSymbol(), MODE_DIGITS), 0)) &&
         (ticket_=GlobalVariableGet(OrderSymbol() + "_" + DoubleToStr(OrderStopLoss()/MarketInfo(OrderSymbol(), MODE_DIGITS), 0))) > 0 &&
         GlobalVariableCheck(OrderSymbol() + StringSubstr(IntegerToString(ticket_), StringLen(IntegerToString(ticket_)) - 4) + "_TPx");
         if (! done) {
            GlobalVariableSet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TPx", 1.0);
            GlobalVariableSet(OrderSymbol() + "_" + DoubleToStr(OrderStopLoss()/MarketInfo(OrderSymbol(), MODE_DIGITS), 0), OrderTicket()); }
//         if (OrderSelect(mOrderSelect(1, OrderSymbol(), !OrderType()), SELECT_BY_POS)) { ticket = OrderTicket();
            tst = OrderModify(ticket, OrderOpenPrice(), (OrderType() && LM < OrderOpenPrice() && LM > 0.0) || 
               (! OrderType() && LM > OrderOpenPrice()) ? LM : OrderOpenPrice(), done? TP2: TP3, 0, clrNONE);
Print("*****2* (3) OrderSelect: "+IntegerToString(tst)+" - "+IntegerToString(ticket)+" - "+OrderCloseTime()+" - "+IntegerToString(OrderTicket())+" - "+DoubleToStr(TP2, MarketInfo(OrderSymbol(), MODE_DIGITS))+
   " - " + DoubleToStr(TP3, MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - " + DoubleToStr(OrderTakeProfit(), MarketInfo(OrderSymbol(), MODE_DIGITS)) + " *******");
/*             }// }
else Print("*****3* (3) OrderSelect: " + IntegerToString(ticket) + " - " + OrderCloseTime() + " - " + mOrderSelect(1, OrderSymbol(), !OrderType()) + " - " + IntegerToString(OrderTicket()) + " - " +
   DoubleToStr(LM, MarketInfo(OrderSymbol(), MODE_DIGITS))+" *******");*/ }
      TP1 = ticket? GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(ticket), StringLen(IntegerToString(ticket)) - 4) + "_TP1"): 0.0;
      if (((OrderType() && MarketInfo(OrderSymbol(), MODE_BID) < TP2) || (! OrderType() && MarketInfo(OrderSymbol(), MODE_ASK) > TP2)) && ticket &&
      OrderStopLoss() != TP1) tst = OrderModify(ticket, OrderOpenPrice(), TP1, OrderTakeProfit(), 0, clrNONE);
         break;
         case 4  :
         break; }
#endif }

   while(Hour() == 22 && StringFind(Op_Symbs, ":" + IntegerToString(Day()-1)) > 0) Op_Symbs = StringSubstr(Op_Symbs, StringFind(Op_Symbs, ":" + IntegerToString(Day()-1)) + 8);
   while(Hour() == 22 && StringFind(Op_Symbs, ":|") > 0) Op_Symbs = StringSubstr(Op_Symbs, StringFind(Op_Symbs, ":|") + 2);
   while(Hour() == 22 && StringFind(Lm_Symbs, ":" + IntegerToString(Day()-1)) > 0) Lm_Symbs = StringSubstr(Lm_Symbs, StringFind(Lm_Symbs, ":" + IntegerToString(Day()-1)) + 8);
   while(Hour() == 22 && StringFind(Lm_Symbs, ":|") > 0) Lm_Symbs = StringSubstr(Lm_Symbs, StringFind(Lm_Symbs, ":|") + 2);
   if (Hour() == 22 && ! Minute() && Seconds() < 15 && ! Del_Reps) { Del_Reps = true;         Op_Symb2s = "";         FileDelete("Op_Symb2s_List.txt", 0);
      ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
         "date_time.bat", ">>logs\\Del_Reps_Trades.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2);
      ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram\\"+
         "Del_Reps_Trades.bat", ">>logs\\Del_Reps_Trades.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\Files\\Telegram", 2); }
   else if (Minute()) Del_Reps = false;
#ifdef o_real

   if (StringFind(AccountCompany(), "Global") < 0)          // if (StringSubstr(AccountCompany(), 0, 5) == "Eight")
      if (DayOfWeek() == 5 && Hour() == 22 && Minute() > 42 && OrdersTotal()) { ArrayResize(line_read2, OrdersTotal(), 1);    Close_All_TradesW(); }
      else  if (DayOfWeek() == 1 && Hour() == 6 && Minute() && ! OrdersTotal() && FileIsExist("Liste dObjets EA - dump.csv")) { Open_All_TradesW();
         FileDelete("Liste dObjets EA - dump_.csv", 0);        FileMove("Liste dObjets EA - dump.csv", 0, "Liste dObjets EA - dump_.csv", 0); }
#endif
 }

void OnDeinit(const int reason) {
   if (Op_Symbs != "") { FileDelete("Op_Symbs_List.txt", 0);      Sleep(PAUSE);     copy_file(1, Op_Symbs); }
   if (Op_Symb2s != "") { FileDelete("Op_Symb2s_List.txt", 0);    Sleep(PAUSE);     copy_file(2, Op_Symb2s); }
   if (Lm_Symbs != "") { FileDelete("Lm_Symbs_List.txt", 0);      Sleep(PAUSE);     copy_file(3, Lm_Symbs); }
   EventKillTimer(); }

int tim_min;
void OnTimer() { t_web ++;
   if (! t_web || t_web >= 180) { ResetLastError();            // bool copy_FTP2() {
      int res=1, rs2, timeout=5000, ts, cpt=0;        char post[], result[];
#ifdef o_FH2
      string URL="http://www.ecomclub.com/transfert_VPS/FH2/",
#endif
#ifdef o_FH4
      string URL="http://www.ecomclub.com/transfert_VPS/FH4/",
#endif
#ifdef o_FH5
      string URL="http://www.ecomclub.com/transfert_VPS/FH5/",
#endif
#ifdef o_FH6
      string URL="http://www.ecomclub.com/transfert_VPS/FH6/",
#endif
#ifdef o_FH7
      string URL="http://www.ecomclub.com/transfert_VPS/FH7/",
#endif
         filename, headers, temp;      //, terminal=arr_Terms[Terminal], admin=arr_Admins[Terminal];
      if (FileIsExist(".\\Telegram\\Del_Trade_All.bat", 0)) FileMove(".\\Telegram\\Del_Trade_All.bat", 0, ".\\Telegram\\Del_Trade_All.ba_", 0);

      string str="";      int rs2_;       rs2 = 0;       res = WebRequest("GET", URL + "transfert.txt", NULL, NULL, timeout, post, 0, result, headers);        Sleep(2 * PAUSE);
      if (!rs2) { if (res<0||res==404) res = WebRequest("GET", URL + "OrderSend_Magic_Num_Ind.mq4", NULL, NULL, timeout, post, 0, result, headers);   else rs2 = 1;  Sleep(2 * PAUSE); }
      if (!rs2) { if (res<0||res==404) res = WebRequest("GET", URL + "OrderSend_Magic_Num.mq4", NULL, NULL, timeout, post, 0, result, headers);    else rs2 = 2;     Sleep(2 * PAUSE); }
      if (!rs2) { if (res<0||res==404) res = WebRequest("GET", URL + "Telegram_Gold-Cup.mq4", NULL, NULL, timeout, post, 0, result, headers);      else rs2 = 3;     Sleep(2 * PAUSE); }
//      if (!rs2) { if (res<0||res==404) res = WebRequest("GET", URL + "Telegram_Gold-Cup.mqh", NULL, NULL, timeout, post, 0, result, headers);      else rs2 = 4;     Sleep(2 * PAUSE); }   // v 5
      if (!rs2) { if (res<0||(res!=200&&res!=404)) Print("*** Error in WebRequest (1-"+IntegerToString(rs2)+"). Error code = ", GetLastError(), ", res = "+res, " ***");   if (res==200) rs2 = 4; }
      while(rs2) { PrintFormat("** The file has been successfully loaded ("+IntegerToString(rs2)+"), File size = %d bytes **", ArraySize(result));
         while(ts != 42 && cpt < 7) { if (StrToInteger(CharToString(result[0]))) filename = StringSubstr(CharArrayToString(result), 4);
            else  if (rs2 == 2) filename = "OrderSend_Magic_Num_Ind.mq4";  else  if (rs2 == 3) filename = "OrderSend_Magic_Num.mq4";
            else  if (rs2 == 4) filename = "Telegram_Gold-Cup.mq4";        else  if (rs2 == 5) filename = "Telegram_Gold-Cup.mqh";     else  filename = "WebResult.html";
            if (rs2 == 1) { Sleep(2 * PAUSE);      res = WebRequest("GET", URL + filename, NULL, NULL, timeout, post, 0, result, headers); }
            if (res < 0) Print("*** Error in WebRequest (" + filename + "). Error code = ", GetLastError(), " ***");
            else { PrintFormat("** The file has been successfully loaded ("+filename+"), File size = %d bytes **", ArraySize(result));
               if (StringSubstr(filename, StringLen(filename) - 4) == ".bat") filename = StringSubstr(filename, 0, StringLen(filename) - 4) + ".txt";
               int filehandle = FileOpen(filename, FILE_WRITE|FILE_BIN|FILE_COMMON);
               if (filehandle != INVALID_HANDLE) {
                  FileWriteArray (filehandle, result, 0, ArraySize(result));
                  FileClose(filehandle);        Sleep(5 * PAUSE);          if (rs2 == 1) { ts = 42;   if (StringSubstr(filename, StringLen(filename) - 4) == ".mqh") rs2 = 5; }
                  if (StringSubstr(filename, StringLen(filename) - 4) == ".txt") filename = StringSubstr(filename, 0, StringLen(filename) - 4) + ".bat";
                  if (rs2 == 2) ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\" +
                     "copy_file_i.bat", "OrderSend_Magic_Num_Ind.mq4 >>Logs\\copy_file_i.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4", 2);
                  if (rs2 == 3) ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\" +
                     "copy_file_s.bat", "OrderSend_Magic_Num.mq4 >>Logs\\copy_file_s.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4", 2);
                  if (rs2 == 4) ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\" +
                     "copy_file_e.bat", "Telegram_Gold-Cup.mq4 >>Logs\\copy_file_e.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4", 2);
                  if (rs2 == 5) ts = ShellExecuteW(0,"open","C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4\\" +
//                     "copy_file_h.bat", "Telegram_Gold-Cup.mqh >>Logs\\copy_file_h.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4", 2);
                     "copy_file_h.bat", filename + " >>Logs\\copy_file_h.txt", "C:\\Users\\Administra" + admin + "\\AppData\\Roaming\\MetaQuotes\\Terminal\\" + terminal + "\\MQL4", 2);

#ifndef o_FH46     // remettre o_FH46 lorsque FSX_VIP (/ FH4) sera transféré sur FH6 en remplaçant FRN_VIP
                  res = WebRequest("GET", URL + "file_delete.php?it=" + filename, NULL, NULL, timeout, post, 0, result, headers);
                  if (res < 0) Print("*** Error in WebRequest (2-"+(ts==42? IntegerToString(rs2): filename)+"). Error code = ", GetLastError(), " ***");
                  else PrintFormat("** The file has been successfully deleted ("+(ts==42? IntegerToString(rs2): filename)+"), File size = %d bytes **", ArraySize(result));
                  if (rs2 == 1 || rs2 == 5) { res = WebRequest("GET", URL + "file_delete.php?it=transfert.txt", NULL, NULL, timeout, post, 0, result, headers);
                     if (res < 0) Print("*** Error in WebRequest (2-"+(ts==42? IntegerToString(rs2): "transfert.txt")+"). Error code = ", GetLastError(), " ***");
                     else PrintFormat("** The file has been successfully deleted ("+(ts==42? IntegerToString(rs2): "transfert.txt")+"), File size = %d bytes **", ArraySize(result)); } }
#else
/*#ifdef o_FH7      // == ^
                  res = WebRequest("GET", URL + "file_delete.php?it=" + filename, NULL, NULL, timeout, post, 0, result, headers);
                  if (res < 0) Print("*** Error in WebRequest (2-"+(ts==42? IntegerToString(rs2): filename)+"). Error code = ", GetLastError(), " ***");
                  else PrintFormat("** The file has been successfully deleted ("+(ts==42? IntegerToString(rs2): filename)+"), File size = %d bytes **", ArraySize(result));
                  if (rs2 == 1 || rs2 == 5) { res = WebRequest("GET", URL + "file_delete.php?it=transfert.txt", NULL, NULL, timeout, post, 0, result, headers);
                     if (res < 0) Print("*** Error in WebRequest (2-"+(ts==42? IntegerToString(rs2): "transfert.txt")+"). Error code = ", GetLastError(), " ***");
                     else PrintFormat("** The file has been successfully deleted ("+(ts==42? IntegerToString(rs2): "transfert.txt")+"), File size = %d bytes **", ArraySize(result)); } }
#else */
                  bool t_res=false;          int it=2;      while(it < 4) {         // #ifdef o_FH4 3#else 2#endif
                     if (rs2 == 2 && FileIsExist("copy_indicator"+IntegerToString(it)+".txt", FILE_COMMON)) { FileMove("copy_indicator"+IntegerToString(it)+".txt", FILE_COMMON, "copy_indicator0.txt", FILE_COMMON);
                        if (! t_res) res = WebRequest("GET", URL + "file_delete.php?it=" + filename, NULL, NULL, timeout, post, 0, result, headers);           t_res = true; }
                     if (rs2 == 3 && FileIsExist("copy_script"+IntegerToString(it)+".txt", FILE_COMMON)) { FileMove("copy_script"+IntegerToString(it)+".txt", FILE_COMMON, "copy_script0.txt", FILE_COMMON);
                        if (! t_res) res = WebRequest("GET", URL + "file_delete.php?it=" + filename, NULL, NULL, timeout, post, 0, result, headers);           t_res = true; }
                     if (rs2 == 4 && FileIsExist("copy_expert"+IntegerToString(it)+".txt", FILE_COMMON)) { FileMove("copy_expert"+IntegerToString(it)+".txt", FILE_COMMON, "copy_expert0.txt", FILE_COMMON);
                        if (! t_res) res = WebRequest("GET", URL + "file_delete.php?it=" + filename, NULL, NULL, timeout, post, 0, result, headers);           t_res = true; }
                     if (rs2 == 5 && FileIsExist("copy_include"+IntegerToString(it)+".txt", FILE_COMMON)) { FileMove("copy_include"+IntegerToString(it)+".txt", FILE_COMMON, "copy_include0.txt", FILE_COMMON);
                        if (! t_res) res = WebRequest("GET", URL + "file_delete.php?it=" + filename, NULL, NULL, timeout, post, 0, result, headers);           t_res = true; }      it ++; }
                  if (t_res) { if (res < 0) Print("*** Error in WebRequest (2-"+(ts==42? IntegerToString(rs2): filename)+"). Error code = ", GetLastError(), " ***");
                     else  PrintFormat("** The file has been successfully deleted ("+(ts==42? IntegerToString(rs2): filename)+"-"+IntegerToString(res)+"), File size = %d bytes **", ArraySize(result));
                     if (rs2 == 1 || rs2 == 5) { res = WebRequest("GET", URL + "file_delete.php?it=transfert.txt", NULL, NULL, timeout, post, 0, result, headers);
                        if (res < 0) Print("*** Error in WebRequest (2-"+(ts==42? IntegerToString(rs2): "transfert.txt")+"). Error code = ", GetLastError(), " ***");
                        else PrintFormat("** The file has been successfully deleted ("+(ts==42? IntegerToString(rs2): "transfert.txt")+"-"+IntegerToString(res)+"), File size = %d bytes **",ArraySize(result)); } }
                  else  Print("*** WAIT in WebRequest (2-"+(ts==42? IntegerToString(rs2): "transfert.txt")+"). Error code = ", GetLastError(), " ***"); }
#endif// #endif
               else Print("*** Error in FileOpen (" + filename + "). Error code=", GetLastError(), " ***"); }           cpt ++; }
         rs2_ = rs2;       str += "-" + IntegerToString(rs2);         ts = 0;          cpt = 0;          rs2 = 0;       res = -1;         Sleep(5 * PAUSE);
//         if ((rs2==1 || rs2==5)#ifdef o_FH6 && t_res#endif) { res = . . .
         if ((rs2==1 || rs2==5) && t_res) { res = WebRequest("GET", URL + "transfert.txt", NULL, NULL, timeout, post, 0, result, headers);         Sleep(2 * PAUSE); }
//         if (! rs2#ifdef o_FH6 && (StringFind(str, "2") == -1 || (t_res && rs2_ == 2))#endif) {
         if (! rs2 && (StringFind(str, "2") == -1 || (t_res && rs2_ == 2))) {
            if (res < 0 || res == 404) res = WebRequest("GET", URL + "OrderSend_Magic_Num_Ind.mq4", NULL, NULL, timeout, post, 0, result, headers);      else rs2 = 1;  Sleep(2 * PAUSE); }
//         if (! rs2#ifdef o_FH6 && (StringFind(str, "3") == -1 || (t_res && rs2_ == 3))#endif) {
         if (! rs2 && (StringFind(str, "3") == -1 || (t_res && rs2_ == 3))) {
            if (res < 0 || res == 404) res = WebRequest("GET", URL + "OrderSend_Magic_Num.mq4", NULL, NULL, timeout, post, 0, result, headers);       else rs2 = 2;     Sleep(2 * PAUSE); }
//         if (! rs2#ifdef o_FH6 && (StringFind(str, "4") == -1 || (t_res && rs2_ == 4))#endif) {
         if (! rs2 && (StringFind(str, "4") == -1 || (t_res && rs2_ == 4))) {
            if (res < 0 || res == 404) res = WebRequest("GET", URL + "Telegram_Gold-Cup.mq4", NULL, NULL, timeout, post, 0, result, headers);         else rs2 = 3;     Sleep(2 * PAUSE); }
//         if (!rs2) { if (res<0||res==404) res = WebRequest("GET", URL + "Telegram_Gold-Cup.mqh", NULL, NULL, timeout, post, 0, result, headers);      else rs2 = 4;     Sleep(2 * PAUSE); }   // v 5
//         if (! rs2#ifdef o_FH6 && (StringFind(str, "5") == -1 || (t_res && rs2_ == 5))#endif) {
         if (! rs2 && (StringFind(str, "5") == -1 || (t_res && rs2_ == 5))) {
            if (res < 0 || (res != 200 && res != 404)) Print("*** Error in WebRequest (3-"+IntegerToString(rs2)+"). Error code = ", GetLastError(), ", res = "+res, " ***");
         if (res == 200) rs2 = 4; } }           t_web = 0;

         filehandle = FileOpen("jour_semaine.txt", FILE_WRITE|FILE_COMMON);      // |FILE_BIN
//         URL = "http://www.ecomclub.com/rep_logs_ATS/jour_semaine.txt";          res = WebRequest("GET", URL, NULL, NULL, timeout, post, 0, result, headers);
         if (filehandle != INVALID_HANDLE) {/* FileWriteArray (filehandle, result, 0, ArraySize(result)); */
            int var_d = StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_DATE), 8, 2)), var_m = StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_DATE), 5, 2)),
               var_y = StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_DATE), 0, 4));
//            double var_i = (var_m - 14) / 12, var_k = ((var_m - 14) / 12 + 4800 + var_y) * 1461 / 4, var_l = (var_m - var_i * 12 - 2) * 367 / 12, var_h = (var_i + 4900 + var_y) / 100 * 3 / 4,
//               var_t = var_k + var_l - var_h + var_d - 32075;        var_t = (var_t / 7 - floor(var_t / 7)) * 7;
            double var_t = (1461.0 * (var_y + 4800.0 + (var_m - 14.0) / 12.0)) / 4.0 + (367.0 * (var_m - 2.0 - 12.0 * ((var_m - 14.0) / 12.0))) / 12.0 -
               (3.0 * ((var_y + 4900.0 + (var_m - 14.0) / 12.0) / 100.0)) / 4.0 + var_d - 32075.0;
            var_t = (var_t / 7.0 - floor(var_t / 7.0)) * 7.0;        int var_w = float(var_t);	      // if (var_t < 0) var_t = 6;
            if (var_w == 6 && StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_MINUTES), 0, 2)) == 23 &&
            StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_MINUTES), 3, 2)) > 40) var_w = 0;
            FileWrite(filehandle,/* DayOfWeek()-1*/ var_w);          FileClose(filehandle); }//#ifdef o_FH246

      if ((StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_DATE), 8, 2)) == Day() && DayOfWeek() && DayOfWeek() < 6) ||
      FileIsExist("macro_week_1.log", FILE_COMMON)) { bool tst;      cpt = 0;
if ((tst=FileIsExist("macro_week_1.log", FILE_COMMON)))
Alert("******* FileIsExist(\"macro_week_1.log\", FILE_COMMON) : " + tst + " - DayOfWeek() : " + DayOfWeek() + " - TimeLocal() " + TimeToStr(TimeLocal(), TIME_MINUTES) + " *******");
         if ((tst=FileIsExist("macro_week_1.log", FILE_COMMON)) && DayOfWeek() == 1) FileMove("macro_week_1.log", FILE_COMMON, "macro_week_0.log", FILE_COMMON);
         string mac_chk2="macro_time_chk2"+EnumToString(Terminal)+".log";        while(! FileIsExist(mac_chk2, FILE_COMMON) && cpt < 7) { if (cpt) Sleep(PAUSE);
            if (FileIsExist("macro_time_chk.log", FILE_COMMON)) FileCopy("macro_time_chk.log", FILE_COMMON, mac_chk2, FILE_COMMON);          cpt ++; }
         Sleep(PAUSE);        int handle=FileOpen(mac_chk2, FILE_COMMON|FILE_TXT|FILE_READ);
         if (handle != INVALID_HANDLE) { temp = FileReadString(handle);          FileClose(handle);
            temp = StringSubstr(temp, 6, 4) + "/" + StringSubstr(temp, 3, 2) + "/" + StringSubstr(temp, 0, 2) + StringSubstr(temp, 10, 9);
            bool ml=(TimeLocal() - StrToTime(temp) < 300);              temp = ml || tst? "&ml=1": "&ml=2";    // v terrminal 'b' comme FH6b / Telegram_Gold-Cup_VPS.mqh
            URL = "http://www.ecomclub.com/web_send_mail.php?vps=" + vps + EnumToString(Terminal) + (b? "&b=1": "") + "&src=" + EnumToString(mgc_num) +
               (StrToInteger(StringSubstr(TimeToStr(TimeCurrent(), TIME_MINUTES), 0, 2)) > 22 || ! ml || tst? temp: "");
if (! ml) Alert("******* ATTENTION : ERREUR de Suivi macros ! (" + IntegerToString(TimeLocal() - StrToTime(temp)) + ") - DayOfWeek() = " + DayOfWeek() + " *******");
            res = WebRequest("GET", URL, NULL, NULL, timeout, post, 0, result, headers);              FileDelete(mac_chk2, FILE_COMMON);
if (! DayOfWeek() || (DayOfWeek() == 1 && Hour() < 2))
Alert("******* res = WebRequest(\"GET\", URL, : " + res + " - DayOfWeek() : " + DayOfWeek() + " - TimeLocal()" + TimeToStr(TimeLocal(), TIME_MINUTES) + " *******"); }
else Alert("******* handle==INVALID_HANDLE : FileOpen(\"macro_time_chk.log\", - DayOfWeek() : " + DayOfWeek() + " - TimeLocal() " + TimeToStr(TimeLocal(), TIME_MINUTES) + " *******"); }
/*#endif*/      TrailingStop(2, 30, NULL); }          if (! t_web || ! (t_web % 60)) { TrailingStop(1, 30, NULL);       tim_min = Minute();#ifdef o_real
      double vScale=(WindowPriceMax()-WindowPriceMin())/(!WindowPriceMax()?1.154:WindowPriceMax())/1.154/(1.154-1.061);          ObjectsPositions(vScale);
      if (! DrawArrow_chk(WindowPriceMax()-50 * vScale*Point,0, 1)) {/*Print("*** DrawArrow_chk Error (1): ", GetLastError(), " ***");*/}#endif

      tst = false;      string Symbs="";     for (int pos=0; pos < ObjectsTotal(); pos ++) {    // && ! tst
         string name=ObjectName(pos);              datetime time1=ObjectGet(ObjectName(pos), OBJPROP_TIME1);
         tst = (StringSubstr(name, 0, 9) == "FXSSI.CAL" && ((TimeCurrent() < time1 && time1 - TimeCurrent() < 600) ||
            (TimeCurrent() > time1 && TimeCurrent() - time1 < 900)));
         if (tst) Symbs += ObjectGet(ObjectName(pos), OBJPROP_TEXT) + "|";         tst = false; } }
//   return(res >= 0);
   TrailingStop(0, tst? 50: 30, Symbs); }

string File_Next(bool mode,int nf,int n_rep) {
   string tel_dir=mode? "Telegram"+(n_rep? "_copied ("+IntegerToString(n_rep)+")": "")+"\\*": "Telegram\\*", filename;  // dans .\MQL4\Files
   int i=1, pos=0, last_pos=-1;     bool tst=false;

//--- get the search handle in the root of the local folder
   long search_handle=FileFindFirst(tel_dir, filename, 0);
   if (search_handle==INVALID_HANDLE) { Print("*** INVALID_HANDLE - "+tel_dir+" - "+filename+" ***");   return(""); }

//--- check if the FileFindFirst() is executed successfully
   if (search_handle!=INVALID_HANDLE) {
      //--- in a loop, check if the passed strings are the names of files or directories
      do { ResetLastError();
         //--- if it's a file, the function returns true, and if it's a directory, it returns error ERR_FILE_IS_DIRECTORY
         FileIsExist(StringSubstr(tel_dir, 0, StringLen(tel_dir)-1) + filename);
         if (GetLastError() == ERR_FILE_IS_DIRECTORY) i --;
//         PrintFormat("%d : %s name = %s", i, GetLastError()==ERR_FILE_IS_DIRECTORY? "Directory": "File", filename);
//         if (StringSubstr(filename, 0, StringLen(symbol)) == symbol) break;
         if (i == nf) { tst = true;     break; }    i ++; }    // i peut être utilisé comme numéro de fichier dans la liste

      while(FileFindNext(search_handle,filename));

//      if (!FileFindNext(search_handle, next)) filename = "last_file";
      if (! tst) filename = "last_file";

      //--- close the search handle
      FileFindClose(search_handle); }
   else { Print("Files not found!");   filename = "File not found(0)"; }

//   MessageBox(filename, NULL, MB_OK);
   return(filename); }

#ifdef o_FH6
string line_read[][11];    int lrc=11;
#else
#ifdef o_FH4
string line_read[][19];    int lrc=19;
#else
#ifdef o_FH5
string line_read[][11];    int lrc=11;
#else
string line_read[][8];     int lrc=8;
#endif #endif #endif
int CSV_FILE_READ(int _row,int n_rep,string filename) {
   filename = ".\\Telegram_copied ("+IntegerToString(n_rep)+")\\" + filename;
   int row=_row, col=0, handle=FileOpen(filename,FILE_CSV|FILE_READ, " ");
   if(handle > 0) {
      while(True && col < lrc) { string temp=FileReadString(handle);
#ifdef o_FHn
         temp = StringTrimLeft(StringTrimRight(temp));
         line_read[row][col] = temp != "" ? temp : ".";
#else
         line_read[row][col] = temp;
#endif
         if (FileIsEnding(handle)) break;
         if (FileIsLineEnding(handle)) { col = 0;        row ++; }
         else#ifdef o_FHn if (col < lrc-1)#endif col ++; }      row ++;
      FileClose(handle); }
   else Alert("*** (2) File "+filename+" not found, the last error is ", GetLastError() + " ***");
   return(row); }

void copy_file(int Item,string temp) { int handle;
   string filename=Item? Item==1? "Op_Symbs_List.txt": Item==2? "Op_Symb2s_List.txt": "Lm_Symbs_List.txt": "macro_logs_copy.log";
   if (!FileIsExist(filename)) handle = FileOpen (filename,FILE_TXT|FILE_WRITE);
   else   handle = FileOpen (filename,FILE_TXT|FILE_READ|FILE_WRITE);
   if (handle != INVALID_HANDLE) {
      if (FileSize(handle) > 0) FileSeek(handle, FileSize(handle), 0);
      FileWrite(handle, temp); }
   else Print ("*** Problème : handle == INVALID_HANDLE. (2) / "+Symbol()+" / "+GetLastError()+" ***");
   FileClose(handle); }

int mOrdersTotal(string Symb,double SL) { int total=OrdersTotal(), mtotal=0;
  if (Symb == "" || Symb == NULL) return(mtotal);        datetime otime;

  for (int pos=0; pos < total; pos ++) {
      if (! OrderSelect(pos, SELECT_BY_POS)) continue;
      if (!mtotal && OrderSymbol()==Symb && OrderType() < 2 && OrderStopLoss()==0.0 && OrderMagicNumber()==mgc_num) otime = OrderOpenTime();
      if (OrderSymbol() == Symb && OrderType() < 2 && ((SL > 0.0 && SL == OrderStopLoss()) ||
         (SL == 0.0 && fabs(otime - OrderOpenTime()) < 17)) && OrderMagicNumber() == mgc_num) mtotal ++; }
  return(mtotal); }

int mOrderSelect(bool Mode,string Symb,bool Bull) { bool tst=false;
  if (Symb == "" || Symb == NULL) return(0);
  int total=OrdersTotal(), pos0=-1, ticket;        double PL0=0.0;

  for (int pos=0; pos < total#ifdef o_FH46 && ! tst#endif; pos ++) {     // && ! tst
#ifdef o_FH4 Alert("*****1* mOrderSelect() - " + pos + " - " + total + " *******");#endif
      if (! OrderSelect(pos, SELECT_BY_POS)) continue;         ticket = OrderTicket();
#ifdef o_FH4 Alert("*****2* mOrderSelect() - " + pos + " - " + ticket + " - " + OrderSymbol() + " - " + OrderMagicNumber() + " - " + OrderType() + " *******");#endif
#ifdef o_FH46
      if (OrderSymbol() == Symb && OrderMagicNumber() == mgc_num && ((! Mode && OrderType() < 2) || (Mode && OrderType() > 1))) {   // tst = true;
#else
      if (OrderSymbol()==Symb && OrderMagicNumber()==mgc_num && (!Mode || (OrderStopLoss()!=OrderOpenPrice() && fabs(OrderStopLoss()-OrderOpenPrice()) > 130 * 
      MarketInfo(OrderSymbol(),MODE_TICKSIZE) && OrderType() == ! Bull && mOrdersTotal(OrderSymbol(), OrderStopLoss())))) {   // tst = true;
#endif
         tst = OrderSelect(ticket, SELECT_BY_TICKET);
#ifdef o_FH4 Alert("*****3* mOrderSelect() - " + pos + " - " + ticket + " - " + tst + " *******");#endif
         pos0 = PL0 < OrderProfit()#ifdef o_FH46 || OrderProfit() <= 0.0#endif? pos: pos0;        if (PL0 < OrderProfit()) PL0 = OrderProfit();
#ifdef o_FH4 Alert("*****4* mOrderSelect() - " + pos + " - " + ticket + " - " + pos0 + " - " + PL0 + " *******");#endif
          } }
  return(pos0); }

void BrokerDigitAdjust(string symbol) {
 int Multiplier = 1;
 if (MarketInfo(symbol,MODE_DIGITS) == 3 || MarketInfo(symbol,MODE_DIGITS) == 5) Multiplier = 10;
 if (MarketInfo(symbol,MODE_DIGITS) == 6) Multiplier = 100;
 if (MarketInfo(symbol,MODE_DIGITS) == 7) Multiplier = 1000;
 pips2dbl = Multiplier*MarketInfo(symbol,MODE_POINT); }

double OffsetDollars, Bal_Max=0.0, Equ_Max=0.0, E_Balance=0.0;             datetime Max_Time;
void TrailingStop(int mode,int OffsetPoints,string Symbs) { bool tst1, tst2, tst3=false, tst4=false;
   int TS;           if (OffsetPoints == 50) TS = 30;       else TS = 70;              double E_Bal=0.0;
   if (mode == 2) { if (FileIsExist("MT4_TrailingStop_tx.txt", 0)) FileDelete("MT4_TrailingStop_tx.txt", 0);
      int rs1, rs2=-1, timeout=5000;      char post[], result[];     string URL="http://www.ecomclub.com/", headers;
      rs1 = WebRequest("GET", URL + "MT4_no_TrailingStop.txt", NULL, NULL, timeout, post, 0, result, headers);        Sleep(2 * PAUSE);
      if (rs1 < 0 || rs1 == 404) rs2 = WebRequest("GET", URL + "MT4_TrailingStop_tx.txt", NULL, NULL, timeout, post, 0, result, headers);
      if (rs2 > 0 && rs2 != 404) { int filehandle = FileOpen("MT4_TrailingStop_tx.txt", FILE_WRITE|FILE_BIN);
         if (filehandle != INVALID_HANDLE) { FileWriteArray (filehandle, result, 0, ArraySize(result));        FileClose(filehandle); } } }
   if (FileIsExist("MT4_TrailingStop_tx.txt", 0)) { filehandle = FileOpen("MT4_TrailingStop_tx.txt", FILE_TXT|FILE_READ);
      if (filehandle != INVALID_HANDLE) { TS = StrToInteger(FileReadString(filehandle));     Sleep(PAUSE);     FileClose(filehandle); } }

#ifdef o_FH7   OffsetPoints *= 2;#endif
   for (int i=OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == mgc_num && (TS == 70 ||    // && OrderType() < 2
      (TS == 30 && (StringFind(Symbs, StringSubstr(OrderSymbol(), 0, 3)) >= 0 || StringFind(Symbs, StringSubstr(OrderSymbol(), 3, 3)) >= 0)))) {
        #ifndef o_FH7 if (StringFind(AccountCompany(), "Global") > 0)#endif E_Bal += OrderProfit();          // if (StringSubstr(AccountCompany(), 0, 5) != "Eight")
         double TP1=GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP1"),
            TP2=GlobalVariableGet(OrderSymbol() + StringSubstr(IntegerToString(OrderTicket()), StringLen(IntegerToString(OrderTicket())) - 4) + "_TP2");
         if (TP2 > 0.0) { if (TP1 == 0.0) TP1 = (OrderOpenPrice() + TP2) / 2.0;
            double SLL=NormPrice(TP1 + (TP2 - TP1) * TS / 100 + (OrderType() == OP_BUY? -1: 1) * (15.0 * MarketInfo(OrderSymbol(),MODE_POINT)), OrderSymbol()), SL2;      // if (TP1 > 0.0)
if (Hour() != tsh && (mode || (! mode && ! ((Minute() - tim_min) % 2) && Seconds() < 5)))
      Print("*** TrailingStop (0) " + OrderTicket()+" - "+OrderSymbol()+" - "+(OrderType()==OP_BUY? "OP_BUY": "OP_SELL")+" - LM: "+DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),
   MODE_DIGITS)) + " - SL: " + DoubleToStr(OrderStopLoss(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP: " + DoubleToStr(OrderTakeProfit(), MarketInfo(OrderSymbol(), MODE_DIGITS)) +
   " - TP1: " + DoubleToStr(TP1, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP2: " + DoubleToStr(TP2, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - SLL: " + DoubleToStr(SLL,
   MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - (1-global) " + (OrderType() == OP_BUY? NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OrderStopLoss(),OrderSymbol()) > NormPrice(OffsetPoints *
   MarketInfo(OrderSymbol(), MODE_POINT), OrderSymbol()) && (((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()) > TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_BID),
   OrderSymbol()) > TP1 + (TP2 - TP1) * TS / 100))): NormPrice(OrderStopLoss() - MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()) > NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),
   OrderSymbol()) && (((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()) < TP1+(TP2-TP1)* TS / 100)))) +
   " -1-g " + (OrderType() == OP_BUY? NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OrderStopLoss(),OrderSymbol()): NormPrice(OrderStopLoss() - MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol())) + " -1-d " +
   NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()) + " - (tst2) " + (OrderType()==OP_BUY? (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_BID),OrderSymbol()) > TP1+(TP2-TP1)*TS/100)):
   (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1 + (TP2 - TP1) * TS / 100))) + " -2-g " + (OrderType() == OP_BUY? NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()):
   NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol())) + " -2-d " + NormPrice(TP1 + (TP2 - TP1) * TS / 100, OrderSymbol()) + " -TS: " + IntegerToString(TS) + " ***");
if (Hour() != tsh || (OrderType()==OP_BUY && NormPrice(MarketInfo(OrderSymbol(),MODE_BID)-OrderStopLoss(),OrderSymbol()) > NormPrice(OffsetPoints*MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()) &&
(((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()) > TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()) > TP1 + (TP2 - TP1) * TS / 100)))) ||
(OrderType() == OP_SELL && NormPrice(OrderStopLoss() - MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()) > NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()) &&
(((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1 + (TP2 - TP1) * TS / 100)))))
   if (mode || (! mode && ! ((Minute() - tim_min) % 2) && Seconds() < 5)) { tst4 = true;
      Print("*** TrailingStop (1) " + OrderTicket()+" - "+OrderSymbol()+" - "+(OrderType()==OP_BUY? "OP_BUY": "OP_SELL")+" - LM: "+DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),
   MODE_DIGITS)) + " - SL: " + DoubleToStr(OrderStopLoss(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP: " + DoubleToStr(OrderTakeProfit(), MarketInfo(OrderSymbol(), MODE_DIGITS)) +
   " - TP1: " + DoubleToStr(TP1, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP2: " + DoubleToStr(TP2, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - SLL: " + DoubleToStr(SLL,
   MarketInfo(OrderSymbol(), MODE_DIGITS)) + " - (1-global) " + (OrderType() == OP_BUY? NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OrderStopLoss(),OrderSymbol()) > NormPrice(OffsetPoints *
   MarketInfo(OrderSymbol(), MODE_POINT), OrderSymbol()) && (((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()) > TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_BID),
   OrderSymbol()) > TP1 + (TP2 - TP1) * TS / 100))): NormPrice(OrderStopLoss() - MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()) > NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),
   OrderSymbol()) && (((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()) < TP1+(TP2-TP1)* TS / 100)))) +
   " -1-g " + (OrderType() == OP_BUY? NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OrderStopLoss(),OrderSymbol()): NormPrice(OrderStopLoss() - MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol())) + " -1-d " +
   NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()) + " - (tst2) " + (OrderType()==OP_BUY? (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_BID),OrderSymbol()) > TP1+(TP2-TP1)*TS/100)):
   (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1 + (TP2 - TP1) * TS / 100))) + " -2-g " + (OrderType() == OP_BUY? NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()):
   NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol())) + " -2-d " + NormPrice(TP1 + (TP2 - TP1) * TS / 100, OrderSymbol()) + " -TS: " + IntegerToString(TS) + " ***"); }
            if (OrderType() == OP_BUY && NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OrderStopLoss(),OrderSymbol()) > NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()) &&
            (((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()) > TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_BID), OrderSymbol()) > TP1 + (TP2 - TP1) * TS / 100)))) {
Alert("*** TrailingStop (2) " + OrderTicket() + " - " + OrderSymbol() + " - OP: " + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - SL: " +
   DoubleToStr(OrderStopLoss(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP: " + DoubleToStr(OrderTakeProfit(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP1: " +
   DoubleToStr(TP1, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP2: " + DoubleToStr(TP2, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - SLL: " +
   DoubleToStr(SLL, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - " + tst1 + " - " + tst2 + " ***");
               if (TP2 > TP1 && OrderModify(OrderTicket(), OrderOpenPrice(), tst1 && ! tst2? NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT), OrderSymbol()):
                  tst2? (SL2=NormPrice(MarketInfo(OrderSymbol(),MODE_BID) - OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol())) > SLL? SL2: SLL:
                  OrderStopLoss(), OrderTakeProfit(),OrderExpiration(),clrNONE) == false) Alert("Cannot modify the SL due to: ", ErrorDescription(GetLastError()));
               else  tst3 = TRUE; }
            else if (OrderType() == OP_SELL && NormPrice(OrderStopLoss() - MarketInfo(OrderSymbol(),MODE_ASK),OrderSymbol()) > NormPrice(OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()) &&
            (((tst1=0) && NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1) || (tst2=(NormPrice(MarketInfo(OrderSymbol(),MODE_ASK), OrderSymbol()) < TP1 + (TP2 - TP1) * TS / 100)))) {
Alert("*** TrailingStop (3) " + OrderTicket() + " - " + OrderSymbol() + " - OP: " + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - SL: " +
   DoubleToStr(OrderStopLoss(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP: " + DoubleToStr(OrderTakeProfit(), MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP1: " +
   DoubleToStr(TP1, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - TP2: " + DoubleToStr(TP2, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - SLL: " +
   DoubleToStr(SLL, MarketInfo(OrderSymbol(),MODE_DIGITS)) + " - " + tst1 + " - " + tst2 + " ***");
               if (TP2<TP1 && TP2>0.0 && OrderModify(OrderTicket(),OrderOpenPrice(), tst1 && ! tst2? NormPrice(MarketInfo(OrderSymbol(),MODE_ASK) + OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol()):
                  tst2? (SL2=NormPrice(MarketInfo(OrderSymbol(),MODE_ASK) + OffsetPoints * MarketInfo(OrderSymbol(),MODE_POINT),OrderSymbol())) < SLL? SL2: SLL:
                  OrderStopLoss(), OrderTakeProfit(),OrderExpiration(),clrNONE) == false) Alert("Cannot modify the SL due to: ", ErrorDescription(GetLastError()));
               else  tst3 = TRUE; } } } }
#ifdef o_real
   double LimitDollars=210.0;       OffsetDollars = StringFind(AccountCompany(), "Global") < 0? 30.0: 20.0;    // StringSubstr(AccountCompany(),0,5) == "Eight"
   if (E_Balance == 0.0 && GlobalVariableCheck("E_Bal_Max")) E_Balance = GlobalVariableGet("E_Bal_Max");
#ifndef o_FH7   if (StringFind(AccountCompany(), "Global") < 0)       // if (StringSubstr(AccountCompany(), 0, 5) == "Eight")
      for (i = OrdersTotal() - 1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderType() < 2) E_Bal += OrderProfit();#endif
   if (! tst3) { LimitDollars *= AccountBalance() / 25000.00;     LimitDollars *= RM / 0.3;
      OffsetDollars *= AccountBalance() / 25000.00;#ifndef o_FH7            OffsetDollars *= RM / 0.3;
#else      if (StringFind(AccountCompany(), "Global") < 0) LimitDollars = 110.0;#endif
//      if (E_Balance < AccountEquity() - AccountBalance()) E_Balance = AccountEquity() - AccountBalance();
      if (E_Balance < E_Bal) { E_Balance = E_Bal;           GlobalVariableSet("E_Bal_Max", E_Balance); }
if (Hour() != tsh && (mode || (! mode && ! ((Minute() - tim_min) % 2) && Seconds() < 5))) Print("*** TrailingStop (0) - E_Balance: "+DoubleToStr(E_Balance,2)+
   " - (1-global) " + (E_Balance - E_Bal > OffsetDollars && (tst2=(E_Balance > LimitDollars))) + " -1-g " + DoubleToStr(E_Balance - E_Bal, 2) +
   " -1-d " + DoubleToStr(OffsetDollars, 2) + " - (tst2) " + (E_Balance > LimitDollars) + " -2-g " + DoubleToStr(E_Balance, 2) + " -2-d " +
   DoubleToStr(LimitDollars, 2) + " -acc_f " + DoubleToStr(AccountBalance() / 25000.00, 1) + " -rm_f " + DoubleToStr(RM / 0.3, 1) + " ***");
if (Hour() != tsh || (E_Balance - E_Bal > OffsetDollars && (tst2=(E_Balance > LimitDollars))))
   if (mode || (! mode && ! ((Minute() - tim_min) % 2) && Seconds() < 5)) { tst4 = true;
      Print("*** TrailingStop (1) - E_Balance: " + DoubleToStr(E_Balance, 2) + " - (1-global) " +
   (E_Balance - E_Bal > OffsetDollars && (tst2=(E_Balance > LimitDollars))) + " -1-g " + DoubleToStr(E_Balance - E_Bal, 2) + " -1-d " +
   DoubleToStr(OffsetDollars, 2) + " - (tst2) " + (E_Balance > LimitDollars) + " -2-g " + DoubleToStr(E_Balance, 2) + " -2-d " +
   DoubleToStr(LimitDollars, 2) + " -acc_f " + DoubleToStr(AccountBalance() / 25000.00, 1) + " -rm_f " + DoubleToStr(RM / 0.3, 1) + " ***"); }
      if (E_Balance - E_Bal > OffsetDollars && (tst2=(E_Balance > LimitDollars))) { Close_All_Trades(0);
Alert("*** TrailingStop (2) - E_Balance: " + DoubleToStr(E_Balance, 2) + " - " + DoubleToStr(E_Bal, 2) + " - " + tst2 + " ***"); } }
#endif   if (tst4) tsh = Hour();
   if (mode) { if (GlobalVariableCheck("Equity_Max")) Equ_Max = GlobalVariableGet("Equity_Max");
      if (GlobalVariableCheck("Balance_Max")) Bal_Max = GlobalVariableGet("Balance_Max");
      if (AccountBalance() > Bal_Max) { GlobalVariableSet("Balance_Max", AccountBalance());
         GlobalVariableSet("Balance_Time", TimeCurrent());     Max_Time = TimeCurrent(); }
      if (AccountEquity() > Equ_Max) GlobalVariableSet("Equity_Max", AccountEquity()); }
}

double NormPrice(double Price,string Symb) { return NormalizeDouble(Price, MarketInfo(Symb, MODE_DIGITS)); }

string Symb_Check(string Symb,double LM) { lot = _lot;         ResetLastError();
#ifdef o_FH6      // remettre o_FH46 lorsque FSX_VIP (/ FH4) sera transféré sur FH6 en remplaçant FRN_VIP
   lot = AccountBalance() < 100.0? 0.01: floor(AccountBalance() / 100.0) * 0.01;
#ifdef o_FH7
   lot =/* Symb == "DJ30" || Symb == "CL-OIL" || Symb == "NAS100" || Symb == "XAUUSD" || Symb == "BTCUSD"? 0.1:*/ AccountBalance() < 100.0? 0.01: round(AccountBalance() /
      (AccountBalance() > 1000.0? 1000.0: 100.0)) * 0.01;
#endif
#else
   lot =/* Symb == "DJ30" || Symb == "CL-OIL" || Symb == "NAS100" || Symb == "XAUUSD" || Symb == "BTCUSD"? 0.1:*/ AccountBalance() < 100.0? 0.01: round(AccountBalance() /
      (AccountBalance() > 1000.0? 1000.0: 100.0)) * 0.01;
#endif
   if (StringFind(Symb, "/") > 3) Symb = StringSubstr(Symb, 0, StringFind(Symb, "/"));    else if (StringFind(Symb, "/") > 0) StringReplace(Symb, "/", "");
   string s_comp=AccountCompany();                    StringReplace(Symb, "|", "");
   int i_comp=StringSubstr(s_comp,0,5) == "Black"? 0: StringSubstr(s_comp,0,5) == "FX Ch"? 1: StringSubstr(s_comp,0,5) == "Trade"? 2: StringSubstr(s_comp,0,5) == "Vanta"? 3:
      StringSubstr(s_comp,0,5) == "Eight"? 4: 5;
   switch(i_comp) {
         case 0  :      if (Symb == "Silver") Symb = "XAGUSD";
      if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         Symb += "p";         if (Symb == "XBRUSDp") Symb = "BRENT";
      if (Symb=="XTIUSDp" || Symb=="USOILp") if (LM > 0.0) Symb = fabs((MarketInfo("WTI",MODE_BID)+MarketInfo("WTI",MODE_ASK))/2 - LM) > 
         fabs((MarketInfo("BRENT",MODE_BID)+MarketInfo("BRENT",MODE_ASK))/2 - LM) ? "BRENT" : "WTI";     else  Symb = "WTI";
      if (StringSubstr(Symb, 0, 3) == "GNP") Symb = "GBP" + StringSubstr(Symb, 3);        if (Symb == "US30p") { Symb = "US30";     lot = 0.01; }
         break;
         case 1  :      if (Symb == "Silver") Symb = "XAGUSD";
      if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         if (Symb == "XBRUSD") Symb = "BRENT";           // Symb += "p";
      if (Symb=="XTIUSD" || Symb=="USOIL") if (LM > 0.0) Symb = fabs((MarketInfo("WTI",MODE_BID)+MarketInfo("WTI",MODE_ASK))/2 - LM) > 
         fabs((MarketInfo("BRENT",MODE_BID)+MarketInfo("BRENT",MODE_ASK))/2 - LM) ? "BRENT" : "WTI";     else  Symb = "WTI";
      if (StringSubstr(Symb, 0, 3) == "GNP") Symb = "GBP" + StringSubstr(Symb, 3);        if (Symb == "US30") { Symb = "US30";      lot = 0.1; }
         break;
         case 2  :
         break;
         case 3  :      if (Symb == "Silver") Symb = "XAGUSD";
      if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         if (Symb == "XBRUSD") Symb = "BRENT";           // Symb += "p";
      if (Symb=="XTIUSD" || Symb=="USOIL") if (LM > 0.0) Symb = fabs((MarketInfo("WTI",MODE_BID)+MarketInfo("WTI",MODE_ASK))/2 - LM) > 
         fabs((MarketInfo("BRENT",MODE_BID)+MarketInfo("BRENT",MODE_ASK))/2 - LM) ? "BRENT" : "WTI";     else  Symb = "WTI";
      if (StringSubstr(Symb, 0, 3) == "GNP") Symb = "GBP" + StringSubstr(Symb, 3);        if (Symb == "US30") { Symb = "DJ30";      lot = 0.1; }
      if (Symb == "NASdaq100") { Symb = "NAS100";     lot = 0.1; }         if (Symb == "CRUDE") Symb = "CL-OIL";
         break;
         case 4  :         string str=Symb;        if (Symb == "Silver") Symb = "XAGUSD";
      if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";         if (Symb == "XBRUSD") Symb = "UKOUSD";
      if (Symb=="XTIUSD" || Symb=="USOIL") /*if (LM > 0.0) Symb = fabs((MarketInfo("WTI",MODE_BID)+MarketInfo("WTI",MODE_ASK))/2 - LM) > 
         fabs((MarketInfo("BRENT",MODE_BID)+MarketInfo("BRENT",MODE_ASK))/2 - LM) ? "BRENT" : "WTI";     else*/  Symb = "USOUSD";
      if (StringSubstr(Symb,0,3) == "GNP") Symb = "GBP"+StringSubstr(Symb,3) + ".i";
      if (Symb == "US30") Symb += StringFind(AccountCompany(), "Global") < 0? ".p": ".i";    //       lot = 0.1; }
      else  if (Symb == "NASdaq100") Symb = "NDX100" + (StringFind(AccountCompany(), "Global") < 0? ".p": ".i");
      /*lot = 0.1; } */          else  if (Symb == "CRUDE") Symb = "CL-OIL";
      else if (Symb=="BTCUSD") Symb += ".p";    else if (str==Symb && ((Symb!="XAUUSD" && Symb!="XAGUSD") || StringFind(s_comp,"Global")>0)) Symb += ".i";
         break;
         default :
      if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";      if (Symb == "Silver") Symb = "XAGUSD"; }

      if (port) { port = false;
         for (int pos=0; pos < OrdersTotal() && ! port; pos ++) port = (OrderSelect(pos, SELECT_BY_POS) && Symb == OrderSymbol() && mgc_num == OrderMagicNumber()); }
Print("******* " + s_comp + " - " + IntegerToString(i_comp) + " - " + port + " *******");          _p = i_comp ? "" : "p";
#ifdef o_FH4      if ((Symb == "DJ30" || Symb == "US30" || Symb == "NAS100" || Symb == "XAUUSD"+_p || Symb == "BTCUSD") && AccountBalance() < 200.0) lot = 0.0;#endif
 return(Symb); }

void Close_All_Trades(int mode) { string temp;     E_Balance = 0.0;     GlobalVariableSet("E_Bal_Max", 0);
  for (int i = OrdersTotal()-1; i >= 0; i --) {
    if (OrderSelect(i, SELECT_BY_POS) && (#ifndef o_FH7(StringFind(AccountCompany(), "Global") < 0 &&     // StringSubstr(AccountCompany(), 0, 5) == "Eight"
    fabs(OrderProfit()) > fmax(OffsetDollars, 50.0)) ||#endif OrderMagicNumber() == mgc_num)) {
       int type = OrderType();      bool result = false;
       switch(type) {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Pink);   // Slippage
                         break;
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Pink);   // Slippage
                         break;
          //Close pending orders
            case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );     break;
            case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );     break;
            case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );     break;
            case OP_SELLSTOP  : result = OrderDelete( OrderTicket() ); }
       if (result == false) Sleep(2000); } } //*/

  if (mode) temp = "***** Account CLOSE ALL Demand. All Trades Have Been Closed. ("+DoubleToStr(AccountBalance(),2)+" - "+Hour()+") *****";
  else   temp = "***** Account Balance TRAILINGSTOP. All Trades Have Been Closed. ("+DoubleToStr(AccountBalance(),2)+" - "+Hour()+") *****";
  Alert(temp);          // copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
/* t_ngt0 = true;        GlobalVariableSet("t_ngt_3", 1.0); */       Sleep(100);       if (mode) ExpertRemove(); }
#ifdef o_real

void Close_All_TradesW() { string temp;       w_ticket = 0;
  for (int i = OrdersTotal()-1; i >= 0; i --) {
    if (OrderSelect(i, SELECT_BY_POS)) { bool result = false;     if (mgc_num == OrderMagicNumber() || ! OrderMagicNumber()) {
       mOrderSend(OrderSymbol(), OrderLots(), OrderType(), OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit(), OrderMagicNumber(), OrderComment());
       switch(OrderType()) {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Pink);   // Slippage
                         break;
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Pink);   // Slippage
                         break;
          //Close pending orders
            case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );     break;
            case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );     break;
            case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );     break;
            case OP_SELLSTOP  : result = OrderDelete( OrderTicket() ); }
       if (result == false) Sleep(2000); } } }

  temp = "***** Account WE Reached. All Trades Have Been Closed. ("+DoubleToStr(AccountBalance(),2)+" - "+Hour()+") *****";      Alert(temp); }

string line_read2[][18];       int w_ticket=0;
void mOrderSend(string Symb,double wlot,int Type,double LM,double SL,double TP,long mgcnum,string Comm) {
   w_ticket ++;         string tmp;       int itmp=22;         if (Type > 3) return;
// OrderTicket;1;OrderLot;1;OrderType;1;OrderPrice;31818.23;OrderMgNum;1626656408;OrderStopLoss;32618.23;OrderTakeProfit;;OrderSymb;EURUSD;OrderComment;;
   tmp = "OrderTicket;"+w_ticket+";OrderLot;"+wlot+";OrderType;"+Type+";OrderPrice;"+DoubleToStr(LM, MarketInfo(Symb, MODE_DIGITS))+";OrderMgNum;"+mgcnum+";OrderStopLoss;"+
      DoubleToStr(SL, MarketInfo(Symb, MODE_DIGITS))+";OrderTakeProfit;"+DoubleToStr(TP, MarketInfo(Symb, MODE_DIGITS))+";OrderSymb;"+Symb+";OrderComment;"+Comm+";";
   int handle;       string filename="Liste dObjets EA - dump.csv";
   if (!FileIsExist(filename)) handle = FileOpen (filename,FILE_TXT|FILE_WRITE);
   else   handle = FileOpen (filename,FILE_TXT|FILE_READ|FILE_WRITE);
   if (handle != INVALID_HANDLE) { if (FileSize(handle)) FileSeek(handle, FileSize(handle), 0);
       FileWrite(handle, tmp); }          FileClose(handle);
//   else Print ("Problème : handle == INVALID_HANDLE. (2) / "+vSymbol+" ***");
   line_read2[w_ticket-1][1] = w_ticket;        line_read2[w_ticket-1][3] = wlot;         line_read2[w_ticket-1][5] = Type;
   line_read2[w_ticket-1][7] = DoubleToStr(LM, MarketInfo(Symb, MODE_DIGITS));            line_read2[w_ticket-1][9] = mgcnum;
   line_read2[w_ticket-1][11] = DoubleToStr(SL, MarketInfo(Symb, MODE_DIGITS));           line_read2[w_ticket-1][13] = DoubleToStr(TP, MarketInfo(Symb, MODE_DIGITS));
   line_read2[w_ticket-1][15] = Symb;                          line_read2[w_ticket-1][17] = Comm;
Print("******* " + (w_ticket-1) + " - " + line_read2[w_ticket-1][1] + " - " + line_read2[w_ticket-1][3] + " - " + line_read2[w_ticket-1][5] + " - " + line_read2[w_ticket-1][7] + " - " +
   line_read2[w_ticket-1][9] + " - " + line_read2[w_ticket-1][11] + " - " + line_read2[w_ticket-1][13] + " - " + line_read2[w_ticket-1][15] + " - " + line_read2[w_ticket-1][17] + " *******"); }

void Open_All_TradesW() { int nLines=0, handle=FileOpen("Liste dObjets EA - dump.csv", FILE_TXT|FILE_READ, ';');
   if (handle != INVALID_HANDLE) { while(true) { string line = FileReadString(handle);
      if (FileIsLineEnding(handle)) nLines ++;        if (FileIsEnding(handle)) break; }
   FileClose(handle);         Alert("******* File contains "+nLines+" lines *******"); }
   ArrayResize(line_read2, nLines, 1);       int row=0;        double price;        ResetLastError();

   if (FileIsExist("Liste dObjets EA - dump.csv", 0)) WE_FILE_READ("Liste dObjets EA - dump.csv");

   if (line_read2[0][0] != "OrderTicket") { Alert("Erreur sur la valeur de départ !");       return; }
// OrderTicket;1;OrderLot;1;OrderType;1;OrderPrice;31818.23;OrderMgNum;1626656408;OrderStopLoss;32618.23;OrderTakeProfit;;OrderSymb;EURUSD;rderComment;;
   while (row < ArraySize(line_read2) / 18) {
      if (fabs(StrToDouble(line_read2[row][7]) - (price=((MarketInfo(line_read2[row][15], MODE_BID) + MarketInfo(line_read2[row][15], MODE_ASK)) / 2))) < 0.01 * price &&
      OrderSend(line_read2[row][15], StrToInteger(line_read2[row][5]), StrToDouble(line_read2[row][3]), (StrToInteger(line_read2[row][5])? MarketInfo(line_read2[row][15], MODE_BID):
         MarketInfo(line_read2[row][15], MODE_ASK)), 15, StrToDouble(line_read2[row][11]), StrToDouble(line_read2[row][13]), line_read2[row][17], StrToInteger(line_read2[row][9])))
Alert("******* " + line_read2[row][15] + " - " + line_read2[row][5] + " - " + line_read2[row][3] + " - " + line_read2[row][7] + " - " + line_read2[row][11] + " - " +
   line_read2[row][13] + " - " + line_read2[row][17] + " - " + line_read2[row][9] + " *******");            else
Alert("******* Erreur : " + line_read2[row][15] + " - " + line_read2[row][5] + " - " + line_read2[row][3] + " - " + line_read2[row][7] + " - " + line_read2[row][11] + " - " +
   line_read2[row][13] + " - " + line_read2[row][17] + " - " + line_read2[row][9] + " - " + GetLastError() + " - " +
   DoubleToStr(fabs(StrToDouble(line_read2[row][7]) - price), MarketInfo(line_read2[row][15], MODE_DIGITS)) + " *******");             row ++; } }

void WE_FILE_READ(string filename) {
   int row=0, col=0, handle=FileOpen(filename,FILE_CSV|FILE_READ,";");
   if(handle > 0) {
      while(True) { string temp=FileReadString(handle);
         if (FileIsEnding(handle)) break;
         line_read2[row][col] = temp;
         if(FileIsLineEnding(handle)) {
            col = 0;       row ++; }
         else col ++; }
      FileClose(handle); }
   else Comment("File "+filename+" not found, the last error is ", GetLastError()); }

bool DrawArrow_chk(double LinePrice,int BarNum,int I) { int tmfr=Period();
   string stmfr= tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
      tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1", 
      ArrowName="EA_Check-"+stmfr+"-"+IntegerToString(I)+"_"+IntegerToString(BarNum)+" "+IntegerToString(Time[BarNum]);
   if (! ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice)) return false;
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, I? 252: 251);
   ObjectSet(ArrowName, OBJPROP_COLOR, I==1? clrSilver: clrSkyBlue);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, I==3? 251: 252);
   ObjectSet(ArrowName, OBJPROP_COLOR, I==1 || I>=4? I==1 && OrdersTotal()? clrGold: clrSilver: clrSkyBlue);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
   ObjectSet(ArrowName, OBJPROP_WIDTH, I==5? 1: 2);
//   ObjectSet(ArrowName, OBJPROP_YDISTANCE, 55);
   return true;
}

void ObjectsPositions(double vScale) {
   int j=0,tmfr=Period(),bar=WindowFirstVisibleBar(),obj_total=ObjectsTotal(),bars=WindowBarsPerChart();    while(! Time[bar-bars+j]) j ++;
   string name, stmfr= tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
      tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1";
   datetime OTime, WM = WindowPriceMax();       for (int pos=0; pos < obj_total; pos ++) {
     name = ObjectName(pos);    OTime = ObjectGet(name,OBJPROP_TIME1);
     if (pos && (StringSubstr(name,0,8) == "EA_Check" || StringSubstr(name,0,8) == "EA_Test1" || StringSubstr(name,0,8) == "EA_Test2")) 
      if (Time[bar] <= OTime && Time[bar-bars+j]+Period()*60 >= OTime) {
         if (StringSubstr(name,9,StringFind(name,"-",StringFind(name,"-")+1)-9) != stmfr) {   // && stmfr!="M1"
            ObjectSet(name,OBJPROP_BACK,true);       ObjectSet(name,OBJPROP_PRICE1, WM - 50 * vScale * Point);
            if (ObjectGet(name,OBJPROP_COLOR)) { ObjectSet(name,OBJPROP_ZORDER,ObjectGet(name,OBJPROP_COLOR));    ObjectSet(name,OBJPROP_COLOR,clrIndigo); } }
         else { ObjectSet(name,OBJPROP_BACK,false);      ObjectSet(name,OBJPROP_PRICE1, WM - 50 * vScale * Point);
            if (ObjectGet(name,OBJPROP_ZORDER)) { ObjectSet(name,OBJPROP_COLOR,ObjectGet(name,OBJPROP_ZORDER));      ObjectSet(name,OBJPROP_ZORDER,0); } } } }
   return; }
#endif
