/* #import "shell32.dll"
 int ShellExecuteW(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import */
extern int Valid_Hours = 192;
extern bool reWrite_Alerts = 0;        // mettre 1 sur un seul compte FTUK
extern bool High_Risk = false;
extern string Ftp_Ids = "2-4";

int ordersTotal=0, f_mod, f_mod2, f_siz, f_siz2;         datetime t_read;        bool rew=reWrite_Alerts, hr=High_Risk;
string Symb_=" AUDNZD | GBPJPY | USDCHF | USDJPY | GBPAUD | GBPCAD | USDCAD | NZDCAD | AUDCAD | GBPUSD | UKOUSD | US30 | XAUUSD | EURUSD | GBPCHF | CADCHF | USDSGD";

int OnInit() { EventSetTimer(10);
   int handle=FileOpen("Cash_Power_Alerts_w.txt", FILE_TXT|FILE_READ|FILE_COMMON);
   if (handle != INVALID_HANDLE) { f_mod2 = FileGetInteger(handle, FILE_MODIFY_DATE);
      f_siz2 = FileGetInteger(handle, FILE_SIZE);           FileClose(handle); }
   return(INIT_SUCCEEDED); }

void OnTick() { int per=Valid_Hours;            double tx;
   if ((TimeCurrent() - t_read > 15 &&/* (! Hour() || Hour()==8 || Hour()==12 || Hour()==16) &&*/ ! (Minute() % 15) && Seconds() < 7) ||
   ! FileIsExist("Cash_Power_Alerts_w.txt", FILE_COMMON)) {
      string URL, filename="Cash_Power_Alerts_w.txt", headers;
      char post[], result[];           int res, timeout=5000;        //, ts
      URL = "http://www.ecomclub.com/Cash_Power_Alerts.txt";
      res = WebRequest("GET", URL, NULL, NULL, timeout, post, 0, result, headers);
      if (res != 200) Print("*** Error in WebRequest (" + IntegerToString(res) + "). Error code = ", GetLastError(), " ***");
      else { PrintFormat("** The file has been successfully loaded ("+IntegerToString(res)+"), File size = %d bytes **", ArraySize(result));
         t_read = TimeCurrent(); }

      int filehandle = FileOpen(filename, FILE_WRITE|FILE_BIN|FILE_COMMON);
      if (filehandle != INVALID_HANDLE) {
         FileWriteArray (filehandle, result, 0, ArraySize(result));
         FileClose(filehandle); }
      else  Print("******* handle==INVALID_HANDLE : FileOpen(\"Cash_Power_Alerts_w.txt\"  *******"); }              int cpt=0;

//   ts = ShellExecuteW(0,"open","C:\\Users\\Administrateur\\AppData\\Roaming\\MetaQuotes\\Terminal\\E88DA660F9A20E5DD9C622B8430BA4F1\\MQL4\\copy_file.bat",
//      "Cash_Power_Alerts.txt >>Logs\\copy_file.txt", "C:\\Users\\Administrateur\\AppData\\Roaming\\MetaQuotes\\Terminal\\E88DA660F9A20E5DD9C622B8430BA4F1\\MQL4", 2);

   if ((myHour() && DayOfWeek() == 5) || f_mod2 > f_mod || f_siz2 != f_siz) { int handle=FileOpen("Cash_Power_Alerts_w.txt", FILE_TXT|FILE_READ|FILE_COMMON), nLines=0;
      bool tst, Buy, Sell;       if (handle != INVALID_HANDLE) { while(true) { string line="";           line = FileReadString(handle);
         if (FileIsLineEnding(handle)) nLines ++;        if (FileIsEnding(handle)) break; }//        nLines ++;
         FileClose(handle);      // Print("******* File Cash_Power_Alerts_w.txt contains "+nLines+" line"+(nLines > 1? "s": "")+" *******");
         ArrayResize(line_read, nLines + 1, 1);       Sleep(100);       while(TXT_FILE_READ(0) && cpt < 7) { Sleep(100);      cpt ++; }         string Symbs="|", temp;

         string sep="|", line_read2[], tmp, tmp2, tmp3, tmp4="";        ushort u_sep=StringGetCharacter(sep, 0);         nLines = 0;
         Sleep(100);       for (int row=0; row < ArraySize(line_read); row ++) if (StringLen(line_read[row]) > 35) { cpt = 0;
            int k=StringSplit(line_read[row], u_sep, line_read2);             tst = false;         bool tst2=false, tst3;
            if (k > 7) { tmp = StringSubstr(line_read[row], 0, 8);
               if ((tst=(StringFind(line_read[row], tmp, 10) > 0))) {
                  tmp = StringSubstr(line_read[row], StringFind(line_read[row], tmp, 10), StringLen(line_read[row]));
                  line_read[row] = StringSubstr(line_read[row], 0, StringFind(line_read[row], StringSubstr(tmp, 0, 8), 10));
                  k = StringSplit(line_read[row], u_sep, line_read2);
                  while(! MathIsValidNumber(StringSubstr(tmp, StringLen(tmp) - 1, 1)) ||
                  StringGetCharacter(StringSubstr(tmp, StringLen(tmp) - 1, 1), 0) == 13)
                     tmp = StringSubstr(tmp, 0, StringLen(tmp) - 1); }
                  if (StringGetCharacter(StringSubstr(tmp, StringLen(tmp) - 1, 1), 0) == 50)
                     tmp = StringSubstr(tmp, 0, StringLen(tmp) - 3);
                  tst3 = StringLen(tmp) > 100;           tmp3 = tmp;
                  while(tst3) { tmp2 = StringSubstr(tmp3, StringFind(tmp3, "2023") - 6, 8);
                     if ((tst2=(StringFind(tmp3, tmp2, 10) > 0))) {
                        tmp2 = StringSubstr(tmp3, StringFind(tmp3, tmp2, 10), StringLen(tmp3));
                        tmp3 = StringSubstr(tmp3, 0, StringFind(tmp3, StringSubstr(tmp2, 0, 8), 10));
                        while(! MathIsValidNumber(StringSubstr(tmp3, StringLen(tmp3) - 1, 1)) ||
                        StringGetCharacter(StringSubstr(tmp3, StringLen(tmp3) - 1, 1), 0) == 13 ||
                        StringFind(StringSubstr(tmp3, StringLen(tmp3) - 8, 8), "-") > 0)
                           tmp3 = StringSubstr(tmp3, 0, StringLen(tmp3) - 1);
                        if (StringGetCharacter(StringSubstr(tmp3, StringLen(tmp3) - 1, 1), 0) == 50)
                           tmp3 = StringSubstr(tmp3, 0, StringLen(tmp3) - 3);          cpt = 0;
                        while(StringSubstr(tmp3, StringLen(tmp3) - 10, 2) != 16 &&
                        StringSubstr(tmp3, StringLen(tmp3) - 11, 2) != 16 &&
                        StringSubstr(tmp3, StringLen(tmp3) - 12, 2) != 16 && cpt < 4) { tmp3 += "0";     cpt ++; }
                        cpt = 0;       while(StringSubstr(tmp3, StringLen(tmp3) - 10, 2) != 16 && cpt < 4) {
                           tmp3 = StringSubstr(tmp3, 0, StringLen(tmp3) - 1);          cpt ++; }
                        while(StringFind(tmp3, "2023") > 6) tmp3 = StringSubstr(tmp3, 1, StringLen(tmp3) - 1);
                        tmp4 += tmp3 + "\r\n";           nLines ++;        tmp3 = tmp2; }
                     else  tmp3 = StringSubstr(tmp3, 0, 100);        tst3 = StringLen(tmp3) > 100; }
                  if (tmp4 != "" && StringLen(tmp2) > 35) {
                     while(! MathIsValidNumber(StringSubstr(tmp2, StringLen(tmp2) - 1, 1)) ||
                     StringGetCharacter(StringSubstr(tmp2, StringLen(tmp2) - 1, 1), 0) == 13 ||
                     StringFind(StringSubstr(tmp2, StringLen(tmp2) - 8, 8), "-") > 0)
                        tmp2 = StringSubstr(tmp2, 0, StringLen(tmp2) - 1);
                     if (StringGetCharacter(StringSubstr(tmp2, StringLen(tmp2) - 1, 1), 0) == 50)
                        tmp2 = StringSubstr(tmp2, 0, StringLen(tmp2) - 3);          cpt = 0;
                     while(StringSubstr(tmp2, StringLen(tmp2) - 10, 2) != 16 &&
                     StringSubstr(tmp2, StringLen(tmp2) - 11, 2) != 16 &&
                     StringSubstr(tmp2, StringLen(tmp2) - 12, 2) != 16 && cpt < 4) { tmp2 += "0";     cpt ++; }
                     cpt = 0;       while(StringSubstr(tmp2, StringLen(tmp2) - 10, 2) != 16 && cpt < 4) {
                        tmp2 = StringSubstr(tmp2, 0, StringLen(tmp2) - 1);          cpt ++; }
                     while(StringFind(tmp2, "2023") > 6) tmp2 = StringSubstr(tmp2, 1, StringLen(tmp2) - 1);
                     tmp4 += tmp2 + "\r\n";        nLines ++; } }
            while(! MathIsValidNumber(StringSubstr(line_read[row], StringLen(line_read[row]) - 1, 1)) ||
            StringGetCharacter(StringSubstr(line_read[row], StringLen(line_read[row]) - 1, 1), 0) == 13)
               line_read[row] = StringSubstr(line_read[row], 0, StringLen(line_read[row]) - 1);
            if (StringGetCharacter(StringSubstr(line_read[row], StringLen(line_read[row]) - 1, 1), 0) == 50)
               line_read[row] = StringSubstr(line_read[row], 0, StringLen(line_read[row]) - 3);
            if (StringFind(Symb_, StringTrimLeft(StringTrimRight(line_read2[1]))) > 0 &&
            ((StrToInteger(StringTrimLeft(StringTrimRight(line_read2[2]))) == 1440 &&
            TimeCurrent() - StrToInteger(StringTrimLeft(StringTrimRight(line_read2[6]))) < 44 * 96 * 3600) ||
            (StrToInteger(StringTrimLeft(StringTrimRight(line_read2[2]))) == 240 &&
            TimeCurrent() - StrToInteger(StringTrimLeft(StringTrimRight(line_read2[6]))) < 22 * 96 * 3600) ||
            (StrToInteger(StringTrimLeft(StringTrimRight(line_read2[2]))) <= 60 &&
            TimeCurrent() - StrToInteger(StringTrimLeft(StringTrimRight(line_read2[6]))) < 7 * 96 * 3600))) {
               temp += line_read[row] + "\r\n";             nLines ++;
               if (tst && StringLen(tmp) > 35 && tmp4 == "") { temp += tmp + "\r\n";      nLines ++; }
               if (tst2 && StringLen(tmp4) > 35) temp += tmp4; } }

         temp = StringSubstr(temp, 0, StringLen(temp) - 2);
         copy_file("Cash_Power_Alerts.txt", temp);          Sleep(100);          cpt = 0;
         ArrayResize(line_read, nLines + 1, 1);       while(TXT_FILE_READ(1) && cpt < 7) { Sleep(100);      cpt ++; }         Sleep(100);       cpt = 0;

         if (myHour() && DayOfWeek() == 5 && rew) { if (FileIsExist("Cash_Power_Alerts.txt", 0)) { FileDelete("Cash_Power_Alerts.txt", 0);      Sleep(100); }
            FileCopy("Cash_Power_Alerts.txt", FILE_COMMON, "Cash_Power_Alerts.txt", 0);         Sleep(200);
            while(! SendFTP("Cash_Power_Alerts.txt", NULL) && cpt < 7) { Sleep(200);            cpt ++; }      // www/logs_ATS/FxChoice-4
            URL = "http://www.ecomclub.com/web_send_cashpower.php?wa=tr&ftp=" + Ftp_Ids;        Sleep(200);
            res = WebRequest("GET", URL, NULL, NULL, timeout, post, 0, result, headers); }

         else { for (row = ArraySize(line_read) - 1; row >= 0; row --) { k = StringSplit(line_read[row], u_sep, line_read2);
               if (StringFind(Symbs, StringTrimRight(StringTrimLeft(line_read2[1])) + "|" + StringTrimRight(StringTrimLeft(line_read2[2]))) < 0)
                  if (TimeCurrent() - StrToInteger(StringTrimRight(StringTrimLeft(line_read2[6]))) < 44 * 96 * 3600) {
                     GlobalVariableSet(StringTrimRight(StringTrimLeft(line_read2[1])) + "_" + StringTrimRight(StringTrimLeft(line_read2[2])) +
                        "_CashPower", (StringTrimRight(StringTrimLeft(line_read2[3])) == "Sell"? 2: 1));
                     GlobalVariableSet(StringTrimRight(StringTrimLeft(line_read2[1])) + "_" + StringTrimRight(StringTrimLeft(line_read2[2])) +
                        "_CP_Pos", StringTrimRight(StringTrimLeft(line_read2[4])));
                     GlobalVariableSet(StringTrimRight(StringTrimLeft(line_read2[1])) + "_" + StringTrimRight(StringTrimLeft(line_read2[2])) +
                        "_CP_Tim", StringTrimRight(StringTrimLeft(line_read2[6])));
                     Symbs += StringTrimRight(StringTrimLeft(line_read2[1])) + "|" + StringTrimRight(StringTrimLeft(line_read2[2])) + "|"; }
                  else { GlobalVariableSet(StringTrimRight(StringTrimLeft(line_read2[1])) + "_" + StringTrimRight(StringTrimLeft(line_read2[2])) + "_CashPower", 0);
                     GlobalVariableDel(StringTrimRight(StringTrimLeft(line_read2[1])) + "_" + StringTrimRight(StringTrimLeft(line_read2[2])) + "_CP_Pos");
                     GlobalVariableDel(StringTrimRight(StringTrimLeft(line_read2[1])) + "_" + StringTrimRight(StringTrimLeft(line_read2[2])) + "_CP_Tim"); } }
            rew = reWrite_Alerts; } } }

   tst = false;         for (int pos=0; pos < OrdersTotal() && ! tst; pos ++) tst = OrderSelect(pos, SELECT_BY_POS) && ! OrderStopLoss();
   string Symb;         if (OrdersTotal() != ordersTotal || tst) for (pos = 0; pos < OrdersTotal(); pos ++) {
         if (OrderSelect(pos, SELECT_BY_POS)) { Symb = StringFind(OrderSymbol(), ".") > 0? StringSubstr(OrderSymbol(), 0, StringFind(OrderSymbol(), ".")):
               StringSubstr(OrderSymbol(), StringLen(OrderSymbol())-1, 1) == "p"? StringSubstr(OrderSymbol(), 0, StringLen(OrderSymbol())-1): OrderSymbol();      StringToUpper(Symb);
            Symb = Symb_Check(Symb);      if (StringFind(OrderSymbol(), "JPY") > 0 || StringFind(OrderSymbol(), "USD") > 0 || StringFind(OrderSymbol(), "GBP") > 0) {
               if (hr) tx = 0.01;         else  tx = 0.007495; }           else { if (hr) tx = 0.005;          else  tx = 0.00375; }
            if (OrderStopLoss() == 0.0 || (OrderStopLoss() == NormPrice((OrderType()? 1.0 + tx: 1.0 - tx) * OrderOpenPrice(), Symb) && GlobalVariableGet(Symb+"_240_CashPower") == OrderType()) ||
            (OrderStopLoss() == NormPrice((OrderType()? 1.0 + tx*2.0: 1.0 - tx*2.0) * OrderOpenPrice(), Symb) && GlobalVariableGet(Symb+"_240_CashPower") != OrderType())) {
               tst = (Sell=((GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600 &&
                  ((GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600))) ||
                  (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600 &&
                  ((GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600))) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600 &&
                  ((GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600) ||
                  (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600))) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600 &&
                  ((GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600) ||
                  (GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 2 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600))))) ||
                  (Buy=((GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600 &&
                  ((GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600))) ||
                  (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600 &&
                  ((GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600))) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600 &&
                  ((GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600) ||
                  (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600))) ||
                  (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_30_CP_Tim") < 0.125*per*3600 &&
                  ((GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_240_CP_Tim") < per*3600) ||
                  (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb + "_60_CP_Tim") < 0.25*per*3600) ||
                  (GlobalVariableCheck(Symb+"_1440_CashPower") && GlobalVariableGet(Symb+"_1440_CashPower") == 1 && TimeCurrent() - GlobalVariableGet(Symb+"_1440_CP_Tim") < 3.5*per*3600)))));
               if (tst && ((Sell && ! Buy && ! OrderType()) || (Buy && ! Sell && OrderType())))
                  tst = OrderModify(OrderTicket(), OrderOpenPrice(), NormPrice((OrderType()? 1.0 + tx: 1.0 - tx) * OrderOpenPrice(), Symb), OrderTakeProfit(), 0, clrNONE);
               else  tst = OrderModify(OrderTicket(), OrderOpenPrice(), NormPrice((OrderType()? 1.0 + tx*2.0: 1.0 - tx*2.0) * OrderOpenPrice(), Symb), OrderTakeProfit(), 0, clrNONE); } } }

   ordersTotal = OrdersTotal();        f_mod = f_mod2;         f_siz = f_siz2; }

