int ticket, itmp_, itmp=0;       datetime tim1;    bool Bull, t_Sent=false;

int OnInit() { ticket = 0;       tim1 = 0;
   return(INIT_SUCCEEDED); }

void OnTick() { string temp, name, comm;     datetime OTim1;      bool tst=false, t_H4_M5=false;      itmp_ = itmp;
   if (ObjectsTotal() && (! itmp_ || ((Hour() == 1 || (Hour() == 13 && Period() < 240)) && ! Minute() && ! Seconds())))
      for (int pos=0; pos < ObjectsTotal() && ! tst; pos ++) { name = ObjectName(pos);
         tst = name == "eFess_ Success rate";         temp = ObjectGetString(0, name, OBJPROP_TEXT);
         itmp = tst && StringSubstr(temp, StringLen(temp) - 1) == "%"? StrToInteger(StringSubstr(temp, StringLen(temp) - 4, 3)): 0; }
if ((! itmp_ || itmp_ != itmp) && tst && itmp) Print("*** eFess_ Success rate! - " + name + " - " + temp + " - " + IntegerToString(itmp) + " ***");

   int signs, wins, loss;     if (ObjectsTotal()) for (pos = 0; pos < ObjectsTotal(); pos ++) { name = ObjectName(pos);
         if (name == "eFess_ --------" || name == "eFess_ Cancelled" || name == "eFess_ Min profit" ||
         name == "eFess_ Signals" || name == "eFess_ Success rate" || name == "eFess_ Title" ||
         name == "eFess_ Win loss" || name == "eFess_RectLabel") ObjectSet(name, OBJPROP_XDISTANCE, -220.0);
         if (name == "eFess_ Signals") { temp = ObjectGetString(0, name, OBJPROP_TEXT);
            signs = StrToInteger(StringSubstr(temp, StringLen(temp) - 3, 3));    comm = "* Signals : " + IntegerToString(signs); }
         if (name == "eFess_ Win loss") { temp = ObjectGetString(0, name, OBJPROP_TEXT);
            temp = StringSubstr(temp, StringLen(temp) - 9, 1) == ":"? StringSubstr(temp, StringLen(temp) - 7, 7):
               StringSubstr(temp, StringLen(temp) - 8, 1) == ":"? StringSubstr(temp, StringLen(temp) - 6, 6):
               StringSubstr(temp, StringLen(temp) - 7, 1) == ":"? StringSubstr(temp, StringLen(temp) - 5, 5):
               StringSubstr(temp, StringLen(temp) - 6, 1) == ":"? StringSubstr(temp, StringLen(temp) - 4, 4):
               StringSubstr(temp, StringLen(temp) - 3, 3);     
            wins = StrToInteger(StringSubstr(temp, 3, 1) == "/"? StringSubstr(temp, 0, 3):
               StringSubstr(temp, 2, 1) == "/"? StringSubstr(temp, 0, 2): StringSubstr(temp, 0, 1));
            loss = StrToInteger(StringSubstr(temp, 3, 1) == "/"? StringSubstr(temp, 4, 3):
               StringSubstr(temp, 2, 1) == "/"? StringSubstr(temp, 3, 3): StringSubstr(temp, 2, 3));
            comm += " / Win/Loss : " + wins + "/" + loss + " / Success : " + itmp + "% *"; }
         if (itmp_ != itmp) Comment(comm); }

   t_Sent = OrdersTotal();       if (t_Sent && ! ticket) { ticket = GlobalVariableGet(Symbol() + "_ticket" + (Period() >= 30? "_240": ""));
      if (ticket > 0) tim1 = GlobalVariableGet(Symbol() + "_tim1" + (Period() >= 30? "_240": "")); }
   t_Sent = ticket;        Bull = t_Sent && OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime() && ! OrderType();

   if (Period() >= 30 || (((Hour() == 10 && Minute() > 45) || Hour() == 11 || (Hour() == 12 && Minute() <= 15) ||
   (Hour() == 15 && Minute() > 45) || Hour() == 16 || (Hour() == 17 && Minute() <= 15)) && wins > 7 && itmp > 70)) {
      if ((iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 0) > 0.0 ||
      (tst=(iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 1) > 0.0 ||
      iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 2) > 0.0))) && ! t_Sent &&
      ! iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 0) &&
      ! iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 1) &&
      (! GlobalVariableCheck(Symbol() + "_M5_Sell") || ! GlobalVariableGet(Symbol() + "_M5_Sell") || (GlobalVariableGet(Symbol() + "_M5_Sell") < 0 &&
      GlobalVariableGet(Symbol() + "_M5_Buy") > 0 && GlobalVariableGet(Symbol() + "_M5_tim2") < GlobalVariableGet(Symbol() + "_M5_tim1"))) &&
      (tst || TimeCurrent() % (60 * Period()) > Period() * 180.0 / 4.0)) {
         ticket = OrderSend(Symbol(), 0, 0.01, Ask, 15, 0.99 * Ask, 0.0, NULL, Period() >= 30? 5555543: 5555542, 0, clrNONE);
         if (ticket > 0) { tim1 = TimeCurrent();         t_Sent = true;       Bull = true;
            if (iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 1) > 0.0)
               tim1 -= (TimeCurrent() % (60 * Period()) >= Period() * 30? 60: 30) * Period();
            if (iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 2) > 0.0)
               tim1 -= (TimeCurrent() % (60 * Period()) >= Period() * 30? 120: 90) * Period();
