enum options_signaux {Harmonic_Scanner=0, Harm_Scan_ATS=1, Harm_Scan_Cash_Power=2, Cash_Power_ATS=3};
extern options_signaux Option_Signaux = Cash_Power_ATS;

double ExtOpenBuffer[], ExtCloseBuffer[]/*, ExtLowHighBuffer[], ExtHighLowBuffer[]*/, haOpen, haClose, haHigh, haLow, Exp_Ind[100][21];
bool Buy, Sell, t_Rsi515=false, t_Adx=false, t_Send=false, t_exp, t_exp2, t_exp3, t_exp4, t_box, t_box2, t_box3=false, t_CPClose=false, t_CPClos2=false,
   t_BH=false, t_BH2=false, t_P60=false, t_P60b=false;
int option=Option_Signaux, nBars=500, ticket=0, t_cpt, ticket_;      string namBox;
datetime CP_tims[6], tim_exp, tim_ex2, tim_box, t_BxClo=0;       //s[50][2];

int OnInit() {// EventSetTimer(60);
//   ChartSetSymbolPeriod(0, SymbolName(pos, false), 0);         pos ++;
//   FileMove("New_Symbol_OK_off.txt", FILE_COMMON, "New_Symbol_OK_on.txt", FILE_COMMON);

   ArrayResize(ExtOpenBuffer, nBars);     ArrayResize(ExtCloseBuffer, nBars);       HA_Buffers();
   Exp_Inds();          return(INIT_SUCCEEDED); }

void OnTick() { if (! (TimeCurrent() % 60)) {/*
  }

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

void OnTimer() {*/ bool tst=false;       datetime CP_tim;
/*   for (int obj=0; obj < ObjectsTotal(); obj ++) { string name=ObjectName(obj);
      if (StringFind(name, "BCD") > 0 && ObjectType(name) == OBJ_TRIANGLE && pos)
         if (ObjectGet(name, OBJPROP_TIME3) > Time[10] && ObjectGet(name, OBJPROP_TIME3) - ObjectGet(name, OBJPROP_TIME1) > 15 * Period() * 60) {
            for (int ob=0; ob < ObjectsTotal() && ! tst; ob ++) { string name2=ObjectName(ob);
               tst = ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) > ObjectGet(name, OBJPROP_TIME3); }         if (! tst) {
Alert("**1* TRIANGLE - " + ChartSymbol() + " - " + SymbolName(pos - 1, false) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME3), TIME_MINUTES) + " ***");   break; }
Alert("******* FIN - " + ChartSymbol() + " - " + SymbolName(pos-1, false) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME3), TIME_MINUTES) + " *******");
            GlobalVariableSet("Current_Symbol", pos - (alt? 0: 1));        ExpertRemove();         EventKillTimer();      return; }            else
Alert("**2* TRIANGLE - " + ChartSymbol() + " - " + SymbolName(pos - 1, false) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME3), TIME_MINUTES) + " ***"); } */

   if (option > 1) { CP_tim = Get_Cash_Power(0);      CP_tims[5] = CP_tim;//         int k=0;             ArrayInitialize(CP_tims, 0);
//   ObjectsDelete(0, "EA_vert-");       ObjectsDelete(0, "EA_X-Line_");        ObjectsDelete(0, "EA_Chck2-");
      if (((CP_tim == Time[1] && ((Sell && iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 0, 1) > 0.0) ||
      (Buy && iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 1, 1) > 0.0))) || (CP_tims[0] != CP_tim && CP_tims[3] < Time[0])) && OrderSelect(ticket, SELECT_BY_TICKET) &&
      ((OrderType() && Buy) || (! OrderType() && Sell)) && ! OrderCloseTime() && OrderClose(ticket, OrderLots(), Sell? Bid: Ask, 5, clrNONE)) { ticket_ = ticket;
         ticket = 0;       CP_tim = 0;       if (t_CPClose) { t_CPClos2 = true;        Order_Send(Time[0], Sell); }        t_BH2 = false;      t_P60 = false;    t_P60b = false;
Alert("*** CashPower Close - " + TimeToStr(CP_tims[0], TIME_DATE|TIME_MINUTES) + " ***"); }
      if ((CP_tims[0] && CP_tim && CP_tims[0] != CP_tim) || t_exp) Exp_Inds();

      if (ticket && OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime()/* && ! t_box3 && ! t_CPClos2*/) { if (Period() >= 240) { bool tst2;
            for (int obj=0; obj < ObjectsTotal() && ! tst && ! tst2; obj ++) { string name=ObjectName(obj);
               tst2 = ((Sell && (name == "RSLinesS1" || name == "RSLinesS2" || name == "RSLinesS3")) ||
                  (Buy && (name == "RSLinesR1" || name == "RSLinesR2" || name == "RSLinesR3"))) &&
                  ((Sell && ObjectGet(name, OBJPROP_PRICE1) > OrderTakeProfit() && ObjectGet(name, OBJPROP_PRICE1) < OrderOpenPrice()) ||
                  (Buy && ObjectGet(name, OBJPROP_PRICE1) < OrderTakeProfit() && ObjectGet(name, OBJPROP_PRICE1) > OrderOpenPrice())) &&
                  fabs(ObjectGet(name, OBJPROP_PRICE1) - OrderOpenPrice()) < fabs((Sell? iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim) + 1):
                  iLow(NULL, 0, iBarShift(NULL, 0, CP_tim) + 1)) - OrderOpenPrice()) && ObjectGet(name, OBJPROP_TIME2) > Time[1];
               tst = (tst2 || (Sell && name == "RSLinesS1") || (Buy && name == "RSLinesR1")) && ObjectType(name) == OBJ_TREND;
               if (tst) { tst = ((iBarShift(NULL, 0, CP_tims[0]) > 7 && ObjectGet(name, OBJPROP_TIME1) - CP_tims[0] > 7 * Period() * 60 &&
                     CP_tims[0] && ! CP_tims[4]) || (iBarShift(NULL, 0, CP_tims[4]) > 7 && ObjectGet(name, OBJPROP_TIME1) - CP_tims[4] >
                     7 * Period() * 60 && CP_tims[4])) && ObjectGet(name, OBJPROP_TIME2) - ObjectGet(name, OBJPROP_TIME1) > 5 * Period() * 60
                     && ! t_box3 && ! t_CPClos2;
                  if (! tst) { for (int ob=0; ob < ObjectsTotal() && ! tst; ob ++) { string name2=ObjectName(ob);
                        tst = (StringFind(name2, "BoxLine") > 0 && ObjectGet(name2, OBJPROP_TIME2) == Time[1] &&
                           ObjectGet(name2, OBJPROP_TIME2) - ObjectGet(name2, OBJPROP_TIME1) > 2 * Period() * 60 &&
                           ObjectGet(name, OBJPROP_TIME1) < ObjectGet(name2, OBJPROP_TIME1)) && (tst2 ||
                           ObjectGet(name2, OBJPROP_TIME1) - ObjectGet(name, OBJPROP_TIME1) < 5 * Period() * 60); }
                     if (tst) { t_BxClo = Time[0];       tst = false;      name = name2;
                        for (ob = 0; ob < ObjectsTotal() && ! tst; ob ++) { name2 = ObjectName(ob);
                           tst = StringFind(name2, "rect") > 0 && ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) ==
                              ObjectGet(name, OBJPROP_TIME2) && StringSubstr(name, StringFind(name, "BoxLine") + 7, 16) ==
                              StringSubstr(name2, StringFind(name2, "rect") + 4, 16); }
                        double SL=(Sell? ObjectGet(name2, OBJPROP_PRICE1): ObjectGet(name2, OBJPROP_PRICE2)) + (Sell? 1.0: -1.0) * 22 * Point(); } } }
               tst2 = ((Sell && StringFind(name, "liquid_buy") > 0) || (Buy && StringFind(name, "liquid_sell") > 0)) &&
                  ObjectType(name) == OBJ_TREND && ((ObjectGet(name, OBJPROP_TIME1) > CP_tims[0] && CP_tims[0] && ! CP_tims[4]) ||
                  (ObjectGet(name, OBJPROP_TIME1) > CP_tims[4] && CP_tims[4])) && ! t_box3 && ! t_CPClos2;              if (tst || tst2) {
               if (t_BxClo && SL && ((Sell && SL > Ask) || (Buy && SL < Bid)) && OrderModify(ticket, OrderOpenPrice(), SL, OrderTakeProfit(), 0, clrNONE))
Alert("*** " + (tst? "RSLinesRS1": "liquid_line") + " Modify(1) - " + name + " - " + DoubleToStr(ObjectGet(name, OBJPROP_PRICE1), Digits()) + " - " +
   TimeToStr(CP_tims[0], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tims[4], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " ***");
               if (! (t_BxClo && SL && ((Sell && SL > Ask) || (Buy && SL < Bid))) && OrderClose(ticket, OrderLots(), Sell? Ask: Bid, 5, clrNONE)) { ticket_ = ticket;      ticket = 0;    CP_tim = 0;
Alert("*** " + (tst? "RSLinesRS1": "liquid_line") + " Close - " + name + " - " + DoubleToStr(ObjectGet(name, OBJPROP_PRICE1), Digits()) + " - " +/* ObjectGet(name, OBJPROP_COLOR) + " - " +*/
   TimeToStr(CP_tims[0], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tims[4], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " ***"); } } }
            tst = false;      for (obj = 0; obj < ObjectsTotal() && ! tst && ! t_box3 && ! t_CPClos2; obj ++) { name = ObjectName(obj);
               tst = ((Buy && (name == "RSLinesS1" || StringFind(name, "liquid_buy") > 0)) || (Sell &&
                  (name == "RSLinesR1" || StringFind(name, "liquid_sell") > 0))) && ObjectType(name) == OBJ_TREND &&
                  ObjectGet(name, OBJPROP_TIME1) > CP_tims[0] && CP_tims[4]; }               if (tst)
               if (OrderModify(ticket, OrderOpenPrice(), ObjectGet(name, OBJPROP_PRICE1) + (Sell? 1.0: -1.0) * 22 * Point(), OrderTakeProfit(), 0, clrNONE))
Alert("*** " + (tst? "RSLinesRS1": "liquid_line") + " Modify(2) - " + name + " - " + DoubleToStr(ObjectGet(name, OBJPROP_PRICE1), Digits()) + " - " + t_box2 + " - " +
   TimeToStr(CP_tims[0], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tims[4], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " ***"); }
         else { double TS=MarketInfo(Symbol(), MODE_TICKSIZE), TV=MarketInfo(Symbol(), MODE_TICKVALUE), SL2;               t_P60 = true;
            if (t_BH && OrderProfit() > fabs(OrderTakeProfit() - OrderOpenPrice()) / TS * TV * 0.0005) { SL2 = NormPrice(OrderOpenPrice(), Symbol());
               if (((Sell && OrderStopLoss() > SL2) || (Buy && OrderStopLoss() < SL2)) && OrderModify(ticket, OrderOpenPrice(), SL2, OrderTakeProfit(), 0, clrNONE)) { t_BH2 = true;
Alert("*** OrderModify(1) - " + Buy + " - " + Sell + " - " + DoubleToStr(SL2, Digits()) + " - " + DoubleToStr(OrderStopLoss(), Digits()) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " ***"); } }
            if (OrderProfit() > fabs(OrderTakeProfit() - OrderOpenPrice()) / TS * TV * 0.004 && f_wBars(OrderOpenTime(), TimeCurrent()) > 48 * 60 / Period()) {
               SL2 = NormPrice(OrderOpenPrice() + (OrderTakeProfit() - OrderOpenPrice()) * 0.25, Symbol());
               if (((Sell && OrderStopLoss() > SL2) || (Buy && OrderStopLoss() < SL2)) && OrderModify(ticket, OrderOpenPrice(), SL2, OrderTakeProfit(), 0, clrNONE)) { t_BH2 = true;
Alert("*** OrderModify(2) - " + Buy + " - " + Sell + " - " + DoubleToStr(SL2, Digits()) + " - " + DoubleToStr(OrderStopLoss(), Digits()) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " ***"); } }
            if (OrderProfit() > fabs(OrderTakeProfit() - OrderOpenPrice()) / TS * TV * 0.007) { SL2 = NormPrice(OrderOpenPrice() + (OrderTakeProfit() - OrderOpenPrice()) * 0.5, Symbol());
               if (((Sell && OrderStopLoss() > SL2) || (Buy && OrderStopLoss() < SL2)) && OrderModify(ticket, OrderOpenPrice(), SL2, OrderTakeProfit(), 0, clrNONE)) { t_BH2 = true;
Alert("*** OrderModify(3) - " + Buy + " - " + Sell + " - " + DoubleToStr(SL2, Digits()) + " - " + DoubleToStr(OrderStopLoss(), Digits()) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " ***"); } }
            if (OrderProfit() > fabs(OrderTakeProfit() - OrderOpenPrice()) / TS * TV * 0.009) { SL2 = NormPrice(OrderOpenPrice() + (OrderTakeProfit() - OrderOpenPrice()) * 0.75, Symbol());
               if (((Sell && OrderStopLoss() > SL2) || (Buy && OrderStopLoss() < SL2)) && OrderModify(ticket, OrderOpenPrice(), SL2, OrderTakeProfit(), 0, clrNONE)) { t_BH2 = true;
Alert("*** OrderModify(4) - " + Buy + " - " + Sell + " - " + DoubleToStr(SL2, Digits()) + " - " + DoubleToStr(OrderStopLoss(), Digits()) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " ***"); } }
            t_BH = (t_BH? t_BH: (t_BH2=(OrderProfit() < -1.0 * fabs(OrderStopLoss() - OrderOpenPrice())/TS*TV * 0.0025 && f_wBars(OrderOpenTime(), TimeCurrent()) > 24 * 60/Period()))); } }
      else  t_BH = false; }