void OnDeinit(const int reason) { EventKillTimer(); }

void OnTimer() { int handle=FileOpen("Cash_Power_Alerts_w.txt", FILE_TXT|FILE_READ|FILE_COMMON);
   if (handle != INVALID_HANDLE) { f_mod2 = FileGetInteger(handle, FILE_MODIFY_DATE);
      f_siz2 = FileGetInteger(handle, FILE_SIZE);           FileClose(handle); } }

/* string line_read[][7];
bool CSV_FILE_READ() { string filename="Cash_Power_Alerts.txt", filenam2="Cash_Power_Alerts-2.txt";
   if (FileIsExist(filenam2, FILE_COMMON)) FileDelete(filenam2, FILE_COMMON);       Sleep(100);
   FileCopy(filename, FILE_COMMON, filenam2, FILE_COMMON);        Sleep(100);       filename = filenam2;
   int row=0, col=0, handle=-1, cpt=0;       while(handle < 0 && cpt < 7) {
      handle = FileOpen(filename, FILE_CSV|FILE_READ|FILE_COMMON, "|");
      if(handle > 0) { while(True) { string temp=StringTrimLeft(StringTrimRight(FileReadString(handle)));
         line_read[row][col] = temp;         if (FileIsEnding(handle)) break;
         if (FileIsLineEnding(handle)) { col = 0;     row ++; }
         else  col ++; }         FileClose(handle); }
   else { if (! cpt) Alert("*** File "+filename+" not found, the last error is ", GetLastError() + " ***");
         Sleep(100);       cpt ++; } }       return(handle > 0); } */