Alert("*** BUY! - " + IntegerToString(ticket) + " - " + Symbol() + " - " + Bull + " - " + TimeToStr(tim1, TIME_MINUTES) + " ***"); } }

      if ((iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 0) > 0.0 ||
      (tst=(iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 1) > 0.0 ||
      iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 2) > 0.0))) && ! t_Sent &&
      ! iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 0) &&
      ! iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 1) &&
      (! GlobalVariableCheck(Symbol() + "_M5_Buy") || ! GlobalVariableGet(Symbol() + "_M5_Buy") || (GlobalVariableGet(Symbol() + "_M5_Buy") < 0 &&
      GlobalVariableGet(Symbol() + "_M5_Sell") > 0 && GlobalVariableGet(Symbol() + "_M5_tim1") < GlobalVariableGet(Symbol() + "_M5_tim2"))) &&
      (tst || TimeCurrent() % (60 * Period()) > Period() * 180.0 / 4.0)) {
         ticket = OrderSend(Symbol(), 1, 0.01, Bid, 15, 1.01 * Bid, 0.0, NULL, Period() >= 30? 5555543: 5555542, 0, clrNONE);
         if (ticket > 0) { tim1 = TimeCurrent();         t_Sent = true;       Bull = false;
            if (iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 1) > 0.0)
               tim1 -= (TimeCurrent() % (60 * Period()) >= Period() * 30? 60: 30) * Period();
            if (iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 2) > 0.0)
               tim1 -= (TimeCurrent() % (60 * Period()) >= Period() * 30? 120: 90) * Period();
Alert("*** SELL! - " + IntegerToString(ticket) + " - " + Symbol() + " - " + Bull + " - " + TimeToStr(tim1, TIME_MINUTES) + " ***"); } } }

   if (t_Sent) { GlobalVariableSet(Symbol() + "_ticket" + (Period() >= 30? "_240": ""), ticket);
      GlobalVariableSet(Symbol() + "_tim1" + (Period() >= 30? "_240": ""), tim1);         GlobalVariableSet(Symbol() + "_Period", Period()); }

// dnTrend GBPJPY.i240 2022.12.08 08:00 O
   tst = false;      for (pos = ObjectsTotal()-1; pos >= 0 && ! tst && t_Sent; pos --) {
      datetime OTim2=0;       name = ObjectName(pos);       OTim1 = ObjectGet(name, OBJPROP_TIME1);      // type = ObjectType(name);
      tst = (StringSubstr(name, 0, 7) == "dnTrend" || StringSubstr(name, 0, 7) == "upTrend") && StringSubstr(name, 8, StringLen(Symbol())) == Symbol() &&
         floor(OTim2 / (60 * Period())) > floor(tim1 / (60 * Period())) && tim1 > 0 && floor(TimeCurrent() / (60 * Period())) - floor(OTim1 / (60 * Period())) < 720 / Period();
      if (tst && OTim1 > OTim2) OTim2 = OTim1; }