//if (Day() == 5 && Month() == 5 && Hour() == 7) f_End_EA();

   tst = false;      if (! t_box && ! t_box2) for (obj = 0; obj < ObjectsTotal() && ! tst; obj ++) { name = ObjectName(obj);
      if (StringFind(name, "BoxLine") > 0 && ObjectGet(name, OBJPROP_TIME2) == Time[1] && ((Sell &&
      ObjectGet(name, OBJPROP_PRICE1) < iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim))) || (Buy && ObjectGet(name, OBJPROP_PRICE1) >
      iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)))) && ObjectGet(name, OBJPROP_TIME1) - CP_tims[0] > 7 * Period() * 60 && CP_tims[0]) {
         for (ob = 0; ob < ObjectsTotal() && ! tst; ob ++) { name2 = ObjectName(ob);
            tst = StringFind(name2, "rect") > 0 && ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) ==
               ObjectGet(name, OBJPROP_TIME2) && StringSubstr(name, StringFind(name, "BoxLine") + 7, 16) ==
               StringSubstr(name2, StringFind(name2, "rect") + 4, 16); }            if (tst) { t_box2 = (ObjectGet(name2, OBJPROP_COLOR) != 5789784);          tim_box = TimeCurrent();
Alert("*** t_box - " + name + " - " + ChartSymbol() + " - " + Symbol() + " - " + name2 + " - " + TimeToStr(CP_tims[0], TIME_DATE|TIME_MINUTES) + " - " + t_box2 + " - " + ObjectGet(name2, OBJPROP_COLOR) + " ***");
             } } }

   t_box3 = (t_box2 && TimeCurrent() - tim_box > (7 + (DayOfWeek() < TimeDayOfWeek(tim_box)? 48 * 60 / Period(): 0)) * Period() * 60);
   if (ticket && OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime() && t_box3 &&
   TimeCurrent() - OrderOpenTime() > (7 + (DayOfWeek() < TimeDayOfWeek(tim_box)? 48 * 60 / Period(): 0)) * Period() * 60 &&
   TimeCurrent() - tim_box > (7 + (DayOfWeek() < TimeDayOfWeek(tim_box)? 48 * 60 / Period(): 0)) * Period() * 60) { t_box2 = false;    t_box3 = false; }
   if (ticket && OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime() && t_CPClos2 && TimeCurrent() - OrderOpenTime() >
   (7 + (DayOfWeek() < TimeDayOfWeek(tim_box)? 48 * 60 / Period(): 0)) * Period() * 60) { t_CPClose = false;      t_CPClos2 = false; }
   if (ticket < 0 || (! OrdersTotal() && ticket)) { ticket_ = ticket;      ticket = 0;      CP_tim = 0; }
   double atr_m1=500000.0, atr_m2=0.0;       for (int bar=0; bar < 500; bar ++)
      if (iCustom(NULL, 0, "ATR.ex4", 14, 0, bar) < atr_m1) atr_m1 = iCustom(NULL, 0, "ATR.ex4", 14, 0, bar);
      else if (iCustom(NULL, 0, "ATR.ex4", 14, 0, bar) > atr_m2) atr_m2 = iCustom(NULL, 0, "ATR.ex4", 14, 0, bar);
   if (option == 1 || option == 3) { t_Adx = (iCustom(NULL, 0, "New folder\\ADX.ex4", 7, 0, iBarShift(NULL, 0, CP_tim)) > 25.0 ||
            iCustom(NULL, 0, "New folder\\ADX.ex4", 14, 0, iBarShift(NULL, 0, CP_tim)) > 25.0) &&
            iCustom(NULL, 0, "ATR.ex4", 14, 0, iBarShift(NULL, 0, CP_tim)) > 1.0 / 3.0 * (atr_m1 + atr_m2) / 2.0;
         t_Rsi515 = m3_RSI(0, iBarShift(NULL, 0, CP_tim), 2) > 31 && m3_RSI(0, iBarShift(NULL, 0, CP_tim), 2) < 69;
         t_P60b = t_BH2 || t_P60;         for (obj = 0; obj < ObjectsTotal(); obj ++) { name = ObjectName(obj);
            if ((StringFind(name, "liquid_") > 0 || StringFind(name, "BoxLine") > 0) && ObjectType(name) == OBJ_TREND/* && (! t_Rsi515 || t_Adx)*/)      // && pos
/* if (StringFind(name, "BoxLine") > 0 && t_box && ! ticket && ObjectGet(name, OBJPROP_TIME1) > CP_tims[0])
Alert("**0* CP - " + name + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tims[0], TIME_DATE|TIME_MINUTES) + " - " +
   DoubleToStr(ObjectGet(name, OBJPROP_PRICE1), Digits()) + " - " + TimeToStr(ObjectGet(name, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " - " +
   TimeToStr(ObjectGet(name, OBJPROP_TIME2), TIME_DATE|TIME_MINUTES) + " - " + t_box + " - " + t_box2 + " - " + t_box3 + " - " + ticket_ + " - " + ticket + " - " +
   OrderSelect(ticket_, SELECT_BY_TICKET) + " - " + TimeToStr(OrderCloseTime(), TIME_DATE|TIME_MINUTES) + " ***"); */
               if (option == 3 && ((fabs(ObjectGet(name, OBJPROP_TIME1) - CP_tim) < 15 * Period() * 60 && CP_tims[2] != CP_tim) || (StringFind(name, "BoxLine") > 0 &&
               (ObjectGet(name, OBJPROP_TIME1) - CP_tim < 50 * Period() * 60 || t_box || t_box3 || t_P60b))) && ((Buy && StringFind(name, "liquid_buy") > 0) ||      // && (! t_Rsi515 || t_Adx)
               (Sell && StringFind(name, "liquid_sell") > 0) || (tst=((Period() >= 240 || t_P60b) && StringFind(name, "BoxLine") > 0 && (CP_tim - ObjectGet(name, OBJPROP_TIME2) < 3 * Period() * 60 ||
               (! t_P60b && (t_box || t_box3) && ! ticket && ObjectGet(name, OBJPROP_TIME1) > CP_tims[0])))))) { if (StringFind(name, "BoxLine") < 0 && t_box && ! ticket) t_box = false;
                  tst = false;     if (t_P60b && (t_BH2 || ! ticket_ || (OrderSelect(ticket_, SELECT_BY_TICKET) && ((Sell && ObjectGet(name, OBJPROP_PRICE1) > OrderClosePrice()) ||
                  (Buy && ObjectGet(name, OBJPROP_PRICE1) < OrderClosePrice()))/* && TimeCurrent() - OrderCloseTime() < 15 * Period() * 60*/))) {
                     for (ob = 0; ob < ObjectsTotal() && ! tst; ob ++) { name2 = ObjectName(ob);
                        tst = StringFind(name2, "rect") > 0 && ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) ==
                           ObjectGet(name, OBJPROP_TIME2) && StringSubstr(name, StringFind(name, "BoxLine") + 7, 16) ==
                           StringSubstr(name2, StringFind(name2, "rect") + 4, 16); }      namBox = name2;         t_P60b = tst; }         // && ObjectGet(name2, OBJPROP_COLOR) != 5789784);
                  t_P60b = tst && (ObjectGet(name, OBJPROP_TIME2) == Time[1] || (ticket_ && OrderSelect(ticket_, SELECT_BY_TICKET) && OrderCloseTime() > CP_tims[5]));
                  if ((t_Send=(ObjectGet(name, OBJPROP_TIME1) == Time[1] || (tst && ObjectGet(name, OBJPROP_TIME1) < Time[0] && ObjectGet(name, OBJPROP_TIME2)
                  == Time[1]) || (CP_tim == Time[1] && ((Sell && iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 0, 1) > 0.0) ||
                  (Buy && iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 1, 1) > 0.0))))) &&
                  (Period() >= 240 || t_P60b || ! ticket_ || (OrderSelect(ticket_, SELECT_BY_TICKET) && OrderCloseTime() && TimeCurrent() - OrderCloseTime() > 3 * Period() * 60))) {
                     CreateVLine(t_box && ! ticket && ObjectGet(name, OBJPROP_TIME1) > CP_tims[0]? ObjectGet(name, OBJPROP_TIME2): CP_tim, Period(), Buy);        Order_Send(CP_tim, Sell);
if (CP_tims[2] != CP_tim || t_box || t_box2) { CP_tims[2] = CP_tim;
Alert("*** CP - " + name + " - " + ChartSymbol() + " - " + Symbol() + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " - " + tst + " - " + t_box + " - " + t_box2 + " - " + t_box3 + " - " +
   DoubleToStr(m3_RSI(0, iBarShift(NULL, 0, CP_tim), 2), 2) + " - " + DoubleToStr(iCustom(NULL, 0, "New folder\\ADX.ex4", 7, 0, iBarShift(NULL, 0, CP_tim)), 2) + " - " +
   DoubleToStr(iCustom(NULL, 0, "New folder\\ADX.ex4", 14, 0, iBarShift(NULL, 0, CP_tim)), 2) + " - " + DoubleToStr(iCustom(NULL, 0, "ATR.ex4", 14, 0, iBarShift(NULL, 0, CP_tim)), Digits()) + " ***"); } }
             } } }