string line_read[];
bool TXT_FILE_READ(int mode) {
   string filename="Cash_Power_Alerts" + (mode? "": "_w") + ".txt", filenam2="Cash_Power_Alerts-2.txt";
   if (FileIsExist(filenam2, FILE_COMMON)) FileDelete(filenam2, FILE_COMMON);       Sleep(100);
   FileCopy(filename, FILE_COMMON, filenam2, FILE_COMMON);        Sleep(100);       filename = filenam2;
   int row=0, handle=FileOpen(filename, FILE_TXT|FILE_READ|FILE_COMMON);
   if(handle > 0) { while(True) { string temp=FileReadString(handle);
         line_read[row] = temp;        if (FileIsEnding(handle)) break;
         row ++; }         FileClose(handle); }
   else  Print("*** (2) File "+filename+" not found, the last error is ", GetLastError() + " ***");
   return(handle > 0); }

int copy_file(string filename,string temp) { int handle, it=0;
   bool tst=false;//         filename = StringSubstr(filename, 0, StringFind(filename, ".")) + ".txt";
   while (! tst && it < 7) { handle = FileOpen (filename, FILE_TXT|FILE_WRITE|FILE_COMMON);
      if (handle != INVALID_HANDLE) { tst = FileWrite(handle, temp);
         if (! tst) Print ("Problème : FileWrite(handle, ("+it+" - "+IntegerToString(GetLastError())+") / "+Symbol()+" ***");
         FileClose(handle); }
      else Print ("Problème : handle == INVALID_HANDLE. ("+it+" - "+IntegerToString(GetLastError())+") / "+Symbol()+" ***");     it ++; }
   return(handle); }

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

bool myHour() { return(StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_MINUTES), 0, 2)) == 22 &&
      StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_MINUTES), 3, 2)) >= 40); }

string Symb_Check(string Symb) { ResetLastError();       string s_comp=AccountCompany();
   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 == "BRENT") Symb = "UKOUSD";
         break;
         case 1  :      if (Symb == "US30INDEX") Symb = "US30";      if (Symb == "BRENTCRUD") Symb = "UKOUSD";
         break;
         case 2  :
         break;
         case 3  :
         break;
         case 4  :
         break;
         default :
      if (Symb == "GOLD" || Symb == "Gold") Symb = "XAUUSD";      if (Symb == "Silver") Symb = "XAGUSD"; }

//      _p = i_comp ? "" : "p";
 return(Symb); }