if (tst && OrdersTotal() && AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
   Alert("*** --Trend! - " + name + " - " + TimeToStr(OTim1, TIME_MINUTES) + " - " + TimeToStr(OTim2, TIME_MINUTES) + " - " + TimeToStr(tim1, TIME_MINUTES) + " ***");

   t_H4_M5 = Period() >= 30 && ((GlobalVariableGet(Symbol() + "_M5_Buy") && t_Sent && ! Bull) || (GlobalVariableGet(Symbol() + "_M5_Sell") && t_Sent && Bull));

   if (t_Sent && Bull && ((! iCustom(NULL,0,"Entry_Points_Pro.ex4","",1000,"",0,0,500,"",0,"","08:00","21:00","",1,90, 2, floor(TimeCurrent()/(60*Period())) - floor(tim1/(60*Period()))) &&
   tim1 > 0) || iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 0) > 0.0 ||
   tst || t_H4_M5) && OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime()) {      // 4/5 flèche grise
      t_Sent = ! OrderClose(ticket, 0.01, OrderType()? Ask: Bid, 15, clrNONE);            if (! t_Sent) {
Alert("*** BUY Closed! - " + IntegerToString(ticket) + " - " + Symbol() + " - " + Bull + " - " + tst + " - " + t_H4_M5 + " - " + TimeToStr(tim1, TIME_MINUTES) + " - " +
   (floor(TimeCurrent()/(60*Period())) - floor(tim1/(60*Period()))) + " ***");
         ticket = 0;       tim1 = 0;         if (t_H4_M5) GlobalVariableSet(Symbol() + "_M5_Sell", -1);           /* GlobalVariableSet(Symbol() + "_M5_tim2", 0); }*/ } }

   if (t_Sent && ! Bull && ((! iCustom(NULL,0,"Entry_Points_Pro.ex4","",1000,"",0,0,500,"",0,"","08:00","21:00","",1,90, 3, floor(TimeCurrent()/(60*Period())) - floor(tim1/(60*Period()))) &&
   tim1 > 0) || iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 0) > 0.0 ||
   tst || t_H4_M5) && OrderSelect(ticket, SELECT_BY_TICKET) && ! OrderCloseTime()) {      // 4/5 flèche grise
      t_Sent = ! OrderClose(ticket, 0.01, OrderType()? Ask: Bid, 15, clrNONE);            if (! t_Sent) {
Alert("*** SELL Closed! - " + IntegerToString(ticket) + " - " + Symbol() + " - " + Bull + " - " + tst + " - " + t_H4_M5 + " - " + TimeToStr(tim1, TIME_MINUTES) + " - " +
   (floor(TimeCurrent()/(60*Period())) - floor(tim1/(60*Period()))) + " ***");
         ticket = 0;       tim1 = 0;         if (t_H4_M5) GlobalVariableSet(Symbol() + "_M5_Buy", -1);            /* GlobalVariableSet(Symbol() + "_M5_tim1", 0); }*/ } }

   if (! ticket) { GlobalVariableSet(Symbol() + "_ticket" + (Period() >= 30? "_240": ""), 0);         GlobalVariableSet(Symbol() + "_tim1" + (Period() >= 30? "_240": ""), 0); }

   if ((GlobalVariableCheck(Symbol() + "_M5_Buy") && GlobalVariableGet(Symbol() + "_M5_Buy") && floor(TimeCurrent() / (60 * Period())) > floor(GlobalVariableGet(Symbol() + "_M5_tim1") / (60 * Period()))) ||
   ! iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 3, 0)) { GlobalVariableSet(Symbol() + "_M5_Buy", 0);        GlobalVariableSet(Symbol() + "_M5_tim1", 0); }
   if ((GlobalVariableCheck(Symbol() + "_M5_Sell") && GlobalVariableGet(Symbol() + "_M5_Sell") && floor(TimeCurrent() / (60 * Period())) > floor(GlobalVariableGet(Symbol() + "_M5_tim2") / (60 * Period()))) ||
   ! iCustom(NULL, 0, "Entry_Points_Pro.ex4", "", 1000, "", 0, 0, 500, "", 0, "", "08:00", "21:00", "", 1, 90, 2, 0)) { GlobalVariableSet(Symbol() + "_M5_Sell", 0);       GlobalVariableSet(Symbol() + "_M5_tim2", 0); } }

void OnDeinit(const int reason) {
  }