//      double TV=MarketInfo(Symbol(), MODE_TICKVALUE), TS=MarketInfo(Symbol(), MODE_TICKSIZE);            TV = TV < 0.1? 1.0: TV;
 }       t_exp = (tim_exp != Time[0]);

if (OrderSelect(0, SELECT_BY_POS, MODE_HISTORY) && OrderProfit() < -0.5 && OrderSelect(1, SELECT_BY_POS, MODE_HISTORY) && OrderProfit() < -0.5) f_End_EA(); }

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

int f_wBars(datetime Tim1,datetime Tim2) { int wbars=0;
   if (DayOfWeek() < TimeDayOfWeek(Tim1)) wbars = 60 * 48 / Period();
   if (floor(Tim2/(60*Period())) - floor(Tim1/(60*Period())) > 60 * 168 / Period())
      wbars = 2 * 60 * 48 / Period();
   return(floor(Tim2/(60*Period())) - floor(Tim1/(60*Period())) - wbars); }

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) { if (! FileIsExist(filename, FILE_COMMON)) handle = FileOpen (filename, FILE_TXT|FILE_WRITE|FILE_COMMON);
      else  handle = FileOpen (filename, FILE_TXT|FILE_READ|FILE_WRITE|FILE_COMMON);
      if (handle != INVALID_HANDLE) { if (FileSize(handle)) FileSeek(handle, FileSize(handle), 0);
         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); }

datetime Get_Cash_Power(int mode) { bool Buy_=Buy, Sel_=Sell, tst=false;      datetime secs=TimeCurrent();      int j=0, k=0;
   Buy = false;   Sell = false;     for (int bar=0; bar < 200 && (! tst || mode); bar ++) { Comment("* bar = " + IntegerToString(bar) + " *");
      if (tst=((Sell=(iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 0, bar) > 0.0)) ||
      (Buy=(iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 1, bar) > 0.0)))) {// CreateVLine(Time[bar], Period(), Buy);
if (CP_tims[1] != Time[bar]) {
Alert("*** Manual Trade Cashpower Lifetime -> " + Symbol() + " - " + (Buy? "Buy": "Sell") + " - " + IntegerToString(bar) + " - " + TimeToStr(Time[bar], TIME_DATE|TIME_MINUTES) + "! ***");
/*         if (mode) { CP_tims[k][0] = Time[bar];       CP_tims[k][1] = Sell;         j = k;         k ++; }*/       if (bar < 3) CP_tims[3] = Time[bar]; } }
      Sleep(50);        if (bar > 10 && (TimeCurrent() - secs) / bar >= 3.0) break; }           if (bar == 1 || (! tst && ! mode)) { Buy = Buy_;         Sell = Sel_; }
/*   if (tst || (mode && CP_tims[j][0])) Comment("* bar = " + IntegerToString(bar) + " / wa=" + ((mode && j) || bar? "a+": "w") + "&sb=" + Symbol() + "&tf=" + IntegerToString(Period()) +
         "&tp=" + (Buy? "Buy": "Sell") + "&stm=" + TimeToStr(mode? CP_tims[j][0]: Time[bar], TIME_DATE|TIME_MINUTES) + "&tim=" + IntegerToString(Time[bar]) + " *");
   else  Comment("*** Rien trouvé ! ***");*/         return(mode? 0: tst? (CP_tims[1]=Time[bar-1]): 0); }

void CreateVLine(datetime Ltim,int Per,bool Buy2) {
   ObjectCreate(0, "EA_vert-" + IntegerToString(Ltim), OBJ_VLINE, 0, Ltim > 0? Ltim: Time[0], 0);
   ObjectSetInteger(0, "EA_vert-" + IntegerToString(Ltim), OBJPROP_COLOR, Buy2? clrGreen: clrPurple);
   ObjectSetInteger(0, "EA_vert-" + IntegerToString(Ltim), OBJPROP_STYLE, STYLE_DOT);
   ObjectSetInteger(0, "EA_vert-" + IntegerToString(Ltim), OBJPROP_WIDTH, Per==PERIOD_M5? 1: 2); }

bool CreateHLine(double price,bool Buy2,datetime tim) { ResetLastError();
   string LineName="EA_X-Line_" + (Buy2? "Buy": "Sell") + "_" + DoubleToStr(price, Digits()) + "_" + IntegerToString(tim);
   if (! ObjectCreate(0, LineName, OBJ_TREND, 0, tim, price, tim + (5+(DayOfWeek()<TimeDayOfWeek(tim_box)? 48*60/Period(): 0))*Period()*60, price) &&
   GetLastError() == 4200) return(false);
//Print(__FUNCTION__, ": failed to create a Line! Error code = ", GetLastError());
   ObjectSetInteger(0, LineName, OBJPROP_RAY_RIGHT, false);
   ObjectSetInteger(0, LineName, OBJPROP_COLOR, Buy2? clrGreen: clrPurple);
   ObjectSetInteger(0, LineName, OBJPROP_STYLE, STYLE_DOT);
   ObjectSetInteger(0, LineName, OBJPROP_WIDTH, 7);
   ObjectSetInteger(0, LineName, OBJPROP_FILL, false);
   ObjectSetInteger(0, LineName, OBJPROP_BACK, false);
//   ObjectSetInteger(0, LineName, OBJPROP_HIDDEN, true);
   ObjectSetInteger(0, LineName, OBJPROP_ZORDER, 0);
   LineName = "EA_X-Line_" + (Buy2? "Buy": "Sell") + "2_" + IntegerToString(tim);
   if (! ObjectCreate(0, LineName, OBJ_TREND, 0, tim, price, tim + (5+(DayOfWeek()<TimeDayOfWeek(tim_box)? 48*60/Period(): 0))*Period()*60, price))
Print(__FUNCTION__, ": failed to create a Line! Error code = ", GetLastError());
   ObjectSetInteger(0, LineName, OBJPROP_RAY_RIGHT, false);
   ObjectSetInteger(0, LineName, OBJPROP_COLOR, Buy2? clrYellowGreen: clrLightPink);
   ObjectSetInteger(0, LineName, OBJPROP_STYLE, STYLE_DOT);
   ObjectSetInteger(0, LineName, OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, LineName, OBJPROP_FILL, false);
   ObjectSetInteger(0, LineName, OBJPROP_BACK, false);
//   ObjectSetInteger(0, LineName, OBJPROP_HIDDEN, true);
   ObjectSetInteger(0, LineName, OBJPROP_ZORDER, 0);
   return(true); }

