/* #import "shell32.dll"
 int ShellExecuteW(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import */
extern bool High_Risk = true;
string Symb_=" AUDNZD | GBPJPY | USDCHF | USDJPY | GBPAUD | GBPCAD | USDCAD | NZDCAD | AUDCAD | GBPUSD | UKOUSD | US30 | XAUUSD | EURUSD | GBPCHF | CADCHF | USDSGD";

int ordersTotal=0, f_mod, f_mod2, f_siz, f_siz2;         datetime t_read;        bool hr=High_Risk;

int OnInit() { EventSetTimer(10);
   int handle=FileOpen("Cash_Power_Alerts_w2.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() { double tx=0.00375;;
   if ((TimeCurrent() - t_read > 15 &&/* (! Hour() || Hour()==8 || Hour()==12 || Hour()==16) &&*/ ! (Minute() % 15) && Seconds() < 7) ||
   ! FileIsExist("Cash_Power_Alerts_w2.txt", FILE_COMMON)) {
      string URL, filename="Cash_Power_Alerts_w2.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_w2.txt\"  *******"); }              int cpt=0;

//   ts = ShellExecuteW(0,"open","C:\\Users\\Administrateur\\AppData\\Roaming\\MetaQuotes\\Terminal\\E88DA660F9A20E5DD9C622B8430BA4F1\\MQL4\\copy_file.bat",
//      "Cash_Power_Alerts-b.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_w2.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_w2.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-b.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;

         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"); } } } }

   string Symb;         bool tst1, ts3_, tst4, ts4_, tst5, ordt;           int tst6, it1=0, it2=0, ticket;        long prevChart=ChartFirst();
   if (f_mod2 > f_mod || f_siz2 > f_siz) { for (int pos=0; pos < OrdersTotal(); pos ++) if (OrderSelect(pos, SELECT_BY_POS)) { tst6 = 0;
            Symb = StringFind(OrderSymbol(), ".") > 0? StringSubstr(OrderSymbol(), 0, StringFind(OrderSymbol(), ".")):
               StringSubstr(OrderSymbol(), StringLen(OrderSymbol())-1, 1) == "p"? StringSubstr(OrderSymbol(), 0, StringLen(OrderSymbol())-1): OrderSymbol();
//            if (StringFind(OrderSymbol(), "JPY") > 0 || StringFind(OrderSymbol(), "USD") > 0 || StringFind(OrderSymbol(), "GBP") > 0) tx = 0.01;         else  tx = 0.005;
//    Cash_Power 3 / 4 ->  si positions déjà ouvertes, désactiver Forex_99_EA par template PLUS contrôler et fermer les positions ouvertes à contre tendance
//    Cash_Power 4 / 4 ->  si positions déjà ouvertes, faire précédente (CP 3/4) ET fermer la première position à contre tendance jusqu'à la position médiane
            StringToUpper(Symb);             Symb = Symb_Check(Symb);
            tst1 = (GlobalVariableCheck(Symb + "_1440_CashPower") && GlobalVariableGet(Symb + "_1440_CashPower") == 2);
            tst2 = (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 2);
            tst3 = (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 2);           ts3_ = tst3;
            tst4 = (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 2);           ts4_ = tst4;

            if (tst1) tst6 ++;      if (tst2) tst6 ++;      if (tst3) tst6 ++;      if (tst4) tst6 ++;      Sell = (tst6 > 2);      tst5 = (tst6 == 4);

            tst1 = (GlobalVariableCheck(Symb + "_1440_CashPower") && GlobalVariableGet(Symb + "_1440_CashPower") == 1);
            tst2 = (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 1);
            tst3 = (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 1);
            tst4 = (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 1);           tst6 = 0;

            if (tst1) tst6 ++;      if (tst2) tst6 ++;      if (tst3) tst6 ++;      if (tst4) tst6 ++;      Buy = (tst6 > 2);       tst5 = (tst6 == 4);

            tst = (Sell || Buy);       Symb = OrderSymbol();            ordt = OrderType();           ticket = OrderTicket();
            if (tst && ((Sell && ! Buy && ! (OrderType() % 2)) || (Buy && ! Sell && OrderType() % 2 > 0))) {
//                  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);
               if (OrderMagicNumber() == 77777) { if (((OrderType() && OrderStopLoss() < NormPrice(1.0 + tx * OrderOpenPrice(), Symb)) ||
                  (! OrderType() && OrderStopLoss() > NormPrice(1.0 - tx * OrderOpenPrice(), Symb))) && GlobalVariableCheck(Symb + "_T_Hedged") &&
                  TimeCurrent() - GlobalVariableGet(Symb + "_T_Hedged") > 20) {
                     tst = OrderModify(OrderTicket(), OrderOpenPrice(), GlobalVariableGet(Symb + "_SL_Hedged"), OrderTakeProfit(), 0, clrNONE);
                     if (tst) Alert("*** OrderModify(" + IntegerToString(OrderTicket()) + ") (h) - " + DoubleToStr(OrderStopLoss(), MarketInfo(Symb, MODE_DIGITS)) + " - " +
                           DoubleToStr(GlobalVariableGet(Symb + "_SL_Hedged")) + " ***");          GlobalVariableSet(Symb + "_T_Hedged", TimeCurrent()); }
                  else if (! GlobalVariableCheck(Symb + "_SL_Hedged")) GlobalVariableSet(Symb + "_SL_Hedged", OrderStopLoss()); }
               if (OrderType() > 1) { if (OrderType() > 3) { for (int po=0; po < OrdersTotal(); po ++) if (OrderSelect(po, SELECT_BY_POS) && Symb == OrderSymbol()) it2 ++;
                     tst = it2 > 2 || (Buy && tst3 && tst4) || (Sell && ts3_ && ts4_); }           if (tst || ordt < 4) tst = OrderDelete(ticket, clrNONE); }
               else if (OrderProfit() <= -0.015 * OrderOpenPrice() * OrderLots() / MarketInfo(Symb, MODE_POINT) * MarketInfo(Symb, MODE_TICKVALUE) &&
                  OrderClose(OrderTicket(), OrderLots(), OrderType()? MarketInfo(Symb, MODE_ASK): MarketInfo(Symb, MODE_BID), 5, clrNONE))
                     Alert("*** (1) OrderClose(" + IntegerToString(OrderTicket()) + ") - " + DoubleToStr(OrderProfit(), MarketInfo(Symb, MODE_DIGITS)) + " - " +
                        DoubleToStr(-0.015 * OrderOpenPrice() * OrderLots() / MarketInfo(Symb, MODE_POINT) * MarketInfo(Symb, MODE_TICKVALUE), MarketInfo(Symb, MODE_DIGITS)) + " ***");
               else if (hr && (! OrderStopLoss() || OrderStopLoss() == NormPrice((OrderType()? 1.02: 0.98) * OrderOpenPrice(), Symb)))
                  tst = OrderModify(OrderTicket(), OrderOpenPrice(), NormPrice((OrderType()? 1.015: 0.985) * OrderOpenPrice(), Symb), OrderTakeProfit(), 0, clrNONE);
               it2 = 0;          if (tst5) { for (po = 0; po < OrdersTotal(); po ++) if (OrderSelect(po, SELECT_BY_POS) && Symb == OrderSymbol()) it1 ++;
                  if (! it1 && GlobalVariableCheck(Symb + "_T_Closed")) GlobalVariableDel(Symb + "_T_Closed");       else  if (! GlobalVariableCheck(Symb + "_T_Closed")) {
                        for (po = 0; po < OrdersTotal(); po ++) if (OrderSelect(po, SELECT_BY_POS) && Symb == OrderSymbol()) { it2 ++;
                           if (it2 <= it1 / 2 && OrderClose(OrderTicket(), OrderLots(), OrderType()? MarketInfo(Symb, MODE_ASK): MarketInfo(Symb, MODE_BID), 5, clrNONE))
                              Alert("*** (2) OrderClose(" + IntegerToString(OrderTicket()) + ") - " + IntegerToString(it1) + " - " + IntegerToString(it2) + " ***"); }
                        GlobalVariableSet(Symb + "_T_Closed", TimeCurrent()); } }
               if (tst5 || (Buy && tst3 && tst4) || (Sell && ts3_ && ts4_)) { if (! GlobalVariableCheck(Symb + "_T_Hedged")) { it2 = 0;      ResetLastError();
                        for (po = 0; po < OrdersTotal(); po ++) if (OrderSelect(po, SELECT_BY_POS) && Symb == OrderSymbol()) it2 += OrderLots() * 100.0;
                        if (it2) { tst = OrderSend(Symb, Sell + 4, it2 > 2? 3.0 / 400.0 * it2: it2 / 100.0, Sell? MarketInfo(Symb, MODE_BID) - 22 * MarketInfo(Symb, MODE_POINT):
                              MarketInfo(Symb, MODE_ASK) + 22 * MarketInfo(Symb, MODE_POINT), 5, 0.0, 0.0, "spec. trend hedging", 77777, TimeCurrent() + 12 * 3600, clrNONE);
                           if (tst) { GlobalVariableSet(Symb + "_T_Hedged", TimeCurrent());
                              Alert("******* OrderSend() " + (tst? "OK": "Error") + "! - " + (tst? "": GetLastError() + " - ") + DoubleToStr(Sell? MarketInfo(Symb, MODE_BID) - 22 *
                                 MarketInfo(Symb, MODE_POINT): MarketInfo(Symb, MODE_ASK) + 22 * MarketInfo(Symb, MODE_POINT), MarketInfo(Symb, MODE_DIGITS)) + " *******"); } } } }
               else if (GlobalVariableCheck(Symb + "_T_Hedged")) {
                  for (po = 0; po < OrdersTotal(); po ++) if (OrderSelect(po, SELECT_BY_POS) && Symb == OrderSymbol() && OrderComment() == "spec. trend hedging")
                     if (OrderType() < 2 && OrderClose(OrderTicket(), OrderLots(), OrderType()? MarketInfo(Symb, MODE_ASK): MarketInfo(Symb, MODE_BID), 5, clrNONE))
                        Alert("*** (3) OrderClose(" + IntegerToString(OrderTicket()) + ") - spec. trend hedging ***");
                     else  tst = OrderDelete(OrderTicket(), clrNONE);                     GlobalVariableDel(Symb + "_T_Hedged"); }
/*               tst = false;           it2 = 0;           while(! tst && it2 < 50) { it1 = 0;
                  while((ChartSymbol(prevChart) != Symb || ChartPeriod(prevChart) > PERIOD_M5) && it1 < 50) { prevChart = ChartNext(prevChart);    Sleep(100);    it1 ++; }
                  if (ChartSymbol(prevChart) == Symb) { tst = true;        ChartApplyTemplate(prevChart, "template_name.tpl");      Sleep(100); }        it2 ++; }
               if (ChartSymbol(prevChart) != Symb) Alert("******* LE CHART N'A PAS ÉTÉ TROUVÉ ! (1) - " + Symb + " *******"); */ }
            else if (hr && (! OrderStopLoss() || OrderStopLoss() == NormPrice((OrderType()? 1.015: 0.985) * OrderOpenPrice(), Symb)))
               tst = OrderModify(OrderTicket(), OrderOpenPrice(), NormPrice((OrderType()? 1.02: 0.98) * OrderOpenPrice(), Symb), OrderTakeProfit(), 0, clrNONE); }

/*      for (int smb=0; smb < SymbolsTotal(false); smb ++) { Symb = SymbolName(smb, false);          tst6 = 0;
            tst1 = (GlobalVariableCheck(Symb + "_1440_CashPower") && GlobalVariableGet(Symb + "_1440_CashPower") == 2);
            tst2 = (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 2);
            tst3 = (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 2);
            tst4 = (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 2);

            if (tst1) tst6 ++;      if (tst2) tst6 ++;      if (tst3) tst6 ++;      if (tst4) tst6 ++;      tst = (tst6 > 2);

            tst1 = (GlobalVariableCheck(Symb + "_1440_CashPower") && GlobalVariableGet(Symb + "_1440_CashPower") == 1);
            tst2 = (GlobalVariableCheck(Symb + "_240_CashPower") && GlobalVariableGet(Symb + "_240_CashPower") == 1);
            tst3 = (GlobalVariableCheck(Symb + "_60_CashPower") && GlobalVariableGet(Symb + "_60_CashPower") == 1);
            tst4 = (GlobalVariableCheck(Symb + "_30_CashPower") && GlobalVariableGet(Symb + "_30_CashPower") == 1);        tst6 = 0;

            if (tst1) tst6 ++;      if (tst2) tst6 ++;      if (tst3) tst6 ++;      if (tst4) tst6 ++;      tst = (tst? tst: tst6 > 2);

            if (! tst) { it2 = 0;           while(! tst && it2 < 50) { it1 = 0;
                  while((ChartSymbol(prevChart) != Symb || ChartPeriod(prevChart) > PERIOD_M5) && it1 < 50) { prevChart = ChartNext(prevChart);    Sleep(100);    it1 ++; }
                  if (ChartSymbol(prevChart) == Symb) { tst = true;        ChartApplyTemplate(prevChart, "Forex99 EA.tpl");         Sleep(100); }        it2 ++; }
               if (ChartSymbol(prevChart) != Symb) Alert("******* LE CHART N'A PAS ÉTÉ TROUVÉ ! (2) - " + Symb + " *******"); } } */ }

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

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

void OnTimer() {// f_mod2 = TimeCurrent();
   int handle=FileOpen("Cash_Power_Alerts_w2.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-b.txt", filenam2="Cash_Power_Alerts-2b.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);
         if (cpt) Alert("*** File "+filename+" found, OK! (", IntegerToString(cpt) + ") ***"); }
      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? "-b": "_w2") + ".txt", filenam2="Cash_Power_Alerts-b2b.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)) == 23 &&
      StrToInteger(StringSubstr(TimeToStr(TimeLocal(), TIME_MINUTES), 3, 2)) >= 30); }

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); }