void ObjectsDelete(int P, string str) {
   int obj_total=ObjectsTotal(), i=0, j=0;      string name;
   for (int obj=0; obj < obj_total; obj ++) { name = ObjectName(obj);
     if (obj && ((str!="" && StringSubstr(name, 0, StringLen(str)) == str) || (str=="" && (StringSubstr(name,0,8) == "EA_Test_" ||
         StringSubstr(name,0,9) == "H-A_Test_")))) {      // StringSubstr(name,0,6) == "EA_pf_" || <- option en plus à cause de op_case0 **
         j ++;    if (ObjectDelete(name)) { i ++;  obj --; } } }
   if (P) Print (obj, " objects, DELETED: ", i, " / ", j, " / ", obj_total);
   return; }

double t_res=0.0;       int _k=-1;
void Order_Send(datetime CP_tim,bool Sel2) { double SL, TP, SpTr, min2=500000.0;       int min=5000000;        string x_obj, x_obj2="";
   if (t_box || t_box3 || t_CPClos2 || Period() <= 60) { if (! ticket) { if (Period() >= 240 && OrderSelect(ticket_, SELECT_BY_TICKET)) {
         bool tst=false;      for (int obj=0; obj < ObjectsTotal() && ! tst; obj ++) { string name=ObjectName(obj);
            tst = ((Sell && (name == "RSLinesS1" || StringFind(name, "liquid_buy") > 0)) || (Buy &&
               (name == "RSLinesR1" || StringFind(name, "liquid_sell") > 0))) && ObjectType(name) == OBJ_TREND &&
               ObjectGet(name, OBJPROP_TIME1) > CP_tims[0] && CP_tims[0]; }
            if (tst) SL = ObjectGet(name, OBJPROP_PRICE1) + (Sel2? 1.0: -1.0) * 22 * Point();

            if ((Sel2 && Bid < TP) || (! Sel2 && Ask > TP)) TP = (Sel2? Bid: Ask) + OrderTakeProfit() - OrderOpenPrice();
            if ((Sel2 && Ask > SL) || (! Sel2 && Bid < SL)) SL = (Sel2? Ask: Bid) + OrderStopLoss() - OrderOpenPrice(); }

         if (Period() >= 240 && (t_box3 || t_CPClos2)) { SL = (Sel2? Bid: Ask) * (Sel2? 1.01: 0.99) + (Sel2? 1.0: -1.0) * 22 * Point();
            TP = (Sel2? Bid: Ask) * (Sel2? 0.985: 1.015) - (Sel2? 1.0: -1.0) * 22 * Point();/*     t_box2 = false;*/ }
         double dtmp=Exp_Ind[0][20] == Time[0] || Exp_Ind[0][20] == Time[1]? Sel2? (Exp_Ind[1][6] + Exp_Ind[1][9]) * 5.0 /
            (Exp_Ind[2][6]+Exp_Ind[2][9]+Exp_Ind[3][6]+Exp_Ind[3][9]+Exp_Ind[4][6]+Exp_Ind[4][9]+Exp_Ind[5][6]+Exp_Ind[5][9]+Exp_Ind[6][6]+Exp_Ind[6][9]):
            (Exp_Ind[1][5] + Exp_Ind[1][8]) * 5.0 /
            (Exp_Ind[2][5]+Exp_Ind[2][8]+Exp_Ind[3][5]+Exp_Ind[3][8]+Exp_Ind[4][5]+Exp_Ind[4][8]+Exp_Ind[5][5]+Exp_Ind[5][8]+Exp_Ind[6][5]+Exp_Ind[6][8]):
            Sel2? (Exp_Ind[0][6] + Exp_Ind[0][9]) * 5.0 /
            (Exp_Ind[1][6]+Exp_Ind[1][9]+Exp_Ind[2][6]+Exp_Ind[2][9]+Exp_Ind[3][6]+Exp_Ind[3][9]+Exp_Ind[4][6]+Exp_Ind[4][9]+Exp_Ind[5][6]+Exp_Ind[5][9]):
            (Exp_Ind[0][5] + Exp_Ind[0][8]) * 5.0 /
            (Exp_Ind[1][5]+Exp_Ind[1][8]+Exp_Ind[2][5]+Exp_Ind[2][8]+Exp_Ind[3][5]+Exp_Ind[3][8]+Exp_Ind[4][5]+Exp_Ind[4][8]+Exp_Ind[5][5]+Exp_Ind[5][8]);
Alert("*** Exp_Ind - " + (Exp_Ind[0][5]+Exp_Ind[0][8]) + " - " + (Exp_Ind[0][6]+Exp_Ind[0][9]) + " - " + (Exp_Ind[1][5]+Exp_Ind[1][8]) + " - " + (Exp_Ind[1][6]+Exp_Ind[1][9]) + " - " +
   DoubleToStr(dtmp, 2) + " - " + Sel2 + " - " + TimeToStr(Exp_Ind[0][20], TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(Time[0], TIME_DATE|TIME_MINUTES) + " ***");
         if (Period() >= 240 && (! t_BxClo || TimeCurrent() - t_BxClo > 2 * Period() * 60) && ((Sel2 && Bid > TP && Bid < SL) || (! Sel2 && Ask > SL && Ask < TP))) {
            if (dtmp < 4.5) { ticket = OrderSend(Symbol(), Sel2, 0.01, Sel2? Bid: Ask, 5, SL, TP, NULL, 0, 0, clrNONE);
               CreateHLine(SL, false, Time[0]);             CreateHLine(TP, true, Time[0]);
               CP_tims[4] = Time[0]; }       else  tim_ex2 = Time[0];         t_box = false;       t_Send = false; } }
      if (Period() >= 240 || dtmp > 4.5) return; }          if (t_CPClose) t_CPClose = false;

   if ((t_exp3 && Sell) || (t_exp4 && Buy)) { t_exp3 = false;        t_exp4 = false; }
   if ((t_exp3 && Buy) || (t_exp4 && Sell) || (t_exp3=(Exp_Ind2() && ((Sel2 && Sell) || (! Sel2 && Buy)))) || TimeCurrent() - tim_ex2 < 2 * Period() * 60) {
      t_exp4 = t_exp3 && Sell;         t_exp3 = t_exp3 && Buy;       return; }

   int cpt=0;     while((SpTr=SuperTrend(iBarShift(NULL, 0, CP_tim) + cpt)) == 2147483647) cpt ++;
   cpt = 0;       while(((Sel2 && SpTr < SuperTrend(iBarShift(NULL, 0, CP_tim) - cpt - 2)) ||
   (! Sel2 && SpTr > SuperTrend(iBarShift(NULL, 0, CP_tim) - cpt - 2)) || SpTr == 2147483647) &&
   cpt < iBarShift(NULL, 0, CP_tim)) { SpTr = SuperTrend(iBarShift(NULL, 0, CP_tim) - cpt);
      cpt ++; }         SpTr = SuperTrend(iBarShift(NULL, 0, CP_tim) - cpt);
   if (ticket < 0 || (! OrdersTotal() && ticket)) { ticket_ = ticket;         ticket = 0; }

   for (obj = 0; obj < ObjectsTotal(); obj ++) { name = ObjectName(obj);
      if (((Sel2 && StringFind(name, "liquid_Sell") > 0) || (! Sel2 && StringFind(name, "liquid_buy") > 0)) &&
      CP_tim - ObjectGet(name, OBJPROP_TIME1) < min && CP_tim > ObjectGet(name, OBJPROP_TIME1)) {
         min = CP_tim - ObjectGet(name, OBJPROP_TIME1);              x_obj = name; } }

   SL = ((Sel2 && ObjectGet(x_obj, OBJPROP_PRICE1) > SpTr) || (! Sel2 && ObjectGet(x_obj, OBJPROP_PRICE1) < SpTr)?
      ObjectGet(x_obj, OBJPROP_PRICE1): SpTr) + (Sel2? 1.0: -1.0) * 22 * Point();
   if (ObjectGet(x_obj, OBJPROP_TIME2) < CP_tim) SL = Sel2? iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 
      iBarShift(NULL, 0, ObjectGet(x_obj, OBJPROP_TIME2)) - iBarShift(NULL, 0, CP_tim), iBarShift(NULL, 0, CP_tim))):
      iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW,  iBarShift(NULL, 0, ObjectGet(x_obj, OBJPROP_TIME2)) -
      iBarShift(NULL, 0, CP_tim), iBarShift(NULL, 0, CP_tim))) + (Sel2? 1.0: -1.0) * 22 * Point();
   if (fabs((Sel2? Bid: Ask) - SL) > 0.01495 * (Sel2? Bid: Ask)) SL = (Sel2? Bid: Ask) * (Sel2? 1.01495: 0.98505);
   if (! CreateHLine(SL, false, CP_tim)) return;

   bool tst1, tst2, tst4;     min = 5000000;       string x_objs[];     ArrayResize(x_objs, ObjectsTotal() / 2);        cpt = 0;
   for (obj = 0; obj < ObjectsTotal(); obj ++) { name = ObjectName(obj);
      if (((ObjectGet(name, OBJPROP_PRICE1) < SpTr && ObjectGet(name, OBJPROP_PRICE1) < iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) -
      22 * Point() && Sel2 && (StringFind(name, "liquid_buy") > 0 || (StringFind(name, "BoxLine") > 0 &&
      CP_tim - ObjectGet(name, OBJPROP_TIME1) > 25 * Period() * 60 && ObjectGet(name, OBJPROP_PRICE1) < iLow(NULL,
      0, iBarShift(NULL, 0, CP_tim)) - 22 * Point()))) || (! Sel2 && (StringFind(name, "liquid_Sell") > 0 ||
      (StringFind(name, "BoxLine") > 0 && CP_tim - ObjectGet(name, OBJPROP_TIME1) > 25 * Period() * 60 &&
      ObjectGet(name, OBJPROP_PRICE1) > iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)))) &&
      ObjectGet(name, OBJPROP_PRICE1) > iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)) + 22 * Point() &&
      ObjectGet(name, OBJPROP_PRICE1) > SpTr)) && ((tst1=(CP_tim - ObjectGet(name, OBJPROP_TIME1) < min)) ||
      ((tst2=((Sel2 && iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) - ObjectGet(name, OBJPROP_PRICE1) < min2) ||
      (! Sel2 && ObjectGet(name, OBJPROP_PRICE1) - iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)) < min2))))) &&
      CP_tim > ObjectGet(name, OBJPROP_TIME1)) { if (tst1) min = CP_tim - ObjectGet(name, OBJPROP_TIME1);
         if (tst2) min2 = (Sel2? iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) - ObjectGet(name, OBJPROP_PRICE1):
            ObjectGet(name, OBJPROP_PRICE1) - iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)));      x_objs[cpt] = x_obj2;
         if ((tst2 || (tst1 && ((Sel2 && iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) - ObjectGet(name, OBJPROP_PRICE1) <
         iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) - ObjectGet(x_objs[cpt], OBJPROP_PRICE1)) || (! Sel2 && ObjectGet(name,
         OBJPROP_PRICE1) - iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)) < ObjectGet(x_objs[cpt], OBJPROP_PRICE1) - iHigh(NULL, 0,
         iBarShift(NULL, 0, CP_tim))) || x_objs[cpt] == "" || StringFind(name, "BoxLine") > 0))) &&
         (ObjectGet(name, OBJPROP_TIME2) >= CP_tim || StringFind(name, "BoxLine") > 0)) { x_obj2 = name;       cpt ++; } } }
if (CP_tims[2] != CP_tim)
Alert("**1* " + x_obj2 + " - " + DoubleToStr(TP, Digits()) + " - " + DoubleToStr(ObjectGet(x_obj2, OBJPROP_PRICE1), Digits()) + " - " + TimeToStr(ObjectGet(x_obj2, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " - " +
   TimeToStr(ObjectGet(x_obj2, OBJPROP_TIME2), TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " - " + tst1 + " - " + tst2 + " - " + tst4 + " ***");

   double TP2;       bool alt2=false, tst3=false;        string tmp="";       tst = false;
   TP = (TP2=ObjectGet(x_obj2, OBJPROP_PRICE1)) + (Sel2? 1.0: -1.0) * 12 * Point();
   while((tst4=(fabs(TP - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) < 0.75 * fabs(SpTr - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) ||
   (Sel2 && Bid < TP + 12 * Point()) || (! Sel2 && Ask > TP - 12 * Point()))) && cpt) { min2 = 500000.0;
      if (alt2) { for (int ob=0; ob < ArraySize(x_objs); ob ++) if (StringFind(tmp, IntegerToString(ob) + "|") < 0 &&
         ! (fabs(TP - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) < 0.75 * fabs(SpTr - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) ||
         (tst=((Sel2 && Bid < TP + 12 * Point()) || (! Sel2 && Ask > TP - 12 * Point()))))) { tst3 = tst || tst3? true: false;
            name = x_objs[ob];      if ((Sel2 && iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) - ObjectGet(name, OBJPROP_PRICE1) < min2) ||
            (! Sel2 && ObjectGet(name, OBJPROP_PRICE1) - iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)) < min2)) {
               tmp += IntegerToString(ob) + "|";      min2 = (Sel2? iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)) - ObjectGet(name, OBJPROP_PRICE1):
                  ObjectGet(name, OBJPROP_PRICE1) - iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)));         cpt = ob; } }        x_obj2 = x_objs[cpt]; }
      TP = (alt2? (TP2=ObjectGet(x_objs[cpt], OBJPROP_PRICE1)) + (Sel2? 1.0: -1.0) * 12 * Point(): TP2);       if (! alt2) cpt --;
      alt2 = alt2? false: true; }               if (tst || tst3) { tst = false;
      for (ob = 0; ob < ObjectsTotal() && ! tst; ob ++) { string name2=ObjectName(ob);
         tst = StringFind(name2, "rect") > 0 && ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) ==
            ObjectGet(x_obj2, OBJPROP_TIME2) && StringSubstr(x_obj2, StringFind(x_obj2, "BoxLine") + 7, 16) ==
            StringSubstr(name2, StringFind(name2, "rect") + 4, 16)/* && ObjectGet(name2, OBJPROP_COLOR) != 5789784*/; }
      if (tst) TP = (Sell? ObjectGet(name2, OBJPROP_PRICE1): ObjectGet(name2, OBJPROP_PRICE2)) + (Sel2? 1.0: -1.0) * 12 * Point(); }
   else if (alt2) TP += (Sel2? 1.0: -1.0) * 12 * Point();         min2 = 500000.0;        tst = false;         tst3 = false;
   for (ob = 0; ob < ObjectsTotal()/* && ! tst*/; ob ++) { name2 = ObjectName(ob);
      tst = StringFind(name2, "BoxLine") > 0 && ObjectType(name2) == OBJ_TREND && ObjectGet(name2, OBJPROP_TIME1) > ObjectGet(x_obj2, OBJPROP_TIME1) &&
         ObjectGet(name2, OBJPROP_TIME1) < CP_tim && ! ((Sel2 && Bid < ObjectGet(name2, OBJPROP_PRICE1) + 12 * Point()) ||
         (! Sel2 && Ask > ObjectGet(name2, OBJPROP_PRICE1) - 12 * Point())) && fabs(ObjectGet(name2, OBJPROP_PRICE1) - iClose(NULL, 0,
         iBarShift(NULL, 0, CP_tim))) < fabs(ObjectGet(x_obj2, OBJPROP_PRICE1) - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) &&
         fabs(ObjectGet(name2, OBJPROP_PRICE1) - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) > (t_Adx? 0.4: 0.75) * fabs(SpTr - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)));
      if (tst && fabs(ObjectGet(name2, OBJPROP_PRICE1) - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))) < min2) { x_obj2 = name2;
         min2 = fabs(ObjectGet(name2, OBJPROP_PRICE1) - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim))); }        tst3 = tst || tst3? true: false; }
   if (tst || tst3) { tst = false;           for (ob = 0; ob < ObjectsTotal() && ! tst; ob ++) { name2 = ObjectName(ob);
         tst = StringFind(name2, "rect") > 0 && ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) ==
            ObjectGet(x_obj2, OBJPROP_TIME2) && StringSubstr(x_obj2, StringFind(x_obj2, "BoxLine") + 7, 16) ==
            StringSubstr(name2, StringFind(name2, "rect") + 4, 16)/* && ObjectGet(name2, OBJPROP_COLOR) != 5789784*/; }
      if (tst) TP = (Sell? ObjectGet(name2, OBJPROP_PRICE1): ObjectGet(name2, OBJPROP_PRICE2)) + (Sel2? 1.0: -1.0) * 12 * Point(); }//      CreateHLine(TP, true, CP_tim);
/*      if ((Sel2 && TP < iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, 160, iBarShift(NULL, 0, CP_tim)))) ||
      (! Sel2 && TP > iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 160, iBarShift(NULL, 0, CP_tim))))) TP = (Sel2? iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, 160, iBarShift(NULL, 0, CP_tim))):
            iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 160, iBarShift(NULL, 0, CP_tim)))) + (Sel2? 1.0: -1.0) * 12 * Point();         CreateHLine(TP, true, CP_tim); */
//if (StringFind(TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES), "04.06 04:00") > 0)
if (CP_tims[2] != CP_tim)
Alert("**2* " + x_obj2 + " - " + DoubleToStr(TP, Digits()) + " - " + DoubleToStr(ObjectGet(x_obj2, OBJPROP_PRICE1), Digits()) + " - " + TimeToStr(ObjectGet(x_obj2, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " - " +
   TimeToStr(ObjectGet(x_obj2, OBJPROP_TIME2), TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " - " + tst1 + " - " + tst2 + " - " + tst4 + " ***");

   if ((Sel2 && TP > Bid) || (! Sel2 && TP < Ask)) TP = iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)) + (Sel2? -0.01: 0.01) * iClose(NULL, 0, iBarShift(NULL, 0, CP_tim));
   if ((Sel2 && SL < Ask) || (! Sel2 && SL > Bid)) SL = iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)) - (Sel2? -0.01: 0.01) * iClose(NULL, 0, iBarShift(NULL, 0, CP_tim));
   if ((Sel2 && SL < Ask) || (! Sel2 && SL > Bid) || (Sel2 && TP > Bid) || (! Sel2 && TP < Ask)) return;          ResetLastError();          CreateHLine(TP, true, CP_tim);
   if (t_Send && ! ticket) { if (t_P60b && ticket_ && OrderSelect(ticket_, SELECT_BY_TICKET)) { SL = OrderOpenPrice();           TP = OrderTakeProfit();
         dtmp = Sel2? t_P60b? ObjectGet(namBox, OBJPROP_PRICE2) - 12 * Point(): Bid: t_P60b? ObjectGet(namBox, OBJPROP_PRICE1) + 12 * Point(): Ask;
//Alert("*** OrderSend(0) - " + Buy + " - " + Sell + " - " + Sel2 + " - " + namBox + " - " + t_P60b + " - " + dtmp + " - " + SL + " - " + TP + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " ***");
         if ((Sel2 && SL < dtmp) || (! Sel2 && SL > dtmp) || (Sel2 && TP > dtmp) || (! Sel2 && TP < dtmp)) { t_BH2 = false;      t_P60 = false;    t_P60b = false;      return; }
         double SL_=SL;       tst = false;      for (obj = 0; obj < ObjectsTotal() && ! tst; obj ++) { name = ObjectName(obj);
            tst = ((Sel2 && name == "RSLinesR1") || (! Sel2 && name == "RSLinesS1")) && ObjectType(name) == OBJ_TREND/* &&
               ObjectGet(name, OBJPROP_TIME1) > CP_tims[0] && CP_tims[0]*/; }
         if (tst) SL = (Sel2? fmax(SL, ObjectGet(name, OBJPROP_PRICE1)): fmin(SL, ObjectGet(name, OBJPROP_PRICE1))) + (Sel2? -1.0: 1.0) * 12 * Point();
         if ((Sel2 && SL < Ask) || (! Sel2 && SL > Bid)) SL = SL_; }             else  dtmp = Sel2? Bid: Ask;
      if ((Sel2 && TP > dtmp - 20 * Point()) || (! Sel2 && TP < dtmp + 20 * Point())) TP += (Sel2? -1.0: 1.0) * 100 * Point();
      if ((Sel2 && TP > Bid - 20 * Point()) || (! Sel2 && TP < Ask + 20 * Point())) TP += (Sel2? -1.0: 1.0) * fabs(TP - dtmp);
      ticket = OrderSend(Symbol(), Sel2 + (t_P60b && ((Sel2 && dtmp > Ask) || (! Sel2 && dtmp < Bid))? 2: 0), 0.01, t_P60b &&
         ((Sel2 && dtmp > Ask) || (! Sel2 && dtmp < Bid))? dtmp: Sel2? Bid: Ask, 5, SL, TP + (t_P60b? Sel2? -1.0: 1.0: 0.0) * fabs(TP - dtmp),
         NULL, 0, t_P60b && ((Sel2 && dtmp > Ask) || (! Sel2 && dtmp < Bid))? Time[0] + 7 * Period() * 60: 0, clrNONE);
      if (ticket > 0) { CP_tims[0] = CP_tim? CP_tim: Time[0];           CP_tims[4] = 0;         t_box = true;
         if (Period() <= 60 && OrderSelect(ticket, SELECT_BY_TICKET) && fabs(OrderTakeProfit() - OrderOpenPrice()) < 0.01 * OrderOpenPrice()) {
            dtmp = OrderOpenPrice() + (OrderTakeProfit() - OrderOpenPrice()) * 2.0;          if (OrderModify(ticket, OrderOpenPrice(), OrderStopLoss(),
               (TP=Sel2? fmax(0.99 * OrderOpenPrice(), dtmp): fmin(1.01 * OrderOpenPrice(), dtmp)), 0, clrNONE)) CreateHLine(TP, true, CP_tim); }
if (CP_tims[2] != CP_tim)
Alert("*** OrderSend() OK! " + ticket + " - " + x_obj2 + " - " + DoubleToStr(Sel2? Bid: Ask, Digits()) + " - " + DoubleToStr(TP, Digits()) + " - " + TimeToStr(ObjectGet(x_obj2, OBJPROP_TIME1),
   TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(ObjectGet(x_obj2, OBJPROP_TIME2), TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " ***"); }
      else { Alert("******* OrderSend() NO! " + GetLastError() + " - " + Buy + " - " + Sell + " - " + Sel2 + " - " + namBox + " - " +
   t_P60b + " - " + dtmp + " - " + SL + " - " + TP + " - " + TimeToStr(CP_tim, TIME_DATE|TIME_MINUTES) + " *******");         f_End_EA();/*          ObjectsDelete(0, "EA_X-Line_");*/ } }

   t_Send = false;         min = 5000000;          string x_obj3="";          tst = false;
   for (obj = 0; obj < ObjectsTotal(); obj ++) { name = ObjectName(obj);
      if (StringFind(name, "BoxLine") > 0 && ObjectType(name) == OBJ_TREND && ObjectGet(name, OBJPROP_TIME1) - CP_tim < min &&
      CP_tim < ObjectGet(name, OBJPROP_TIME1)) {/* for (ob = 0; ob < ObjectsTotal() && ! tst; ob ++) { string name2=ObjectName(ob);
            tst = StringFind(name2, "rect") > 0 && ObjectType(name2) == OBJ_RECTANGLE && ObjectGet(name2, OBJPROP_TIME2) ==
               ObjectGet(name, OBJPROP_TIME2) && StringSubstr(name, StringFind(name, "BoxLine") + 7, 16) ==
               StringSubstr(name2, StringFind(name2, "rect") + 4, 16) && ObjectGet(name2, OBJPROP_COLOR) != 5789784; }
         if (tst) {*/ min = ObjectGet(name, OBJPROP_TIME1) - CP_tim;         x_obj3 = name; } }// }
   if (ticket > 0) t_CPClose = true;            if (CP_tims[2] != CP_tim)
Alert("*** BoxLine - " + x_obj3 + " - " + DoubleToStr(ObjectGet(x_obj3, OBJPROP_PRICE1), Digits()) + " - " +/* ObjectGet(name2, OBJPROP_COLOR) + " - " +*/
   TimeToStr(ObjectGet(x_obj3, OBJPROP_TIME1), TIME_DATE|TIME_MINUTES) + " - " + TimeToStr(ObjectGet(x_obj3, OBJPROP_TIME2), TIME_DATE|TIME_MINUTES) + " ***");

   double res;       tst = false;      tst1 = false;        tst2 = false;//        bool tst3;
      for (int bar=0; bar < fmin(300, iBarShift(NULL, 0, CP_tim)) && ! tst; bar ++) {
/*      if (! tst4 && (tst=((Sel2 && (iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) > SL || iLow(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) < TP)) ||
      (! Sel2 && (iLow(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) < SL || iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) > TP)))))
         res = (tst1=((Sel2 && iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) > SL) ||
         (! Sel2 && iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) > TP)))? (Sel2? 1.0: -1.0) * iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)) -
         (Sel2? 1.0: -1.0) * (Sel2? SL: TP): (tst2=((! Sel2 && iLow(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) < SL) ||
         (Sel2 && iLow(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) < TP)))? (Sel2? 1.0: -1.0) * iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)) -
         (Sel2? 1.0: -1.0) * (Sel2? TP: SL): 0.0;
      else */if (! tst4 && (tst=(tst3=((Sel2 && iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 1, iBarShift(NULL, 0, CP_tim) - bar) > 0.0) ||
      (! Sel2 && iCustom(NULL, 0, "New folder\\Manual Trade Cashpower Lifetime.ex4", 0, iBarShift(NULL, 0, CP_tim) - bar) > 0.0))))) {
         res = (iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)) - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar)) * (Sel2? 1.0: -1.0);

         if (OrderSelect(ticket, SELECT_BY_TICKET) && ((! OrderCloseTime() && OrderClose(ticket, OrderLots(), Sel2? Bid: Ask, 5, clrNONE)) ||
         OrderCloseTime())) { ticket_ = ticket;       ticket = 0;       CP_tim = 0;
Alert("*** CP tst3 Close - " + (iBarShift(NULL, 0, CP_tim) - bar) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim) - bar], TIME_DATE|TIME_MINUTES) + " ***"); } }

      /*else */if ((tst=(HA_Reverse(Sel2, iBarShift(NULL, 0, CP_tim) - bar) || (((Sel2 && iClose(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) > SpTr) ||
      (! Sel2 && iClose(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar) < SpTr)) && bar) || (Time[iBarShift(NULL, 0, CP_tim) - bar] == ObjectGet(x_obj3, OBJPROP_TIME2) &&
      (bar > 1.5 * (iBarShift(NULL, 0, ObjectGet(x_obj, OBJPROP_TIME1)) - iBarShift(NULL, 0, CP_tim)) || bar > 23))))) {
         res = (iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)) - iClose(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar)) * (Sel2? 1.0: -1.0);
         SL = (Time[iBarShift(NULL, 0, CP_tim) - bar] == ObjectGet(x_obj3, OBJPROP_TIME2)?
            Sel2? iHigh(NULL, 0, iBarShift(NULL, 0, ObjectGet(x_obj3, OBJPROP_TIME2))):
            iLow(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar): SpTr) + (Sel2? 1.0: -1.0) * 22 * Point();        bar --;

         if (OrderSelect(ticket, SELECT_BY_TICKET) && ((! OrderCloseTime() && OrderClose(ticket, OrderLots(), Sel2? Bid: Ask, 5, clrNONE)) ||
         OrderCloseTime())) { ticket_ = ticket;       ticket = 0;       CP_tim = 0;
Alert("*** BoxLine Close - " + x_obj3 + " - " + DoubleToStr(ObjectGet(x_obj3, OBJPROP_PRICE1), Digits()) + " - " + TimeToStr(ObjectGet(x_obj3, OBJPROP_TIME2), TIME_DATE|TIME_MINUTES) + " ***"); }/*

         if (OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime() && OrderModify(ticket, OrderOpenPrice(), SL, OrderTakeProfit(), 0, clrNONE)) {}
         else  if (OrderSelect(ticket, SELECT_BY_TICKET) && OrderCloseTime()) ticket = 0;*/ } }

/*   if (tst) { DrawArrow_chck(tst3 || (!tst1 && !tst2 && !tst3)? iClose(NULL, 0, iBarShift(NULL, 0, CP_tim) - (bar-1)): (! Sel2 && tst1) || (Sel2 && tst2)? TP: SL,
         iBarShift(NULL, 0, CP_tim) - (bar-1), ((! Sel2 && tst1) || (Sel2 && tst2) || (tst3 || (! tst1 && ! tst2 && ! tst3))) && res > 0.0, k);
      _k = k;        t_res += res;           if (res < 0.0) { ExpertRemove();             EventKillTimer();
      double TV=MarketInfo(Symbol(), MODE_TICKVALUE), TS=MarketInfo(Symbol(), MODE_TICKSIZE);            TV = TV < 0.1? 1.0: TV;
Alert("**2* RESULTAT " + (res > 0.0? "POSITIF, HOURA": "NEGATIF") + " ! - " + DoubleToStr(res, Digits()) + " - " + DoubleToStr(res / TS * TV * 0.01, Digits()) + " - " +
   DoubleToStr(SpTr, Digits()) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim) - (bar-1)], TIME_DATE|TIME_MINUTES) + " - " + tst1 + " - " + tst2 + " - " + tst3 + " - " + tst4 +
   " - " + DoubleToStr(iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)), Digits()) + " - " + DoubleToStr(iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)), Digits()) +
   " - " + DoubleToStr(iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)), Digits()) + " - " + DoubleToStr(iClose(NULL, 0, iBarShift(NULL, 0, CP_tim) - bar+1), Digits()) +
   " - " + DoubleToStr(SL, Digits()) + " - " + DoubleToStr(TP, Digits()) + " ***"); } }*/ }

bool HA_Reverse(bool Sel2,int vBar) { int j=0, k=0;         return(false);
   bool ha1=HA_Bull(iOpen(NULL, 0, vBar), iClose(NULL, 0, vBar), iHigh(NULL, 0, vBar), iLow(NULL, 0, vBar), vBar),
      ha2=HA_Bull(iOpen(NULL, 0, vBar+1), iClose(NULL, 0, vBar+1), iHigh(NULL, 0, vBar+1), iLow(NULL, 0, vBar+1), vBar+1),
      ha3=HA_Bull(iOpen(NULL, 0, vBar+2), iClose(NULL, 0, vBar+2), iHigh(NULL, 0, vBar+2), iLow(NULL, 0, vBar+2), vBar+2),
      ha4=HA_Bull(iOpen(NULL, 0, vBar+3), iClose(NULL, 0, vBar+3), iHigh(NULL, 0, vBar+3), iLow(NULL, 0, vBar+3), vBar+3),
      ha5=HA_Bull(iOpen(NULL, 0, vBar+4), iClose(NULL, 0, vBar+4), iHigh(NULL, 0, vBar+4), iLow(NULL, 0, vBar+4), vBar+4),
      ha6=HA_Bull(iOpen(NULL, 0, vBar+5), iClose(NULL, 0, vBar+5), iHigh(NULL, 0, vBar+5), iLow(NULL, 0, vBar+5), vBar+5);
   if (! ha1) j ++;     if (! ha2) j ++;     if (! ha3) j ++;     if (! ha4) j ++;     if (! ha5) j ++;     if (! ha6) j ++;
   if (ha1) k ++;       if (ha2) k ++;       if (ha3) k ++;       if (ha4) k ++;       if (ha5) k ++;       if (ha6) k ++;
   return(((! Sel2 && ((! ha1 && ! ha2 && ! ha3 && ! ha4) || j > 4)) || (Sel2 && ((ha1 && ha2 && ha3 && ha4) || k > 4)))); }

bool HA_Bull(double vOpen, double vClose, double vHigh, double vLow, int vBar) {
   haOpen = vBar >= nBars - 1? vOpen: ExtOpenBuffer[nBars - vBar-1];
   haClose = vBar >= nBars - 1? vClose: ExtCloseBuffer[nBars - vBar-1];
   haHigh = MathMax(vHigh, MathMax(haOpen, haClose));
   haLow = MathMin(vLow, MathMin(haOpen, haClose));

/*   if (ha_Shw && vBar < 17) { DrawArrow_HA(haOpen, vBar, 3, (haOpen < haClose));  //, vChart);
      DrawArrow_HA(haClose, vBar, 3, (haOpen < haClose));   //, vChart);
      DrawArrow_HA(haHigh, vBar, 2, (haOpen < haClose));    //, vChart);
      DrawArrow_HA(haLow, vBar, 1, (haOpen < haClose)); }   //, vChart); } //*/

   return(haOpen < haClose); }

void DrawArrow_HA(double LinePrice,int BarNum,int Code,bool Bullish) {
   string ArrowName = "H-A_Test_Arr"+(Bullish?"-Up_":"-Down_")+IntegerToString(Code)+"-"+IntegerToString(BarNum)+"-"+LinePrice;
   ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice);
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code);
   ObjectSet(ArrowName, OBJPROP_COLOR, Bullish? clrLime: clrDeepPink);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

void HA_Buffers() {
   ExtOpenBuffer[0] = iOpen(NULL,0,nBars-1);
   ExtCloseBuffer[0] = iClose(NULL,0,nBars-1);

   for (int i=1; i < nBars; i ++) {    // Bars
      haOpen = (ExtOpenBuffer[i-1] + ExtCloseBuffer[i-1]) / 2;
      haClose = (iOpen(NULL,0,nBars-i-1)+iHigh(NULL,0,nBars-i-1)+iLow(NULL,0,nBars-i-1)+iClose(NULL,0,nBars-i-1))/4;
      ExtOpenBuffer[i] = haOpen;
      ExtCloseBuffer[i] = haClose;              /* if (i > Bars-10) {

      Print("** ExtOpenBuffer[i-2] ",ExtOpenBuffer[i-2]," ExtOpenBuffer[i-1] ",ExtOpenBuffer[i-1]," ExtOpenBuffer[i] ",ExtOpenBuffer[i]," | ",i," ... ");
      Print(" (suite) ExtCloseBuffer[i-2] ",ExtCloseBuffer[i-2]," ExtCloseBuffer[i-1] ",ExtCloseBuffer[i-1]," ExtCloseBuffer[i] ",ExtCloseBuffer[i]," ... ");
      Print(" (suite) iOpen(Bars-i-1) ",iOpen(NULL,0,Bars-i-1)," iHigh(Bars-i-1) ",iHigh(NULL,0,Bars-i-1)," iLow(Bars-i-1) ",iLow(NULL,0,Bars-i-1)," iClose(Bars-i-1) ",iClose(NULL,0,Bars-i-1)," ... ");
      Print(" (suite) iOpen(Bars-i) ",iOpen(NULL,0,Bars-i)," iHigh(Bars-i) ",iHigh(NULL,0,Bars-i)," iLow(Bars-i) ",iLow(NULL,0,Bars-i)," iClose(Bars-i) ",iClose(NULL,0,Bars-i)," ... ");
      Print(" (suite) iOpen(Bars-i+1) ",iOpen(NULL,0,Bars-i+1)," iHigh(Bars-i+1) ",iHigh(NULL,0,Bars-i+1)," iLow(Bars-i+1) ",iLow(NULL,0,Bars-i+1)," iClose(Bars-i+1) ",iClose(NULL,0,Bars-i+1)," ... ");
      Print(" (suite) TimeToStr(Bars-i-1) ",TimeToStr(iTime(NULL,0,Bars-i-1),TIME_DATE|TIME_MINUTES)," TimeToStr(Bars-i) ",TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES),
         " TimeToStr(Bars-i+1) ",TimeToStr(iTime(NULL,0,Bars-i+1),TIME_DATE|TIME_MINUTES)," **"); } */ }
   return; }

void DrawArrow_chck(double LinePrice,int BarNum,bool Pos,int k) {
   string ArrowName="EA_Chck2-"+IntegerToString(Pos)+"_"+IntegerToString(BarNum)+" "+IntegerToString(Time[BarNum]);
   if (! ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice + (Bid < 0.5? 40.0: 80.0) * Point()))
      Print("*** ObjectCreate Error : "+IntegerToString(GetLastError())+" / "+DoubleToStr(LinePrice,5)+" - "+IntegerToString(BarNum)+" ***");
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, Pos? 252: 251);
   ObjectSet(ArrowName, OBJPROP_COLOR, Pos? clrGold: clrSilver);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
//   ObjectSet(ArrowName, OBJPROP_YDISTANCE, 55);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 3);

   ArrowName = "EA_Chck2-"+IntegerToString(Pos)+"b_"+IntegerToString(BarNum)+" "+IntegerToString(Time[BarNum]);
   if (! ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum-2],LinePrice + (Bid < 0.5? 37.0: 77.0) * Point()))
      Print("*** ObjectCreate Error : "+IntegerToString(GetLastError())+" / "+DoubleToStr(LinePrice,5)+" - "+IntegerToString(BarNum)+" ***");
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, 129 + k);
   ObjectSet(ArrowName, OBJPROP_COLOR, Pos? clrGold: clrSilver);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
//   ObjectSet(ArrowName, OBJPROP_YDISTANCE, 55);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 1); }

double m3_RSI (ENUM_TIMEFRAMES per,int bar,int nb) {
   return((iCustom(NULL, per, "RSI.ex4", 0, bar + 1) + iCustom(NULL, per, "RSI.ex4", 0, bar + 2) +
      (nb == 3 ? iCustom(NULL, per, "RSI.ex4", 0, bar + 3) : 0.0)) / nb); }

double SuperTrend(int bar) { return(iCustom(NULL, 0, "super-trend_.ex4", 10, 4.0, 0, bar) == 2147483647?
      iCustom(NULL, 0, "super-trend_.ex4", 10, 4.0, 1, bar) == 2147483647? 2147483647:
      iCustom(NULL, 0, "super-trend_.ex4", 10, 4.0, 1, bar): iCustom(NULL, 0, "super-trend_.ex4", 10, 4.0, 0, bar)); }

void f_End_EA() { int zero=0;    Print(1 / zero); }

void Exp_Inds() { int cpt=0;        double dtmp;         ArrayInitialize(Exp_Ind, 0.0);
//   for (int pos=300; pos/* && ! tst*/; pos --) { dtmp = 0.0;       Comment("* pos = " + IntegerToString(pos) + " *");
   for (int pos=0; pos < 300/* && ! tst*/; pos ++) { dtmp = 0.0;        t_exp = false;
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 0, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][0] = dtmp;       Exp_Ind[cpt][10] = Time[pos];//       t_exp = true;
if (0) Alert("******* 0 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 1, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][1] = dtmp;       Exp_Ind[cpt][11] = Time[pos];//       t_exp = true;
if (0) Alert("******* 1 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 2, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][2] = dtmp;       Exp_Ind[cpt][12] = Time[pos];//       t_exp = true;
if (0) Alert("******* 2 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 3, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][3] = dtmp;       Exp_Ind[cpt][13] = Time[pos];//       t_exp = true;
if (0) Alert("******* 3 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 4, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][4] = dtmp;       Exp_Ind[cpt][14] = Time[pos];//       t_exp = true;
if (0) Alert("******* 4 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 5, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][5] = dtmp;       Exp_Ind[cpt][15] = Time[pos];       t_exp = true;
if (0) Alert("******* 5 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 6, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][6] = dtmp;       Exp_Ind[cpt][16] = Time[pos];       t_exp = true;
if (0) Alert("******* 6 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 7, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][7] = dtmp;       Exp_Ind[cpt][17] = Time[pos];//       t_exp = true;
if (0) Alert("******* 7 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 8, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][8] = dtmp;       Exp_Ind[cpt][18] = Time[pos];       t_exp = true;
if (0) Alert("******* 8 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if ((dtmp=iCustom(NULL, 0, "ATS Expansion Index V4.0.ex4", 9, pos)) != 0.0 &&
      dtmp != 2147483647.0) { Exp_Ind[cpt][9] = dtmp;       Exp_Ind[cpt][19] = Time[pos];       t_exp = true;
if (0) Alert("******* 9 - " + DoubleToStr(dtmp, Digits()) + " - " + IntegerToString(cpt) + " *******"); }
      if (t_exp) { Exp_Ind[cpt][20] = Time[pos];         cpt ++; } }
   tim_exp = Time[0];         t_cpt = cpt;         t_exp = false;
   if (TimeCurrent() - t_BxClo > 2 * Period() * 60) t_BxClo = 0; }

bool Exp_Ind2() { double Exp_Sup, Exp_Inf, Exp_Med, E_Range;         bool tst=false;
   for (int obj=0; obj < ObjectsTotal() && ! tst; obj ++) { string name=ObjectName(obj);
      if (name == "ATS Expansion Index V4.0aei_1") Exp_Sup = ObjectGet(name, OBJPROP_PRICE1);
      if (name == "ATS Expansion Index V4.0aei_2") Exp_Inf = ObjectGet(name, OBJPROP_PRICE1);
      if (tst=(name == "ATS Expansion Index V4.0aei_3")) Exp_Med = ObjectGet(name, OBJPROP_PRICE1); }

   E_Range = Sell? Exp_Inf - Exp_Med: Exp_Sup - Exp_Med;
   t_exp2 = Exp_Inf && Exp_Sup && Exp_Inf != 2147483647.0 && Exp_Sup != 2147483647.0? Exp_Ind[0][20] == Time[0]?
      (Buy && ((Exp_Ind[1][5] > E_Range && Exp_Ind[2][6] > E_Range) || (Exp_Ind[1][8] > E_Range && Exp_Ind[2][9] > E_Range))) ||
      (Sell && ((Exp_Ind[1][6] < E_Range && Exp_Ind[2][5] < E_Range) || (Exp_Ind[1][9] < E_Range && Exp_Ind[2][8] < E_Range)))/* ||
      (Buy && (Exp_Ind[2][5] > E_Range || Exp_Ind[2][8] > E_Range)) || (Sell && (Exp_Ind[2][6] < E_Range || Exp_Ind[2][9] < E_Range)) ||
      (Buy && (Exp_Ind[3][5] > E_Range || Exp_Ind[3][8] > E_Range)) || (Sell && (Exp_Ind[3][6] < E_Range || Exp_Ind[3][9] < E_Range))*/:
      (Buy && ((Exp_Ind[0][5] > E_Range && Exp_Ind[1][6] > E_Range) || (Exp_Ind[0][8] > E_Range && Exp_Ind[1][9] > E_Range))) ||
      (Sell && ((Exp_Ind[0][6] < E_Range && Exp_Ind[1][5] < E_Range) || (Exp_Ind[0][9] < E_Range && Exp_Ind[1][8] < E_Range)))/* ||
      (Buy && (Exp_Ind[1][5] > E_Range || Exp_Ind[1][8] > E_Range)) || (Sell && (Exp_Ind[1][6] < E_Range || Exp_Ind[1][9] < E_Range)) ||
      (Buy && (Exp_Ind[2][5] > E_Range || Exp_Ind[2][8] > E_Range)) || (Sell && (Exp_Ind[2][6] < E_Range || Exp_Ind[2][9] < E_Range))*/: false;
//Alert("******* t_exp2 - " + DoubleToStr(Exp_Inf, 1) + " - " + DoubleToStr(Exp_Med, 1) + " - " + DoubleToStr(Exp_Sup, 1) + " - " + DoubleToStr(E_Range, 1) + " - " + t_exp2 + " *******");
   return(t_exp2); }

/* Alert("******* HA-1: " + iBarShift(NULL, 0, CP_tim) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)), iBarShift(NULL, 0, CP_tim)) + " *******");
Alert("******* HA-2: " + (iBarShift(NULL, 0, CP_tim)-1) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-1], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-1),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-1), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-1), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-1), iBarShift(NULL, 0, CP_tim)-1) + " *******");
Alert("******* HA-3: " + (iBarShift(NULL, 0, CP_tim)-2) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-2], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-2),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-2), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-2), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-2), iBarShift(NULL, 0, CP_tim)-2) + " *******");
Alert("******* HA-4: " + (iBarShift(NULL, 0, CP_tim)-3) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-3], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-3),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-3), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-3), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-3), iBarShift(NULL, 0, CP_tim)-3) + " *******");
Alert("******* HA-5: " + (iBarShift(NULL, 0, CP_tim)-4) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-4], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-4),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-4), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-4), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-4), iBarShift(NULL, 0, CP_tim)-4) + " *******");
Alert("******* HA-6: " + (iBarShift(NULL, 0, CP_tim)-5) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-5], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-5),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-5), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-5), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-5), iBarShift(NULL, 0, CP_tim)-5) + " *******");
Alert("******* HA-7: " + (iBarShift(NULL, 0, CP_tim)-6) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-6], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-6),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-6), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-6), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-6), iBarShift(NULL, 0, CP_tim)-6) + " *******");
Alert("******* HA-7: " + (iBarShift(NULL, 0, CP_tim)-7) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-7], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-7),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-7), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-7), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-7), iBarShift(NULL, 0, CP_tim)-7) + " *******");
Alert("******* HA-8: " + (iBarShift(NULL, 0, CP_tim)-8) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-8], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-8),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-8), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-8), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-8), iBarShift(NULL, 0, CP_tim)-8) + " *******");
Alert("******* HA-9: " + (iBarShift(NULL, 0, CP_tim)-9) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-9], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-9),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-9), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-9), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-9), iBarShift(NULL, 0, CP_tim)-9) + " *******");
Alert("******* HA-10: " + (iBarShift(NULL, 0, CP_tim)-10) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-10], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-10),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-10), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-10), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-10), iBarShift(NULL, 0, CP_tim)-10) + " *******");
Alert("******* HA-11: " + (iBarShift(NULL, 0, CP_tim)-11) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-11], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-11),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-11), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-11), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-11), iBarShift(NULL, 0, CP_tim)-11) + " *******");
Alert("******* HA-12: " + (iBarShift(NULL, 0, CP_tim)-12) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-12], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-12),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-12), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-12), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-12), iBarShift(NULL, 0, CP_tim)-12) + " *******");
Alert("******* HA-13: " + (iBarShift(NULL, 0, CP_tim)-13) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-13], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-13),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-13), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-13), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-13), iBarShift(NULL, 0, CP_tim)-13) + " *******");
Alert("******* HA-14: " + (iBarShift(NULL, 0, CP_tim)-14) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-14], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-14),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-14), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-14), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-14), iBarShift(NULL, 0, CP_tim)-14) + " *******");
Alert("******* HA-15: " + (iBarShift(NULL, 0, CP_tim)-15) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-15], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-15),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-15), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-15), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-15), iBarShift(NULL, 0, CP_tim)-15) + " *******");
Alert("******* HA-16: " + (iBarShift(NULL, 0, CP_tim)-16) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-16], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-16),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-16), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-16), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-16), iBarShift(NULL, 0, CP_tim)-16) + " *******");
Alert("******* HA-17: " + (iBarShift(NULL, 0, CP_tim)-17) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-17], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-17),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-17), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-17), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-17), iBarShift(NULL, 0, CP_tim)-17) + " *******");
Alert("******* HA-18: " + (iBarShift(NULL, 0, CP_tim)-18) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-18], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-18),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-18), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-18), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-18), iBarShift(NULL, 0, CP_tim)-18) + " *******");
Alert("******* HA-19: " + (iBarShift(NULL, 0, CP_tim)-19) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-19], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-19),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-19), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-19), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-19), iBarShift(NULL, 0, CP_tim)-19) + " *******");
Alert("******* HA-20: " + (iBarShift(NULL, 0, CP_tim)-20) + " - " + TimeToStr(Time[iBarShift(NULL, 0, CP_tim)-20], TIME_MINUTES) + " - " + HA_Bull(iOpen(NULL, 0, iBarShift(NULL, 0, CP_tim)-20),
   iClose(NULL, 0, iBarShift(NULL, 0, CP_tim)-20), iHigh(NULL, 0, iBarShift(NULL, 0, CP_tim)-20), iLow(NULL, 0, iBarShift(NULL, 0, CP_tim)-20), iBarShift(NULL, 0, CP_tim)-20) + " *******"); */
