/* Le fichier "Liste dObjets EA nr-0_BTC.mq4" est dans le rép. "\mes backups".
Il est identique au fichier "Liste dObjets EA nr-0.mq4" au moment de la création et modification de la version
utilisée "Liste dObjets EA nr-1_BTC.mq4" */
//#property strict         // sauvé dans "Liste dObjets EA (FH2).mq4" avant intégration de VM2 à partir de "Liste dObjets EA (FH2-VM2).mq4" option v_opfx
//#define v_opfx 1           // <=> v_VM2
#define v_opfx_0           // pour récupérer du code de "#ifdef v_opfx" qui concerne aussi "#ifndef v_opfx"
#define mkt_stocks         // marchés indices + cryptos + actions
extern double lot = 0.01;  // Taille des lots
extern int slip = 5;       // Taille du slippage
//extern int comm = 13;      // Commission (pipettes)
//extern int comm = 156;    // Commission (points BTC)
extern int nBars = 300;    // nombre de barres lues
#ifdef v_opfx_0
/*enum DayOWs {dimanche=0, lundi=1, mardi=2, mercredi=3, jeudi=4, vendredi=5};
extern DayOWs First_Day = 1; */     int First_Day = 0;
// nomenclature : marché=1 digit, support=2 digits, période=4 digits, type=1 digit
enum magic_nbs {CHN_60=50100600, HKG_60=50200600, SPX_60=50300600, AUS_60=50400600, 
   UKg_60=50500600, USx_60=50600600, GER_60=50700600, JPN_60=50800600, 
   EUS_60=10100600, BTC_60=20100600, GLD_60=30100600, BRT_60=30300600, 
   CJP_60=10200600, EGB_60=10300600, EJP_60=10400600, GJP_60=10500600, UTR_60=10600600, 
   NAS_60=50900600, FRA_60=51000600, EST_60=51100600, ITA_60=51200600, SUI_60=51300600, 
   CHN_60_lm=50100601, HKG_60_lm=50200601, SPX_60_lm=50300601, AUS_60_lm=50400601, 
   UKg_60_lm=50500601, USx_60_lm=50600601, GER_60_lm=50700601, JPN_60_lm=50800601, 
   EUS_60_lm=10100601, BTC_60_lm=20100601, GLD_60_lm=30100601, BRT_60_lm=30300601, 
   CJP_60_lm=10200601, EGB_60_lm=10300601, EJP_60_lm=10400601, GJP_60_lm=10500601, UTR_60_lm=10600601, 
   NAS_60_lm=50900601, FRA_60_lm=51000601, EST_60_lm=51100601, ITA_60_lm=51200601, SUI_60_lm=51300601};
extern bool magic_on = true;
extern magic_nbs magic_nb = 50100600;
//extern magic_nbs magic_lm = 50100601;
extern bool Fl_Trade = true;
#endif

//                test v iOPen/(iHigh+iLow)/2
bool ea_show=false, Op_OHL=true, Op_Show=false, Op_DDw=false, Op_HiLo=false, Op_Liq2=false, Op_Liq3=false, Op_Liq4=false#ifdef v_opfx_0, op_Liq_=false#endif,
      rate1c=false, rate2c=true, rate3c=false, rate4c=false#ifdef v_opfx, ha_Prev=false, ha_Buff=false, ha_Opt=false, Op_2xBl=false, Op_1xBl#endif, r_copyFtp=true;
int frameX=20, frameY=35, per_target, cpt=1, ticket, total2=0, total3=0, total2_, total3_, Op_Liqu=1, 
   r1_coporder, r2_coporder, r3_coporder, r4_coporder, cpt_wav=0, tmfr#ifdef v_opfx_0, so_cpt=0, r_coptime#endif;
bool t_clo_=false,t_blue=true,t_vilt=true,t_orge=true,bull_,pass1,endbull,St_Trd2,tr_allow=TerminalInfoInteger(TERMINAL_TRADE_ALLOWED);
datetime blue_time,blue_time2,blue_time3, vilt_time,vilt_time2,vilt_time3, orge_time,orge_time2, ADX_time;
double pips2dbl, WM=0, AccBalance, p_Coef, ha1Open, ha1Close, haOpen, haClose, haHigh, haLow;
string bar_Dirs[],bar_Dir, sym_target, LabelNameEnd,LabelNameEnd2,LabelNameStp, s1_coporder,s2_coporder,s3_coporder,s4_coporder, stmfr;
#ifndef v_opfx
double ExtOpenBuffer[], ExtCloseBuffer[]/*, ExtLowHighBuffer[], ExtHighLowBuffer[]*/;
datetime prevTimeCurrent=TimeCurrent(), last_liq_t1, last_liq_t2;
bool infoMarket;     double last_liq_pr, last_ntr_pr;
#else
string tmp3, s_name, s_coptime, str_DCC;
datetime prevTimeCurrent=TimeCurrent(), last_liq_t1, last_liq_t2;
bool infoMarket;     double last_liq_pr, last_ntr_pr, op_Liq_pr, op_Liq_sp;   //int prevMinute=0;
#endif
#ifdef v_opfx_0
string tmp3, s_name, s_coptime, str_DCC, LabelNameSt2;
string tck_vstr,bull_str,tmfr0_str,tmfr1_str,tmfr2_str,l_rct_str,Chart_str,t1_Chart_str,t2_Chart_str,t1_Bull_str,t2_Bull_str,t3_Bull_str,t4_Bull_str,i_Cht_str,t_ATS_str,p_Ver_str;
int prevMinute=0,prevMinut2=0,tmfr_,tmfr_b,t3,test0,test1,test2,HOp,Rect_Ks[50];          long Chart_M5;          string rect_str, Rect_Ns[50][2], EA_cht_str,EA_Ch2_str,EA_Ch3_str;
datetime tim_Chart_M5, tim_Chart_M5b, tim_Alt_M5, last_rect, next_vert, last_rct_=0, i_Cht_M5, curr_time, ATS_Time, tst_5c, tim_M15, tim_flt, tim_flt_=Time[0];
bool t5a_Bullish, t5b_Bullish, t5a_Bull_b, t5b_Bull_b, pass1b, t_night, t_h6, tst_5b, t_ngt0, ha_Shw=false, tmp_saved, t_TST1, t_TST2, Liqu_x2, t_M15_H1=false, t_M5_M15=false,
   OS1_tick=true, OS2_tick=true, OS3_tick=true, OS4_tick=true, OS5_tick=true, OS6_tick=true, OS9_tick=true, bull2, trd_on, fl_Trade=Fl_Trade, t_rsi51_, t_rsi515, tmf_Diff;
int sprd, comm, H1, H2, H3, H3_, diff, nb_ticks, Mg_N, nb_tcks_N, NR, rect_HG, haCoef=1, liqu_x2_n;      double SL, Rect_Hs[50][2], AccBalance_day;      // comm=13  (6+7)   spr2=20
#endif

#ifndef v_opfx
#include <Liste dObjets EA.mqh>
#ifdef v_opfx_0
#include <Enable current EA.mqh>
#endif
#else
#include <Liste dObjets (all).mqh>
#endif
#include <close_after_target_back.mqh>

void OnInit() { ObjectsDelete(1, ""#ifdef v_opfx_0,0, 1#endif);
//  EventSetMillisecondTimer(100);
#ifdef v_opfx if (! EventSetTimer(60))
//  infoMarket = DayOfWeek() < 6 && (DayOfWeek() || Hour() >= 23) && (DayOfWeek() < 5 || Hour() <= 23);
  infoMarket = DayOfWeek() < 6 && (DayOfWeek() || Hour() >= 23) && (DayOfWeek() < 5 || Hour() <= H3); #endif
  ChartSetInteger(0,CHART_SHOW_GRID,true);   ChartSetInteger(0,CHART_SHOW_PERIOD_SEP,true);
  ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrMidnightBlue);
#ifdef v_opfx
            GlobalVariableSet("_RateOC1", false);        GlobalVariableSet("_RateOC2", false);
            GlobalVariableSet("_RateOC3", true);         GlobalVariableSet("_RateOC4", false);
            GlobalVariableSet("_H_A_Opt", false);        GlobalVariableSet("_Op_Liqu", true);
            GlobalVariableSet("_op_HiLo", true);         GlobalVariableSet("_op_30p1", true);
            GlobalVariableSet("_op_20p1", true);         GlobalVariableSet("_op_20p2", true);
            GlobalVariableSet("_op_Exp",  false);        GlobalVariableSet("_Op_OHL",  true);
            GlobalVariableSet("_op_20p5", true);         GlobalVariableSet("_op_20p3", true);
            GlobalVariableSet("_op_20p4", true);         GlobalVariableSet("_op_30p2", true);
            GlobalVariableSet("_op_75p1", true);         GlobalVariableSet("_op_Exp1", false);
            GlobalVariableSet("_op_HiLo1", true);        GlobalVariableSet("_op_20p6", true);
            GlobalVariableSet("_op_Exp2", false);        GlobalVariableSet("_op_HiLo2", true);
            GlobalVariableSet("_op_20p7", true);         GlobalVariableSet("_Op_Liq2", false);
            GlobalVariableSet("_Op_Liq3", false);        GlobalVariableSet("_Op_Liq4", false);
            GlobalVariableSet("_op_HAp1", false);        GlobalVariableSet("_op_HAp2", false);
            GlobalVariableSet("_op_HAp3", false);        GlobalVariableSet("_H_A_Buff", false);
            GlobalVariableSet("_H_A_Prev", false);       GlobalVariableSet("_Op_2xBl", false);
            GlobalVariableSet("_Op_Case01", true);       GlobalVariableSet("_Op_Case02", false);
            GlobalVariableSet("_Op_Case03", false);      GlobalVariableSet("_Op_Case11", true);
            GlobalVariableSet("_Op_Case12", false);      GlobalVariableSet("_Op_Case13", false);
            GlobalVariableSet("_Op_Case21", true);       GlobalVariableSet("_Op_Case22", false);
            GlobalVariableSet("_Op_Case23", false);      GlobalVariableSet("_Op_Case24", false);
            GlobalVariableSet("_Op_Case25", false);      GlobalVariableSet("_Op_Case26", false);
#endif

//  if (GlobalVariableCheck("Op_OHL")) Op_OHL = GlobalVariableGet("Op_OHL");
  if (GlobalVariableCheck("Op_Show")) Op_Show = GlobalVariableGet("Op_Show");
  if (GlobalVariableCheck("Op_DDw")) Op_DDw = GlobalVariableGet("Op_DDw");
//  if (GlobalVariableCheck("Op_HiLo")) Op_HiLo = GlobalVariableGet("Op_HiLo");
  if (GlobalVariableCheck("frameX")) frameX = GlobalVariableGet("frameX");
  if (GlobalVariableCheck("frameY")) frameY = GlobalVariableGet("frameY");

#ifdef v_opfx_0
  ArrayResize(ExtOpenBuffer, nBars);      ArrayResize(ExtCloseBuffer, nBars);       HA_Buffers(1);
  p_Ver_str = "p-Ver_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));
  int p_version=GlobalVariableGet(p_Ver_str);      if (! GlobalVariableCheck(p_Ver_str) || f_Params(0) > p_version) f_Params(1);
  if (Hour() == H1 && ! Minute() && Seconds() < 17) { Alert("***** Heure NON PERMISE ! -> REDEMARRER *****");     Sleep(7000); }
  t_night = ((! Hour() || (Hour() < H1 && (H1 < H3 || Hour() > H3))) && (H1 < H3 || DayOfWeek()));       // 6
  tr_allow = TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && ! t_night;
  tck_vstr = "tck_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));   //+"_"+IntegerToString(Period());
  bull_str = "bullish_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));
  if (GlobalVariableCheck(tck_vstr)) ticket = GlobalVariableGet(tck_vstr);
  if (GlobalVariableCheck(bull_str)) bull_ = GlobalVariableGet(bull_str);           bool t_tick=(ticket > 7);
  if ((GlobalVariableCheck(tck_vstr) && (tr_allow || t_tick)) || (GlobalVariableCheck("Ticket0") && !tr_allow)) {
      if (! t_tick) ticket = tr_allow ? GlobalVariableGet(tck_vstr) : GlobalVariableGet("Ticket0");
      if (tr_allow || t_tick) { if (ticket <= 7) {
#else
  if (GlobalVariableCheck("Bullish")) bull_ = GlobalVariableGet("Bullish");
  if ((GlobalVariableCheck(tck_vstr) && tr_allow) || (GlobalVariableCheck("Ticket0") && !tr_allow)) {
      ticket = tr_allow ? GlobalVariableGet(tck_vstr) : GlobalVariableGet("Ticket0");
      if (tr_allow) { if (ticket <= 7) {
#endif
         if (mOrderSelect(mOrdersTotal(magic_nb)==1?0:2,SELECT_BY_POS)) ticket = OrderTicket();
         Print("*** -> (1) Ticket LOADED! ",ticket," - ... ***");#ifdef v_opfx_0    GlobalVariableSet(tck_vstr, ticket);#endif }
      if (OrderSelect(floor(ticket), SELECT_BY_TICKET) && !OrderCloseTime()) {
         endbull = ! OrderType();
         Print("*** -> (1) Ticket LOADED! ",ticket," - ",endbull? "Buy": "Sell"," - ",tr_allow," ***"); }
      else { Print("*** -> (1a) Ticket NOT LOADED! ",ticket," ***");     ticket = 0; } }
     else   endbull = bull_; }
  else Print("*** -> (1b) Ticket NOT LOADED! ",ticket," ***");

  BrokerDigitAdjust(Symbol());   pass1 = true;  pass1b = true;    NR = 0;
  CreateButton(0,0,"<>",1,frameX-18,frameY+1,0);
  CreateButton(0,0,"Show-EA",0,frameX,frameY,0);

  tmfr = Period();
  stmfr = tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
      tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1";
#ifdef v_opfx

  if (GlobalVariableCheck("_Op_HiLo")) Op_HiLo = GlobalVariableGet("_Op_HiLo");
  if (GlobalVariableCheck("_RateOC1")) rate1c = GlobalVariableGet("_RateOC1");
  if (! rate1c) { if (GlobalVariableCheck("_RateOC2")) rate2c = GlobalVariableGet("_RateOC2");
  if (! rate2c) { if (GlobalVariableCheck("_RateOC3")) rate3c = GlobalVariableGet("_RateOC3");
  if (! rate3c) if (GlobalVariableCheck("_RateOC4")) rate4c = GlobalVariableGet("_RateOC4"); } }
#endif
#ifdef v_opfx_0

  EA_cht_str = "EA_cht_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));
  EA_Ch2_str = "EA_Ch2_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));
  EA_Ch3_str = "EA_Ch3_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));
  t_ATS_str = "t-ATS_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));
  tmfr0_str = "tmfr0_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));      //+"_"+IntegerToString(Period());
  tmfr1_str = "tmfr1_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));      //+"_"+IntegerToString(Period());
  tmfr2_str = "tmfr2_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));      //+"_"+IntegerToString(Period());
  l_rct_str = "l_rct_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));      //+"_"+IntegerToString(Period());
  i_Cht_str = "t-Cht_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));      //+"_"+IntegerToString(Period());
  Chart_str = "Chart_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));      //+"_"+IntegerToString(Period());
  t1_Chart_str = "t1_Chrt_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol())); //+"_"+IntegerToString(Period());
  t2_Chart_str = "t2_Chrt_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol())); //+"_"+IntegerToString(Period());
  t1_Bull_str = "t1_Bull_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));  //+"_"+IntegerToString(Period());
  t2_Bull_str = "t2_Bull_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));  //+"_"+IntegerToString(Period());
  t3_Bull_str = "t3_Bull_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));  //+"_"+IntegerToString(Period());
  t4_Bull_str = "t4_Bull_"+StringSubstr(Symbol(),0,1)+StringSubstr(Symbol(),3,1)+IntegerToString(StringLen(Symbol()));  //+"_"+IntegerToString(Period());
  if (GlobalVariableCheck(l_rct_str)) last_rct_ = GlobalVariableGet(l_rct_str);
  if (GlobalVariableCheck(tmfr0_str)) tmfr = GlobalVariableGet(tmfr0_str);
  if (GlobalVariableCheck(tmfr1_str)) tmfr_ = GlobalVariableGet(tmfr1_str);
  if (GlobalVariableCheck(tmfr2_str)) tmfr_b = GlobalVariableGet(tmfr2_str);
  if (GlobalVariableCheck(Chart_str)) Chart_M5 = GlobalVariableGet(Chart_str);
  if (GlobalVariableCheck(t1_Chart_str)) tim_Chart_M5 = GlobalVariableGet(t1_Chart_str);
  if (GlobalVariableCheck(t2_Chart_str)) tim_Chart_M5b = GlobalVariableGet(t2_Chart_str);
  if (GlobalVariableCheck(t1_Bull_str)) t5a_Bullish = GlobalVariableGet(t1_Bull_str);
  if (GlobalVariableCheck(t2_Bull_str)) t5b_Bullish = GlobalVariableGet(t2_Bull_str);
  if (GlobalVariableCheck(t3_Bull_str)) t5a_Bull_b = GlobalVariableGet(t3_Bull_str);
  if (GlobalVariableCheck(t4_Bull_str)) t5b_Bull_b = GlobalVariableGet(t4_Bull_str);
  if (! Chart_M5 || ! chk_chartm5(0)) Chart_M5 = chart_find();    // (Period() == PERIOD_H1 || Period() == PERIOD_M30) && 
  else Alert("** Initialisation OK avec : " + Symbol() + " / " + IntegerToString(Period()) + " (Chart_M5=" + IntegerToString(Chart_M5) + " - " +
      IntegerToString(ChartPeriod(Chart_M5))+" / "+IntegerToString(ChartPeriod(Chart_M5+1))+" / "+IntegerToString(ChartPeriod(Chart_M5-1))+") **");
  if (Hour()>=HOp && tmfr != Period()) { ChartSetSymbolPeriod(0, NULL, ENUM_TIMEFRAMES(tmfr));    Sleep(50);
      copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)+" "+Symbol()+": ** Initial. OK1 "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" **");
      if (ENUM_TIMEFRAMES(tmfr) >= PERIOD_M30) { ChartSetInteger(0, CHART_SCALE, 0, 5);
//         Alert("** Initial. OK "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" **");
         ChartSetSymbolPeriod(Chart_M5, NULL, PERIOD_M5);      ChartSetInteger(Chart_M5, CHART_SCALE, 0, 4);
         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)+" "+Symbol()+": ** Initial. OK2 "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" **"); }
      else { ChartSetInteger(0, CHART_SCALE, 0, 4);      ChartSetInteger(Chart_M5, CHART_SCALE, 0, 5);
         if (tmfr == PERIOD_M1) ChartSetSymbolPeriod(Chart_M5, NULL, PERIOD_M5);       // v M1
         if (tmfr == PERIOD_M5) ChartSetSymbolPeriod(Chart_M5, NULL, ENUM_TIMEFRAMES(tmfr_));
         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)+" "+Symbol()+": ** Initial. OK3 "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" **"); } }

  if (GlobalVariableCheck("t_ngt_3")) t_ngt0 = GlobalVariableGet("t_ngt_3");
  if (GlobalVariableCheck("t_ngt_2") && Symbol() == "CHINAA50") t_ngt0 = GlobalVariableGet("t_ngt_2");
  GlobalVariableSet(EA_Ch2_str, ChartID());     GlobalVariableSet(EA_cht_str, Time[0]);      GlobalVariableSet(EA_Ch3_str, TimeCurrent());
  nb_ticks = 0;         nb_tcks_N = 0;
#endif
  return; }

void OnTick() { if (ea_show) { ObjectsDelete(0, ""#ifdef v_opfx_0, 0, 0#endif);
     if (GlobalVariableCheck("frameX")) frameX = GlobalVariableGet("frameX");
     CreateButton(0,0,"<>",1,frameX-18,frameY+1,0);     CreateButton(0,0,"Show-EA",0,frameX,frameY,0); }

#ifndef v_opfx
  if (GlobalVariableCheck("Op_HiLo")) Op_HiLo = GlobalVariableGet("Op_HiLo");
  if (GlobalVariableCheck("RateOC1")) rate1c = GlobalVariableGet("RateOC1");
  if (! rate1c) { if (GlobalVariableCheck("RateOC2")) rate2c = GlobalVariableGet("RateOC2");
  if (! rate2c) { if (GlobalVariableCheck("RateOC3")) rate3c = GlobalVariableGet("RateOC3");
  if (! rate3c) if (GlobalVariableCheck("RateOC4")) rate4c = GlobalVariableGet("RateOC4"); } }
#else
  if (prevMinute != Minute()) { r_coptime = copy_time("");
      prevMinute = Minute();        prevSecondTick = GetTickCount(); }

  if (TimeCurrent() % PERIOD_H1*60 < 3 && Period()==PERIOD_H1 && DCC_Check()) { tmfr = PERIOD_M30;
      ChartSetSymbolPeriod(0, NULL, PERIOD_M30);         GlobalVariableSet(tmfr0_str, tmfr);
      copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)+" "+Symbol()+": ***** PASSAGE EN M30 ! ("+str_DCC+") *****");
      Alert("***** PASSAGE EN M30 ! ("+str_DCC+") *****");        tmf_Diff = true; }

  if (! DayOfWeek() || (DayOfWeek()==1 && H1 < H3 && Hour() < H1-1) && Period() > PERIOD_M15) return;    // 5
#endif
#ifdef v_opfx_0

  bool EA_cht_W;                       if (Hour() < 5 && DayOfWeek() == 1) return;
  if (prevMinut2 != Minute() && Seconds() > 2 && GlobalVariableCheck(EA_cht_str)) {
      GlobalVariableSet(EA_Ch2_str, ChartID());
      if (! MQLInfoInteger(MQL_DLLS_ALLOWED)) GlobalVariableSet(EA_cht_str, 20);
      else { EA_cht_W = GlobalVariableGet(EA_cht_str);
         if (EA_cht_W) { GlobalVariableSet(EA_cht_str, 0);
            GlobalVariableSet(EA_Ch3_str, TimeCurrent());      prevMinut2 = Minute(); }
         if (GlobalVariableCheck("t_ngt_3")) t_ngt0 = GlobalVariableGet("t_ngt_3"); } }

  string str, temp;
  if (pass1b && GlobalVariableCheck("Enable_EA") && GlobalVariableGet("Enable_EA")) GlobalVariableSet("Enable_EA", 0.0);
  if (! MQLInfoInteger(MQL_DLLS_ALLOWED) && (! GlobalVariableCheck("Enable_DLL") || GlobalVariableGet("Enable_DLL") == 0.0)) {
      str = TimeToStr(Time[0], TIME_MINUTES);         Sleep(100);                // ResetLastError();
      GlobalVariableSet(EA_cht_str, 20);        GlobalVariableSet("Enable_DLL", 1.0);        GlobalVariableSet("Enable_DLL_mgn", Mg_N);
//      Enable_EA("", 0, 1);             FileMove("EA_Enabled.txt", FILE_COMMON, "EA_Not_Enabled.txt", FILE_COMMON);
      StringReplace(str, ":", "");     ChartSaveTemplate(0,"templates saved EA\\template_saved_"+StringSubstr(Symbol(),0,6)+" - "+str); }
/*      if (ChartApplyTemplate(0, "template_saved_"+StringSubstr(Symbol(), 0, 6))) { //GlobalVariableSet(EA_cht_str, 15.0);
         temp = "** EA -> ChartApplyTemplate OK: -> template_saved_" + StringSubstr(Symbol(), 0, 6) + " **";         Sleep(1000); }
      else temp = "***** EA -> ChartApplyTemplate failed error: "+GetLastError()+" - "+Symbol()+" - "+IntegerToString(ChartID())+" *****";
      Alert(temp);      copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } */
  if (! MQLInfoInteger(MQL_DLLS_ALLOWED) || (! MQLInfoInteger(MQL_TRADE_ALLOWED) && TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))) {
      if (Enable_EA("temp EA "+Symbol()+".set", 1, 0)) temp = "***** "+Symbol()+" - Toggle Expert Advisor button ON *****";
      else     temp = "***** "+Symbol()+" - Toggle Expert Advisor button OFF *****";
      Alert(temp);      copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
      if (MQLInfoInteger(MQL_DLLS_ALLOWED)) return; }
  else if (Mg_N != round(magic_nb / 100000)) { if (Enable_EA("temp EA "+Symbol()+".set", 0, 0))
         temp = "***** "+Symbol()+" - Mg_N != round(magic_nb / 100000) -> OK *****";
      else     temp = "***** "+Symbol()+" - Error: Mg_N != round(magic_nb / 100000) *****";
      Alert(temp);      copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
      if (MQLInfoInteger(MQL_DLLS_ALLOWED)) return; }
  else if (GlobalVariableGet("Enable_DLL_mgn") == Mg_N && GlobalVariableGet("Enable_DLL") == 1.0) {
      GlobalVariableSet("Enable_DLL", 0.0);           GlobalVariableSet("Enable_DLL_mgn", 0.0); }
  if (MQLInfoInteger(MQL_DLLS_ALLOWED) && FileIsExist("EA_Not_Enabled.txt", 0)) FileMove("EA_Not_Enabled.txt", 0, "EA_Enabled.txt", 0);

  if (pass1b) chk_chartm5(1);     if (StringTrimLeft(ChartSymbol(Chart_M5)) == "" || ! int(Chart_M5)) {   //Sleep(1000);
      if (tim_Alt_M5 < Time[0]) if (! int(Chart_M5)) Alert("*** CHART M5 ABSENT ! "+Symbol()+" - "+IntegerToString(Chart_M5)+" ***");
         else Print("** PAS D'ACCES AU CHART M5 ! "+Symbol()+" - "+IntegerToString(Chart_M5)+" **");         tim_Alt_M5 = Time[0];
      if ((! int(Chart_M5) || ! chk_chartm5(2)) && (Period()==PERIOD_H1 || Period()==PERIOD_M30 || pass1b)) Chart_M5 = chart_find();
      if (pass1b) { datetime t_L_Objs7;      if (int(StringSubstr(TimeToStr((t_L_Objs7=tim_L_Objs7(Chart_M5)), TIME_MINUTES), 0, 2)) < 6)
            t_L_Objs7 = StrToTime(IntegerToString(Year())+"."+IntegerToString(Month())+"."+IntegerToString(Day())+" 00:00");
         if (! int(tim_Chart_M5) && (Period() == PERIOD_M5 || Period() == PERIOD_M15)) {
            tmfr_ = PERIOD_H1;         GlobalVariableSet(tmfr1_str, tmfr_);
            tim_Chart_M5 = Chart_M5 > 0? t_L_Objs7: TimeCurrent()-8*3600;     GlobalVariableSet(t1_Chart_str, tim_Chart_M5); }
         if (! int(tim_Chart_M5b) && Period() == PERIOD_M1) {
            tmfr_b = PERIOD_M5;        GlobalVariableSet(tmfr2_str, tmfr_b);
            tim_Chart_M5b = Chart_M5 > 0? t_L_Objs7: TimeCurrent()-8*3600;    GlobalVariableSet(t2_Chart_str, tim_Chart_M5b); } } }

  str = "-" + StringSubstr(EnumToString(magic_nb), 0, 3);
  if (!FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) && !FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0))
      FileCopy("ATS-Ind_On-Off\\ATS-Ind5_Sell.txt", 0, "ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0);
  bool tst, tst2, t_night_, tr_allow_;          int t=0, t1=0, t2=0, err;            // 6
  if (Hour() < H1 && (H1 < H3 || Hour() > H3) && t_h6) { t_h6 = false;  t_ngt0 = false;   GlobalVariableSet("t_ngt_1", 0);    H3 = H3_; }
  else if (Hour() == H1 && (H1 < H3 || DayOfWeek() < 5)) { if (! time_allow) { time_allow = true;     nb_ticks = 0;     nb_tcks_N = 0; }
      t_M5_M15 = false;    t_M15_H1 = false;    if (H1 > H3 && GlobalVariableCheck("t_ngt_2") && str == "-CHN") t_ngt0 = GlobalVariableGet("t_ngt_2"); }
  if (H1 > H3 && (t_night_ != t_night || tr_allow_ != tr_allow)) { t_night_ = t_night;       tr_allow_ = tr_allow; }
  t_night = t_ngt0 || (((H1 < H3 && diff && Hour() == H3 && Minute() > diff) || ! Hour() || (DayOfWeek() == 5 && ((Hour() == 16 && 
      Minute() > 39) || Hour() > 16)) || (Hour() < H1 && (H1 < H3 || Hour() >= H3)) || (!t_h6 && !t_ngt0 && Hour() == H1 && ((H1 < H3 && ! Minute() && 
      Seconds() < 17) || (H1 > H3 && Hour() == H1 && (Minute() < 40 || (Minute() == 40 && Seconds() < 17)))))) && (H1 < H3 || DayOfWeek()));    // 6
  if (H1 > H3 && t_night != t_night_) Print("** Suivi de t_night et tr_allow (1) : "+Symbol()+" / "+IntegerToString(Period())+" - t_night = "+t_night+" - tr_allow = "+tr_allow+" **");
  if (((! Hour() && H1 < H3) || Hour() < HOp || (Hour() >= H1 && H1 > H3 && (str != "-CHN" || Seconds() > 4)) || (last_rct_==Time[0] && Period()>=PERIOD_M30)) &&
   ((Period() >= PERIOD_M15 || (str == "-HKG" && Period() >= PERIOD_M5)) && ! t_M5_M15 && ! t_M15_H1)) { tmfr_ = Period()==PERIOD_M30? Period(): PERIOD_H1;
      while(! (tst=ChartSetSymbolPeriod(0, NULL, str=="-HKG"?PERIOD_M1:PERIOD_M5)) && t1 < 17) { t1 ++;   Sleep(100); }     err = GetLastError();
      if (tst) { //while((! Chart_M5 || ! int(ChartPeriod(Chart_M5))) && t2 < 17) { t2 ++;     Chart_M5 = chart_find();   Sleep(100); }
         if (! chk_chartm5(3)) { temp = "*** ERROR Chart_M5 (3) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***";
            Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
         Sleep(50);      ChartSetInteger(0, CHART_SCALE, 0, 4);             tmfr = str == "-HKG"? PERIOD_M1: PERIOD_M5;
         while(! ChartSetSymbolPeriod(Chart_M5, NULL, ENUM_TIMEFRAMES(tmfr_)) && t2 < 17) { t2 ++;    Sleep(100); }
         Sleep(50);           ChartSetInteger(Chart_M5, CHART_SCALE, 0, 5);         int err2 = GetLastError();
         tim_Chart_M5 = TimeCurrent();       GlobalVariableSet(t1_Chart_str, tim_Chart_M5);
         t5a_Bullish = bull_;                t5b_Bullish = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0);
         GlobalVariableSet(t1_Bull_str, t5a_Bullish);    GlobalVariableSet(t2_Bull_str, t5b_Bullish);
         GlobalVariableSet(tmfr1_str, tmfr_);            GlobalVariableSet(tmfr0_str, tmfr); }     if (last_rct_ < Time[0] && H1 > H3) t_night = true;
      if (tst) { temp = "** Passage en "+(str=="-HKG"?"M1":"M5")+" à "+IntegerToString(fmax(H1,H3))+" H ! (Period()="+IntegerToString(Period())+", t1="+
            IntegerToString(t1) + ", t2=" + IntegerToString(t2) + (t2==17 ? ", err2=" + IntegerToString(err2) : "") + ") **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
      else { if (Period()>PERIOD_M1) Print("*** Erreur - Passage en M5 à "+IntegerToString(fmax(H1,H3))+" H ! (Period()=" + IntegerToString(Period()) +
         ", t1=" + IntegerToString(t1) + ", err1=" + IntegerToString(err) + ") ***");         Sleep(100); }
      if (last_rct_ == Time[0]) { temp = "***** last_rct_ (1) -> while(! (tst=ChartSetSymbolPeriod(0, && DrawArrow_OS(6, *****";
            Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }
  if (str == "-HKG" && Hour() == HOp && Minute() > 30 && Period() == PERIOD_M1) { t1 = 0;
      GlobalVariableSet(tmfr0_str, PERIOD_M5);     while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M5)) && t1 < 17) { t1 ++;      Sleep(100); }
      if (tst) { temp = "** Passage en M5 à "+IntegerToString(HOp)+" H ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }

//  while (StringTrimLeft(ChartSymbol(Chart_M5)) == "" && t < 11) { Sleep(200);    t ++; }
  t = 0;    t1 = 0;     if ((str != "-HKG" && str != "-CHN") || Hour() > 8) while(! tst && t < 17) {
   if ((Hour()>=HOp && (Period()==PERIOD_M5 || Period()==PERIOD_M15) && TimeCurrent() % PERIOD_M5*60 < 7 && tim_Chart_M5 > 0 && 
   TimeCurrent()-tim_Chart_M5 > tmfr_*60*8 && m3_RSI(PERIOD_M5, 2) > 40 && m3_RSI(PERIOD_M5, 2) < 60) ||
   (tst2 = (Period() == PERIOD_M15 && m3_RSI(0, 2) > 35 && m3_RSI(0, 2) < 65 &&
   nb_ticks > 2 && nb_ticks == nb_tcks_N + 1))) {     // ou tester la présence d'un rectangle ATS
      if (! chk_chartm5(4)) { temp = "*** ERROR Chart_M5 (4) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***";
         Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
      if ((StringTrimLeft(ChartSymbol(Chart_M5)) != "" && ((t5b_Bullish == FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) &&
      bull_ == t5a_Bullish) || (t5b_Bullish != FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) && bull_ != t5b_Bullish))) || tst2) {
         while(! (tst=ChartSetSymbolPeriod(0, NULL, Hour()==HOp && !Minute()? PERIOD_H1: ENUM_TIMEFRAMES(tmfr_))) && t1 < 17) { t1 ++;  Sleep(100); }
         if (Hour() == HOp && ! Minute()) GlobalVariableSet(tmfr0_str, PERIOD_H1);
         err = GetLastError();      if (tst && tmfr_ > 0) { Sleep(50);        ChartSetInteger(0, CHART_SCALE, 0, 5);
//            while((! Chart_M5 || ! int(ChartPeriod(Chart_M5))) && t2 < 17) { t2 ++;    Chart_M5 = chart_find();   Sleep(100); }
            if (! chk_chartm5(5)) { temp = "*** ERROR Chart_M5 (5) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***";
               Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
            t2 = 0;     while(! ChartSetSymbolPeriod(Chart_M5, NULL, PERIOD_M5) && t2 < 17) { t2 ++;      Sleep(100); }
            Sleep(50);           ChartSetInteger(Chart_M5, CHART_SCALE, 0, 4);         t_M15_H1 = true;
            temp = "** REPASSAGE EN M30 / H1 ! ("+IntegerToString(tmfr_)+", t5a_Bullish = "+IntegerToString(t5a_Bullish)+", t5b_Bullish = "+IntegerToString(t5b_Bullish)+
               ", t = "+IntegerToString(t)+", t1 = "+IntegerToString(t1)+", t2 = "+IntegerToString(t2)+(t2==17? ", err2 = "+IntegerToString(GetLastError()): "")+") **";
            Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
            tim_Chart_M5 = 0;       GlobalVariableSet(t1_Chart_str, tim_Chart_M5);
            tmfr = tmfr_;           GlobalVariableSet(tmfr0_str, tmfr); }
         else { temp = "*** ERREUR - REPASSAGE EN M30 / H1 ! ("+Symbol()+" - " +(tmfr_?"":"*")+IntegerToString(tmfr_)+(tmfr_?"":"*")+ ", t1 = " +
               IntegerToString(t1) + ", t = " + IntegerToString(t) + ", err1 = " + IntegerToString(err) + ") ***";
            Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } } }
   else if (Period()==PERIOD_M1 && TimeCurrent() % PERIOD_M1*60 < 3 && tim_Chart_M5b > 0 && TimeCurrent()-tim_Chart_M5b > tmfr_b*60 * 4) {
      if (! chk_chartm5(6)) { temp = "*** ERROR Chart_M5 (6) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***";
         Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
      if (StringTrimLeft(ChartSymbol(Chart_M5)) != "" && ((t5b_Bull_b == FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) &&
      bull_ == t5a_Bull_b) || (t5b_Bull_b != FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) && bull_ != t5b_Bull_b))) {
         while(! (tst=ChartSetSymbolPeriod(0, NULL, ENUM_TIMEFRAMES(tmfr_b))) && t1 < 17) { t1 ++;      Sleep(100); }     err = GetLastError();
         if (tst && tmfr_b > 0) { Sleep(50);       ChartSetInteger(0, CHART_SCALE, 0, 4);
//            while((! Chart_M5 || ! int(ChartPeriod(Chart_M5))) && t2 < 17) { t2 ++;    Chart_M5 = chart_find();   Sleep(100); }
            if (! chk_chartm5(7)) { temp = "*** ERROR Chart_M5 (7) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***";
               Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
            t2 = 0;     while(! ChartSetSymbolPeriod(Chart_M5, NULL, ENUM_TIMEFRAMES(tmfr_)) && t2 < 17) { t2 ++;       Sleep(100); }
            Sleep(50);           ChartSetInteger(Chart_M5, CHART_SCALE, 0, 5);
            temp = "** REPASSAGE EN M5 ! (" + IntegerToString(tmfr_b) + ", t5a_Bull_b = "+IntegerToString(t5a_Bull_b) + ", t5b_Bull_b = "+IntegerToString(t5b_Bull_b) +
               ", t1 = "+IntegerToString(t1) + ", t2 = "+IntegerToString(t2) + (t2==17 ? ", err2 = " + IntegerToString(GetLastError()) : "") + ") **";
            Alert(temp);            copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
            tim_Chart_M5b = 0;      GlobalVariableSet(t2_Chart_str, tim_Chart_M5b);
            tmfr = tmfr_b;          GlobalVariableSet(tmfr0_str, tmfr); }
         else { temp = "*** ERREUR - REPASSAGE EN M5 ! ("+Symbol()+" - " +(tmfr_b?"":"*")+IntegerToString(tmfr_b)+(tmfr_b?"":"*")+ ", t1 = " +
               IntegerToString(t1) + ", t = " + IntegerToString(t) + ", err1 = " + IntegerToString(err) + ") ***";
            Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } } }
   else   tst = true;    if (! tst) Sleep(100);    t ++; }
   if (tst2) { temp = "** Sortie de boucle M30 / H1 ! (" + IntegerToString(tmfr_) + ", t = " + IntegerToString(t) + ", t1 = "+IntegerToString(t1) +
         ", t2 = " + IntegerToString(t2) + (t2 == 17? ", err2 = " + IntegerToString(GetLastError()): "") + ") **";      tst2 = false;
      Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }

  tr_allow = TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && ! t_night;
  if (H1 > H3 && tr_allow != tr_allow_) Print("** Suivi de t_night et tr_allow (2) : "+Symbol()+" / "+IntegerToString(Period())+" - t_night = "+t_night+" - tr_allow = "+tr_allow+" **");
#endif
  if (GlobalVariableCheck("Show_EA")) ea_show = GlobalVariableGet("Show_EA");
  if (GlobalVariableCheck("Op_Liq2")) Op_Liq2 = GlobalVariableGet("Op_Liq2");
//  if (GlobalVariableCheck("Op_Liq3")) Op_Liq3 = GlobalVariableGet("Op_Liq3");
  if (GlobalVariableCheck("Op_Liq4")) Op_Liq4 = GlobalVariableGet("Op_Liq4");

  bool strTot=(Point==0.01);        double myLot=0.01;
  int obj_total=ObjectsTotal(), i, j, k=0, k_, p=0, exp_1=0, exp_2=0#ifdef v_opfx, MrktVal, HighVal=0, DDwnVal=0, HiLoVal#endif;
  int obj_bar_cl, obj_bar_cl2, obj_bar_cl3, prv_pos=0, total=0, total0, hightotal=0, drawdown=0, ntot, obj_bar_liq[];   //, type
  int obj_bars[], obj_pos[], obj_pos0[], obj_reOps[][2], reOpn_brs[], reClo_brs[];           // obj_prClots[][2]
  string name,name_, obj_liqTypes[], obj_liqTyps2[], obj_liqTyp_1="", obj_liqTyp_2="";
  double drawdwnp,obj_Prices[],obj_prClots[],reOpn_prs[],reClo_prs[],obj_Levels[]#ifdef v_opfx, params[5]#endif#ifdef v_opfx_0,obj_LiqPrs[][2]#endif;
  datetime OTim1, OTim2, obj_Neutrals[];  bool t_neutral=false, t_liquid_b=false, t_liquid_s=false, t_neutral0, t_liquid_b0, t_liquid_s0;
  ArrayResize(obj_bars, obj_total);       ArrayResize(obj_pos, obj_total);       ArrayResize(obj_pos0, obj_total);
  ArrayResize(obj_reOps, obj_total);      ArrayResize(obj_Prices, obj_total);    ArrayResize(obj_prClots, obj_total);
  ArrayResize(obj_Levels, obj_total);     ArrayResize(reOpn_prs, obj_total);     ArrayResize(reClo_prs, obj_total);
  ArrayResize(reOpn_brs, obj_total);      ArrayResize(reClo_brs, obj_total);     ArrayResize(obj_Neutrals, obj_total);
  ArrayResize(obj_liqTypes, obj_total);   ArrayResize(obj_bar_liq, Bars);#ifdef v_opfx_0  ArrayResize(obj_LiqPrs, obj_total)#endif;
  string nam_B, nam_S, str1, str2, nam_B2, nam_S2, nam_B3, nam_S3, nam_B4, nam_S4;
#ifndef v_opfx
  bool bull, haBull, habull, pos_prem=true, lastliq, lastliq_=true;    //, tst
#else
  if (Op_Liq2) ArrayResize(obj_liqTyps2, obj_total);
  bool bull, haBull, pos_prem=true, tst2=false, lastliq, lastliq_=true;
//  if (GlobalVariableCheck("Bullish")) bull_ = GlobalVariableGet("Bullish");
#endif
//  if (GlobalVariableCheck(bull_str)) bull_ = GlobalVariableGet(bull_str);
  if (bull_==NULL && bull_!=false) Print("** TEST mode strict -> (bull_==NULL && bull_!=false) **");

#ifdef v_opfx_0
  if (GlobalVariableCheck(tck_vstr)) ticket = GlobalVariableGet(tck_vstr);      bool t_tick=(ticket > 7);
  if ((ticket <= 7 && (mOrdersTotal(magic_nb)==1 || mOrdersTotal(magic_nb)==3) && tr_allow) ||
  (! tr_allow && ! t_tick && GlobalVariableCheck("Ticket0") && (ticket=GlobalVariableGet("Ticket0")) > 0)) {
   if ((GlobalVariableCheck(tck_vstr) && (tr_allow || t_tick)) || (GlobalVariableCheck("Ticket0") && !tr_allow)) {
      if (! t_tick) ticket = tr_allow ? GlobalVariableGet(tck_vstr) : ticket;
      if (tr_allow || t_tick) { if (ticket <= 7) {
#else
  if ((ticket <= 7 && (mOrdersTotal(magic_nb)==1 || mOrdersTotal(magic_nb)==3) && tr_allow) ||
  (! tr_allow && GlobalVariableCheck("Ticket0") && (ticket=GlobalVariableGet("Ticket0")) > 0)) {
   if ((GlobalVariableCheck(tck_vstr) && tr_allow) || (GlobalVariableCheck("Ticket0") && !tr_allow)) {
      ticket = tr_allow ? GlobalVariableGet(tck_vstr) : ticket;
      if (tr_allow) { if (ticket <= 7) {
#endif
         if (mOrderSelect(mOrdersTotal(magic_nb)==1?0:2,SELECT_BY_POS)) ticket = OrderTicket();
         Print("*** -> (2) Ticket LOADED! ",ticket," - ... ***");#ifdef v_opfx_0    GlobalVariableSet(tck_vstr, ticket);#endif }
       if (OrderSelect(floor(ticket), SELECT_BY_TICKET) && !OrderCloseTime()) {
         endbull = ! OrderType();
         Print("*** -> (2) Ticket LOADED! ",ticket," - ",endbull? "Buy": "Sell"," - ",tr_allow," ***"); }
       else Print("*** -> (2a) Ticket NOT LOADED! ",ticket," ***"); }
      else   endbull = bull_; }
   else Print("*** -> (2b) Ticket NOT LOADED! ",ticket," ***"); }
//    confirmer manuellement avec une option par click      | v ou MessageBox()     (+ possiblilité d'inverser bull_)      ***
//  if (! OrdersTotal() && ticket) { Print("** --> Ticket CHANGED! (OnTick) ",ticket," -> 0 ***");      ticket = 0; }      ***
  next_vert = 0;     for (int pos = 0; pos < obj_total; pos ++) {
     OTim2 = 0;      name = ObjectName(pos);       //type = ObjectType(name);
     t_neutral0 = t_neutral;   t_liquid_b0 = t_liquid_b;   t_liquid_s0 = t_liquid_s;   //iTime(NULL,0,0)
#ifdef v_opfx_0
     if (StringFind(name, "ertical") > 0 && ObjectGet(name, OBJPROP_TIME1) > Time[0] && ObjectGet(name, OBJPROP_COLOR) == clrRed && 
         (! int(next_vert) || ObjectGet(name, OBJPROP_TIME1) < next_vert)) next_vert = ObjectGet(name, OBJPROP_TIME1);
     if (StringFind(name, "rect") > 0) { if (ObjectGet(name, OBJPROP_TIME2) == Time[0]) {  // ATS V2.0 Userrect1612950600
            name_ = name;     if (cpt_wav < 2) { PlaySound("0294.wav");       cpt_wav ++; } }
         if (ObjectGet(name_, OBJPROP_TIME2) < Time[1]) cpt_wav = 0; }   //*/
     if (StringFind(name, "rect") > 0) { last_rect = ObjectGet(name, OBJPROP_TIME2);      rect_str = name; }
#endif
     if ((t_neutral=(StringFind(name, "neutral") > 0)) ||
     (t_liquid_b=(StringFind(name, "liquid_buy") > 0)) || (t_liquid_s=(StringFind(name, "liquid_sell") > 0))) {
        if ((! t_neutral0 && t_neutral) || (! t_liquid_b0 && t_liquid_b) || (! t_liquid_s0 && t_liquid_s)) i = 0;
        OTim1 = ObjectGet(name,OBJPROP_TIME1);
        while (OTim1 > OTim2 && i < Bars) { OTim2 = iTime(NULL,0,Bars-(i+1));   i ++; }
// Time[0] = bougie en cours  |  Time[Bars-1] = bougie la plus ancienne du chart
        if (t_neutral) { obj_Neutrals[pos] = OTim1;      obj_bars[pos] = i;     obj_pos[p] = pos;     obj_pos0[p] = pos;
            obj_liqTypes[pos] = (ObjectType((nam_B=StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr
               (name, StringFind(name, "tral")+4))) > 0 ? "Buy" : (ObjectType((nam_S=StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+
                  "liquid_sell"+StringSubstr(name, StringFind(name, "tral")+4))) > 0 ? "Sell" : "Error"));
            obj_Prices[pos] = (iOpen(NULL,0,Bars-i) * (rate1c? 5.0: rate2c? 4.0: rate3c? 3.0: rate4c? 2.0: 1.0) +
                  iClose(NULL,0,Bars-i) * (rate1c? 1.0: rate2c? 2.0: rate3c? 3.0: rate4c? 4.0: 5.0)) / 6.0;
#ifndef v_opfx_0
            if (ObjectType((nam_B=StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name, 
#else
            if ((Liqu_x2=(ObjectType((nam_B=StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name, 
#endif
               StringFind(name, "tral")+4))) > 0 && ObjectType((nam_S=StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+
               "liquid_sell"+StringSubstr(name, StringFind(name, "tral")+4))) > 0)#ifdef v_opfx_0))#endif { str1 = obj_liqTypes[pos];     str2 = obj_liqTyp_1;
                  if (Op_HiLo) Print("*** -> 2 liquid lines | ",pos," - ",(Bars-i)," - ",obj_Prices[pos]," - ",StringToUpper(str1)," - ",
                     StringToUpper(str2)," - barre : ",TimeToStr(Time[Bars-i],TIME_DATE|TIME_MINUTES)," ***");
                  obj_liqTypes[pos] = Op_Liqu? Op_Liqu==1? obj_liqTyp_1: Op_Liqu==2? obj_liqTyp_1=="Sell"? "Buy": "Sell": //(obj_bars[pos]-obj_bars[pos-1]==1 ||
                  obj_bars[pos]-obj_bars[pos-1]<=2 && obj_liqTyp_1==obj_liqTyp_2? obj_liqTyp_1=="Sell"? "Buy": "Sell": obj_liqTyp_1: "Error-2";
/* Print("****** (1) ", obj_liqTypes[pos], " ", (Bars - i), " ", iClose(NULL,0,Bars-i), " ", Op_Liqu, " ", obj_bars[pos-1], " ", obj_bars[pos], " ", obj_liqTyp_1, " ", obj_liqTyp_2, " ******");
DrawArrow(iClose(NULL,0,Bars-i)+500*Point, Bars-i, 3, obj_liqTypes[pos]=="Buy", 0);
DrawArrow(iClose(NULL,0,Bars-i)+500*Point, Bars-i, 5, obj_liqTypes[pos]=="Buy", 0); //*/
                  if (Bars - i > 1) { tst = false;
                     haBull = (Op_Liqu && HA_Bull(1, iOpen(NULL,0,Bars-i-2), iClose(NULL,0,Bars-i-2), iHigh(NULL,0,Bars-i-2), iLow(NULL,0,Bars-i-2), Bars-i-2, NULL)
                        && Op_Liq3 && HA_Bull(1, iOpen(NULL,0,Bars-i-1), iClose(NULL,0,Bars-i-1), iHigh(NULL,0,Bars-i-1), iLow(NULL,0,Bars-i-1), Bars-i-1, NULL));
                     if (haBull && obj_liqTypes[pos] == "Sell") { obj_liqTypes[pos] = "Buy";      tst = true; }
                     else { haBull = (Op_Liqu && !HA_Bull(1, iOpen(NULL,0,Bars-i-2), iClose(NULL,0,Bars-i-2), iHigh(NULL,0,Bars-i-2), iLow(NULL,0,Bars-i-2), Bars-i-2, NULL)
                           && Op_Liq3 && !HA_Bull(1, iOpen(NULL,0,Bars-i-1), iClose(NULL,0,Bars-i-1), iHigh(NULL,0,Bars-i-1), iLow(NULL,0,Bars-i-1), Bars-i-1, NULL));
                        if (haBull && obj_liqTypes[pos] == "Buy") { obj_liqTypes[pos] = "Sell";      tst = true; } }
                     if (tst) { total0 -= fabs(iClose(NULL,0,Bars-i-2) - obj_Prices[pos]) * 2 + comm; }     //nb_pos ++; }
/* Print("****** (2) ", obj_liqTypes[pos], " ", (Bars - i), " ", iClose(NULL,0,Bars-i), " ", haBull, " ", tst, " ******");
DrawArrow_pf(iClose(NULL,0,Bars-i)+300*Point, Bars-i, 3, obj_liqTypes[pos]=="Buy", 0);
DrawArrow_pf(iClose(NULL,0,Bars-i)+300*Point, Bars-i, 5, obj_liqTypes[pos]=="Buy", 0); //*/
                      } }
            if (Op_Liq2) { str1 = obj_liqTyps2[pos] == NULL? obj_liqTypes[pos] == "Buy"? "Sell": obj_liqTypes[pos] == "Sell"? "Buy": "-": 
                              obj_liqTyps2[pos] == "Buy" ? "Sell" : obj_liqTyps2[pos] == "Sell" ? "Buy" : "-";
               j = 1;      while ((obj_liqTyps2[pos-j]==NULL? obj_liqTypes[pos-j]: obj_liqTyps2[pos-j]) == obj_liqTypes[pos]) j ++;   tst = false;
               if (obj_liqTypes[pos-j] == str1) { tst = true;        temp = ObjectName(pos-j);
                  nam_B2 = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8))+"liquid_buy"+StringSubstr(temp, StringFind(temp, "tral")+4);
                  nam_S2 = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8)) + "liquid_sell" + StringSubstr(temp, StringFind(temp, "tral") + 4); }
/*if (pos == 57) Print("*1* "+obj_liqTypes[pos]+" - "+obj_liqTypes[pos-1]+" - "+obj_liqTypes[pos-2]+" - "+obj_liqTypes[pos-3]+" - "+obj_liqTypes[pos-j]+" - "+
   IntegerToString(j)+" - "+IntegerToString(Bars-i)+" - "+nam_B2+" - "+nam_S2+" - "+temp+" - "+tst+" - "+DoubleToStr(iLow(NULL,0,Bars-i),5)+" - "+
   DoubleToStr(iHigh(NULL,0,Bars-i),5)+" - "+DoubleToStr(ObjectGet(nam_B2,OBJPROP_PRICE1),5)+" - "+DoubleToStr(ObjectGet(nam_S2,OBJPROP_PRICE1),5)+" ***");//*/
               j ++;       while ((obj_liqTyps2[pos-j]==NULL? obj_liqTypes[pos-j]: obj_liqTyps2[pos-j]) == obj_liqTypes[pos]) j ++;
               if (obj_liqTypes[pos-j] == str1) { tst = true;        temp = ObjectName(pos-j);
                  nam_B3 = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8))+"liquid_buy"+StringSubstr(temp, StringFind(temp, "tral")+4);
                  nam_S3 = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8)) + "liquid_sell" + StringSubstr(temp, StringFind(temp, "tral") + 4); }
/*if (pos == 57) Print("*2* "+obj_liqTypes[pos]+" - "+obj_liqTypes[pos-j]+" - "+obj_liqTypes[pos-j-1]+" - "+obj_liqTypes[pos-j-2]+" - "+obj_liqTypes[pos-j-3]+" - "+
   IntegerToString(j)+" - "+nam_B3+" - "+nam_S3+" - "+temp+" - "+tst+" - "+DoubleToStr(ObjectGet(nam_B3,OBJPROP_PRICE1),5)+" - "+DoubleToStr(ObjectGet(nam_S3,OBJPROP_PRICE1),5)+" ***");//*/
               j ++;       while ((obj_liqTyps2[pos-j]==NULL? obj_liqTypes[pos-j]: obj_liqTyps2[pos-j]) == obj_liqTypes[pos]) j ++;                 /* voir en option ***
-> avec deux autres options Op_Instit et Op_LiqRange : - Op_Instit pour identifier les liquidity lines proches d'un instit avec une nam_B/S3 proche d'une nam_B/S4, ce qui fera 
   déclancher l'ordre plus proche de l'instit (~ -3 pips) plutôt que dès l'apparition de l'expansion line (ou point) -> voir "Capture d'écran 2021-01-14 à 18.53.59 : 23.20.26.png"
   - Op_LiqRange pour inverser tous les ordersend après une inversion de type Op_Liq2 sur obj_liqTypes[pos], en utilisant un flag_Range plutôt qu'une inversion de la liquidity line ;
   ainsi tous les trades inversés après la liquidity line concernée correspondront à du trading de Range, délimité par la liquidity line supérieure et la liquidity line inférieure
   -> fin du Range sur sortie d'une des deux bornes avec un stop à -10 pips ou après la prochaine liquidity line non inversée par Op_Liq2
   - pour le backtest je peux aussi voir le timeframe inférieur (-1 ou -2) pour voir à quel moment / niveau plus précis est apparue la liquidity line concernée */
               if (obj_liqTypes[pos-j] == str1) { tst = true;        temp = ObjectName(pos-j);
                  nam_B4 = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8))+"liquid_buy"+StringSubstr(temp, StringFind(temp, "tral")+4);
                  nam_S4 = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8)) + "liquid_sell" + StringSubstr(temp, StringFind(temp, "tral") + 4); } }
/*if (pos == 57) Print("*3* "+obj_liqTypes[pos]+" - "+obj_liqTypes[pos-j]+" - "+obj_liqTypes[pos-j-1]+" - "+obj_liqTypes[pos-j-2]+" - "+obj_liqTypes[pos-j-3]+" - "+
   IntegerToString(j)+" - "+nam_B4+" - "+nam_S4+" - "+temp+" - "+tst+" - "+DoubleToStr(ObjectGet(nam_B4,OBJPROP_PRICE1),5)+" - "+DoubleToStr(ObjectGet(nam_S4,OBJPROP_PRICE1),5)+" ***"); }//*/
/*            if (Op_Liq2 && (fabs(obj_liqTyp_1=="Buy"? iLow(NULL,0,Bars-i): iHigh(NULL,0,Bars-i) - ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_PRICE1)) < 100*Point
               || fabs(obj_liqTyp_1=="Buy"? iLow(NULL,0,Bars-i): iHigh(NULL,0,Bars-i) - ObjectGet((obj_liqTypes[pos-2]=="Buy"?nam_B3:nam_S3),OBJPROP_PRICE1)) < 100*Point) &&
               ((obj_liqTyp_1 == "Buy" && iLow(NULL,0,Bars-i) < obj_Prices[pos-1]) || (obj_liqTyp_1 == "Sell" && iHigh(NULL,0,Bars-i) > obj_Prices[pos-1]))) { */
#ifdef v_opfx
            int lq_spr = 100 * Period() / 60;
#endif
            if ((Op_Liq2 && ((fabs((obj_liqTyp_1=="Buy"? iLow(NULL,0,Bars-i): iHigh(NULL,0,Bars-i)) - ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_PRICE1)) < #ifdef v_opfx
            lq_spr * Point #else 100*Point #endif &&
               ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_TIME2) - ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_TIME1) > Period() * 120 &&  // <- ||
               fabs(ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_PRICE1) - ObjectGet(ObjectName(pos-1),OBJPROP_PRICE1)) >#ifndef v_opfx 100 #else lq_spr #endif* Point) ||
//               fabs(ObjectGet((obj_liqTypes[pos]=="Buy"?nam_B:nam_S),OBJPROP_PRICE1) - ObjectGet(name, OBJPROP_PRICE1)) > 100 * Point) ||                 // voir en option **
               (fabs((obj_liqTyp_1=="Buy"? iLow(NULL,0,Bars-i): iHigh(NULL,0,Bars-i)) - ObjectGet((obj_liqTypes[pos-2]=="Buy"?nam_B3:nam_S3),OBJPROP_PRICE1)) < #ifdef v_opfx
            lq_spr * Point #else 100*Point #endif &&
               ObjectGet((obj_liqTypes[pos-2]=="Buy"?nam_B3:nam_S3),OBJPROP_TIME2) - ObjectGet((obj_liqTypes[pos-2]=="Buy"?nam_B3:nam_S3),OBJPROP_TIME1) > Period() * 120 &&  // <- ||
               fabs(ObjectGet((obj_liqTypes[pos-2]=="Buy"?nam_B3:nam_S3),OBJPROP_PRICE1) - ObjectGet(ObjectName(pos-2),OBJPROP_PRICE1)) >#ifndef v_opfx 100 #else lq_spr #endif* Point)) &&
//               fabs(ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_PRICE1) - ObjectGet(ObjectName(pos-1),OBJPROP_PRICE1)) > 100 * Point)) &&   // voir en option **
               ((obj_liqTyp_1 == "Buy" && iLow(NULL,0,Bars-i) < obj_Prices[pos-1]) || (obj_liqTyp_1 == "Sell" && iHigh(NULL,0,Bars-i) > obj_Prices[pos-1]))) && tst) {
                  obj_liqTyps2[pos] = obj_liqTypes[pos];    obj_liqTypes[pos] = obj_liqTyp_1;         if (Bars-i > 1) { tst = false;
                  haBull = Op_Liq4 && HA_Bull(1, iOpen(NULL,0,Bars-i-2), iClose(NULL,0,Bars-i-2), iHigh(NULL,0,Bars-i-2), iLow(NULL,0,Bars-i-2), Bars-i-2, NULL)
                     && HA_Bull(1, iOpen(NULL,0,Bars-i-1), iClose(NULL,0,Bars-i-1), iHigh(NULL,0,Bars-i-1), iLow(NULL,0,Bars-i-1), Bars-i-1, NULL) &&
                     obj_liqTyp_1=="Sell" && iHigh(NULL,0,Bars-i-2) - ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_PRICE1) > 70 * Point; // <- voir pos-2..?nam_B3:nam_S3
                  if (haBull && obj_liqTypes[pos] == "Sell") { obj_liqTypes[pos] = "Buy";      tst = true; }
                  else { haBull = Op_Liq4 && !HA_Bull(1, iOpen(NULL,0,Bars-i-2), iClose(NULL,0,Bars-i-2), iHigh(NULL,0,Bars-i-2), iLow(NULL,0,Bars-i-2), Bars-i-2, NULL)
                        && !HA_Bull(1, iOpen(NULL,0,Bars-i-1), iClose(NULL,0,Bars-i-1), iHigh(NULL,0,Bars-i-1), iLow(NULL,0,Bars-i-1), Bars-i-1, NULL) &&
                        obj_liqTyp_1=="Buy" && iLow(NULL,0,Bars-i-2) - ObjectGet((obj_liqTypes[pos-1]=="Buy"?nam_B2:nam_S2),OBJPROP_PRICE1) < -70 * Point;  // <- voir pos-2..?nam_B3:nam_S3
                     if (haBull && obj_liqTypes[pos] == "Buy") { obj_liqTypes[pos] = "Sell";      tst = true; } }
                  if (tst) { total0 -= fabs(iClose(NULL,0,Bars-i-2) - obj_Prices[pos]) * 2 + comm; }     //nb_pos ++; }
                  else  obj_bar_liq[pos] = Bars - i; } }
            if (obj_liqTyp_1 == obj_liqTyp_2 && obj_liqTyp_1 != "") { k ++;     for (j=1; j<=k; j++) obj_pos[p-j] = pos; }
            else   k = 0;                    // groupe activé ou pas, possible meilleur résultat sans mais avec fort drawdown -> *(1)*
#ifdef v_opfx_0
            obj_LiqPrs[pos][0] = ObjectGet((obj_liqTypes[pos]=="Buy"?nam_B:nam_S),OBJPROP_PRICE1);
#endif
            obj_Levels[pos] = (ObjectGet((obj_liqTypes[pos]=="Buy"?nam_B:nam_S),OBJPROP_PRICE1)+ObjectGet(name,OBJPROP_PRICE1))/2.0;
            obj_liqTyp_2 = obj_liqTyp_1;     obj_liqTyp_1 = obj_liqTypes[pos];      p ++; }
/*        total += (prv_pos ? (obj_liqTypes[pos] == "Buy" && obj_liqTypes[prv_pos] == "Sell" ? 1 :      // sans les commissions
            (obj_liqTypes[prv_pos] == "Buy" && obj_liqTypes[pos] == "Sell" ? -1 : 0)) * (obj_Prices[prv_pos]-obj_Prices[pos])/Point : 0);
        Print (pos, " object ("+IntegerToString(type)+") ", name, " description= "+ObjectDescription(name)+" * "+
            TimeToStr(OTim1,TIME_DATE|TIME_SECONDS)+"-"+TimeToStr(OTim2,TIME_DATE|TIME_SECONDS)+"-"+DoubleToStr(iOpen(NULL,0,Bars-i),5)+
            "-("+IntegerToString(i)+")-"+(ObjectType(StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name, 
            StringFind(name, "tral")+4)) > 0 ? "Buy" : (ObjectType(StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+"liquid_sell"+
            StringSubstr(name, StringFind(name, "tral")+4)) > 0 ? "Sell" : t_neutral?"Error":"liquid"))+"-"+ObjectGet(name,OBJPROP_PRICE1)+"-"+
            TimeToString(ObjectGet(name,OBJPROP_TIME2),TIME_DATE|TIME_SECONDS)+"-"+ObjectGet(name,OBJPROP_PRICE2)+"-"+
            DoubleToStr(obj_Prices[pos],5)+"-"+(ObjectType(StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+
            StringSubstr(name, StringFind(name, "tral")+4)) > 0 ? DoubleToStr((obj_Prices[pos]-ObjectGet(name,OBJPROP_PRICE1))/Point,0) :
            (ObjectType(StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_sell"+StringSubstr(name, StringFind(name, "tral")+4))>0 ?
            DoubleToStr((ObjectGet(name,OBJPROP_PRICE1)-obj_Prices[pos])/Point,0) : 0))+" | "+IntegerToString(prv_pos)+" - "+
            DoubleToStr(obj_Prices[prv_pos], 5)+" - "+IntegerToString((prv_pos ? (obj_liqTypes[pos] == "Buy" && obj_liqTypes[prv_pos] == "Sell"? 1: 
            (obj_liqTypes[prv_pos] == "Buy" && obj_liqTypes[pos] == "Sell" ? -1 : 0)) * (obj_Prices[prv_pos]-obj_Prices[pos])/Point : 0))+
            " - "+IntegerToString(total)+" *");
            if ((obj_liqTypes[pos] == "Buy" && obj_liqTypes[prv_pos] != "Buy") ||
               (obj_liqTypes[pos] == "Sell" && obj_liqTypes[prv_pos] != "Sell")) prv_pos = pos;     //*/
     }  }   k = 0;      #ifndef v_opfx_0 p = 0;#endif      total = total0;      // prv_pos = 0;            // <- remettre si | est remis
#ifdef v_opfx_0
  if (last_rct_ < last_rect) { last_rct_ = last_rect;    copy_file_(0, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS) + "." +
      IntegerToString(getCurrentMs()%1000)+" ** - RECTANGLE : "+IntegerToString(Period())+" - "+TimeToStr(ObjectGet(rect_str, OBJPROP_TIME1), 
      TIME_DATE|TIME_MINUTES)+" - "+TimeToStr(last_rect, TIME_DATE|TIME_MINUTES)+" - "+TimeToStr(Time[0], TIME_DATE|TIME_MINUTES)+" **");
      GlobalVariableSet(l_rct_str, last_rct_); }
  temp = ObjectName(obj_pos0[p-1]);
  nam_B = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8)) + "liquid_buy" + StringSubstr(temp, StringFind(temp, "tral") + 4);
  nam_S = StringSubstr(temp, 0, (StringSubstr(temp,5,1)==2?13:8)) + "liquid_sell" + StringSubstr(temp, StringFind(temp, "tral") + 4);
  last_liq_pr = ObjectGet((obj_liqTypes[obj_pos0[p-1]]=="Buy"?nam_B:nam_S),OBJPROP_PRICE1);
  last_liq_t1 = ObjectGet((obj_liqTypes[obj_pos0[p-1]]=="Buy"?nam_B:nam_S),OBJPROP_TIME1);
  last_liq_t2 = ObjectGet((obj_liqTypes[obj_pos0[p-1]]=="Buy"?nam_B:nam_S),OBJPROP_TIME2);
  if ((last_liq_pr==0 || last_liq_t2==0) && (TimeCurrent() - Time[0] < 3 || StringSubstr(temp, 0, 3) == "ATS"))
      Print("*** Erreur sur last_liq_pr ou last_liq_t2. " + DoubleToStr(last_liq_pr,Digits()) + " " + DoubleToStr(ObjectGet(temp,OBJPROP_PRICE1),Digits()) +
         " " + TimeToStr(last_liq_t1, TIME_DATE|TIME_SECONDS) + " " + TimeToStr(last_liq_t2, TIME_DATE|TIME_SECONDS) + " \"" +
         temp + "\" \"" + nam_B + "\" \"" + nam_S + "\" ***");
#endif
  last_ntr_pr = ObjectGet(temp, OBJPROP_PRICE1);      lastliq = tst && lastliq_;       p = 0;
  bool op_case01=GlobalVariableGet("Op_Case01");      // à replacer ailleurs

//  CreateLabel(1.0907,153,0,"   "+DoubleToStr((iClose(NULL,0,153)-iOpen(NULL,0,Bars-i+1))/Point,0)+
//      " "+DoubleToStr(((obj_liqTypes[pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i+1) - iOpen(NULL,0,Bars-i+1)))/Point,0),0,1);
  int pX=80, pY=45, pos_bar_cl;    bool tst1#ifndef v_opfx_0, tst2#endif;     //double vScale=(WindowPriceMax()-WindowPriceMin())/(1.154-1.061);
  double vScale=(WindowPriceMax()-WindowPriceMin())/(!WindowPriceMax()?1.154:WindowPriceMax())/1.154/(1.154-1.061);
  for (pos=0; pos<obj_total; pos++) if (obj_liqTypes[pos] == "Error") { exp_1 ++;
         CreateLabel0(obj_Levels[pos],Bars-obj_bars[pos],"- NO LIQUID LINE - "+IntegerToString(pos)+" *",0,0,0); }   // && Op_HiLo
      else if (obj_liqTypes[pos] == "Error-2") { exp_2 ++;
         CreateLabel0(obj_Levels[pos],Bars-obj_bars[pos],"- 2 LIQUID LINES - "+IntegerToString(pos)+" *",0,0,0); }   // && Op_HiLo
      else if (obj_liqTypes[pos] == "Buy" || obj_liqTypes[pos] == "Sell") {
      obj_reOps[pos][1] = 0;     name = ObjectName(pos);    k_ = k;
      bool t_clo=false;    for (i=obj_bars[pos]+1; i<obj_bars[obj_pos[p+1]] && ! t_clo; i ++) { obj_prClots[pos] = iClose(NULL,0,Bars-i);
         if (iCustom(NULL, PERIOD_H1, "New folder\\ADX.ex4", 0, Bars-i) > 45 || op_case01)
//         haBull = HA_Bull(iOpen(NULL,0,Bars-i+2), iClose(NULL,0,Bars-i+2), iOpen(NULL,0,Bars-i+1), iClose(NULL,0,Bars-i+1), 
//            iHigh(NULL,0,Bars-i+1), iLow(NULL,0,Bars-i+1), iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i));
#ifndef v_opfx
            t_clo = f_mqh_code(0, pos, prv_pos, i, obj_liqTypes[pos], obj_prClots[pos], 0, 0);                                                     // * MQH *
#else
         if (iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) { Print("*** Error High - Low! (1) "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");   continue; }  //Period()<=5 && 
         else if (! obj_bar_liq[pos] || Bars - i > obj_bar_liq[pos] + 2) {
            haBull = HA_Bull(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
            if ((ha_Prev || !ha_Buff || !((haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell"))) && (obj_bars[pos+1] > i || !Op_2xBl))
               t_clo = f_mqh_code_EA(0,pos,prv_pos,i,obj_liqTypes[pos],obj_prClots[pos],0,0,params,HighVal,MrktVal,HiLoVal,DDwnVal); }                         // * MQH *
#endif
         if (ea_show && t_clo) { //&& (!prv_pos || (obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell"))) {
            DrawArrow(obj_prClots[pos], Bars-i, 3, 0, 1);         DrawArrow(obj_prClots[pos], Bars-i, 5, 0, 1); }       // 1er niveau de sortie en bleu
         if (ea_show && !(iHigh(NULL,0,Bars-i) - iLow(NULL,0,Bars-i))) CreateLabel0(iOpen(NULL,0,Bars-i),Bars-i,"- HIGH() = LOW() - "+DoubleToStr(iOpen(NULL,0,  // && Op_HiLo
            Bars-i),4)+" - "+DoubleToStr(iHigh(NULL,0,Bars-i),4)+" - "+DoubleToStr(iLow(NULL,0,Bars-i),4)+" - "+DoubleToStr(iClose(NULL,0,Bars-i),4)+" *",0,0,0); }
//      obj_prClots[pos][0] = (!prv_pos || (obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell"));
      if (!prv_pos || (obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell")) obj_bar_cl = Bars-i+(t_clo?1:0);
      if (! ((obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell"))) { obj_bar_cl3 = obj_bar_cl2;
             obj_bar_cl2 = Bars-i+(t_clo?1:0); }
      if (! t_clo) obj_prClots[pos] = obj_Prices[obj_pos[p+1]];         // -> (1 || *(1)*             // FXChoice -> levier = 1:200
      total += (prv_pos ? (obj_liqTypes[pos] == "Buy" && obj_liqTypes[prv_pos] == "Sell" ? 1 :        // commission = $0.06 = 0.6 pips
//         (obj_liqTypes[prv_pos] == "Buy" && obj_liqTypes[pos] == "Sell" ? -1 : 0)) * (obj_Prices[prv_pos]-obj_Prices[pos])/Point - 6 : 0);
         (obj_liqTypes[prv_pos] == "Buy" && obj_liqTypes[pos] == "Sell" ? -1 : 0)) * (obj_Prices[prv_pos]-obj_prClots[prv_pos]) / Point -
         ((obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell") ? 1 : 0) * comm : 0);
//      string stotal = DoubleToStr((obj_Prices[prv_pos]-obj_prClots[prv_pos]),5)+" "+IntegerToString(total0)+" "+IntegerToString(total);
      if ((obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell")) {
         if (bull == NULL) bull = (obj_liqTypes[prv_pos] == "Buy");
         DrawArrow(((bull=(obj_liqTypes[pos]=="Buy")) ? obj_Levels[prv_pos]+100*vScale*Point : obj_Levels[prv_pos]+250*vScale*Point), Bars-obj_bars[prv_pos], 0, bull, 0);
         if (ea_show) { DrawArrow(obj_Prices[prv_pos], Bars-obj_bars[prv_pos], 3, !bull, 0);     DrawArrow(obj_Prices[prv_pos], Bars-obj_bars[prv_pos], 5, !bull, 0);
//         DrawArrow(iOpen(NULL,0,Bars-obj_bars[prv_pos]), Bars-obj_bars[prv_pos], 1, !bull, 0);
           CreateLabel(obj_Levels[prv_pos],Bars-obj_bars[prv_pos],pos,!bull,"   px: "+DoubleToStr(obj_Prices[prv_pos],5)+" "+DoubleToStr(obj_prClots[prv_pos],5),0,0);
           CreateLabel(obj_Levels[pos],Bars-obj_bars[pos],pos,bull,"   total: "+DoubleToStr(total,0)+" (pipettes)",1,0); }/*
         CreateLabel(obj_Levels[pos],Bars-obj_bars[pos],pos,bull,"   -> "+stotal,2,0);*/ }
      else {      // dans ce bloc la logique d'apparition des flèches est différente par rapport au précédent (-> prv_pos)
         temp = (total ? "intermédiaire" : "départ");
         if (ea_show) { DrawArrow(obj_Prices[pos], Bars-obj_bars[pos], 3, pos_prem?!bull:bull, 0);    DrawArrow(obj_Prices[pos], Bars-obj_bars[pos], 5, pos_prem?!bull:bull, 0); }
         if (obj_bar_cl >= Bars-obj_bars[pos] && pos_bar_cl > obj_bar_cl2 && (! obj_bar_cl3 || obj_bar_cl3 > obj_bar_cl2)
            && obj_prClots[pos])                            // revoir peut-être le cas iClose()
            total += (total ? (obj_liqTypes[pos] == "Buy" ? -1 : (obj_liqTypes[pos] == "Sell" ? 1 : 0)) * ((pos_bar_cl>=Bars-obj_bars[pos]? (!obj_bar_cl3 || obj_bar_cl3>Bars-obj_bars[pos]? 
               obj_Prices[pos]: iClose(NULL,0,obj_bar_cl3)): iClose(NULL,0,obj_bar_cl3>pos_bar_cl?pos_bar_cl:obj_bar_cl3)) - obj_prClots[pos]) / Point - (pos_bar_cl>Bars-obj_bars[pos]? comm: 0): 0);
         if (ea_show && obj_bar_cl >= Bars-obj_bars[pos] && pos_bar_cl > obj_bar_cl2 && (! obj_bar_cl3 || obj_bar_cl3 > obj_bar_cl2)) // v surveiller les flèches intermédiaires après sortie OS 4 **
//         if (obj_bar_cl > Bars-obj_bars[pos] && pos_bar_cl > obj_bar_cl2 && pos_bar_cl > Bars-obj_bars[pos] && pos_bar_cl < Bars-obj_bars[obj_pos0[p]] && (! obj_bar_cl3 || obj_bar_cl3 > obj_bar_cl2))
            DrawArrowInt(obj_Levels[pos]+(bull ? 100*vScale*Point : 250*vScale*Point), Bars-obj_bars[pos], 0, pos_prem?!bull:bull);
         total0 = (total ? 0 : (obj_liqTypes[pos] == "Buy" ? -1 : (obj_liqTypes[pos] == "Sell" ? 1 : 0)) * (obj_Prices[pos] - obj_prClots[pos]) / Point - comm);     if (ea_show && Op_Show) 
         if (ea_show) CreateLabel(obj_Levels[pos],Bars-obj_bars[pos],pos,!bull,"  total: "+DoubleToStr(total? total: total0,0)+" ("+temp+") "+IntegerToString(Bars-obj_bars[pos])+" "+IntegerToString(obj_bar_cl),1,2);
/*      total0 = total;      // avant la ligne < if (obj_bar_cl >= Bars-obj_bars[pos]) > et < total += (total ? ...>
      stotal = DoubleToStr(obj_Prices[pos],5)+" "+DoubleToStr(obj_prClots[pos],5)+" "+DoubleToStr(Point,5);     // avant < CreateLabel(obj_Levels[pos],...>
      string stotal2 = DoubleToStr((obj_Prices[pos] - obj_prClots[pos]),5)+" "+IntegerToString(total0)+" "+IntegerToString(total);   // idem
         CreateLabel(obj_Levels[pos],Bars-obj_bars[pos],pos,!bull,"   -> "+stotal,2,2);      CreateLabel(obj_Levels[pos],Bars-obj_bars[pos],pos,!bull,"   -> "+stotal2,3,2); */ }
//      Print (pos, " (1) object ", ObjectName(pos), " | ", (ObjectType(StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name,StringFind(name,"tral")+4)) 
//         > 0 ? "Buy " : (ObjectType(StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+"liquid_sell"+StringSubstr(name, StringFind(name, "tral")+4)) > 0 ? "Sell" : "Err ")), " ",
//         prv_pos, " - ", obj_Prices[prv_pos], " - ", obj_prClots[prv_pos][1], " - ", obj_Prices[pos], " - ", pos, " - ", obj_pos[p+1], " - ", p, " - total : ", total, " *");
      if ((obj_liqTypes[pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[pos]=="Sell")) pos_prem = false;
      if (hightotal < total) hightotal = total;          else if (drawdown > total - hightotal) { drawdown = total - hightotal;
            if (hightotal) drawdwnp = (drawdown*1.0 / hightotal*1.0) * 100.0; }
      if (t_clo) { //CreateLabel0(iOpen(NULL,0,Bars-obj_bars[obj_pos0[p+1]]),Bars-obj_bars[obj_pos0[p+1]],"- test reOps - "+IntegerToString(pos)+" *",0,0,0);     // -> (0 && *(1)*
         if (ea_show && !((obj_liqTypes[obj_pos0[p+1]]=="Buy" && obj_liqTypes[obj_pos0[p]]=="Sell") || (obj_liqTypes[obj_pos0[p]]=="Buy" && obj_liqTypes[obj_pos0[p+1]]=="Sell")) && Op_Show) 
            CreateLabel0(iOpen(NULL,0,Bars-obj_bars[obj_pos0[p+1]]),Bars-obj_bars[obj_pos0[p+1]],"- test reOps - "+IntegerToString(pos)+"*"+IntegerToString(obj_pos0[p])+
               "*"+IntegerToString(obj_pos0[p+1])+"*"+IntegerToString(obj_pos[p])+"-"+IntegerToString(obj_pos[p+1])+" *",0,0,0);
         bool t_opn=false;     while (i < obj_bars[obj_pos0[p+1]]) { reOpn_prs[k] = 0.0;   reClo_prs[k] = 0.0;             //int t_clo2=0,t_clo3=0;
          t_clo=false;   for (i=i; i<obj_bars[obj_pos0[p+1]] && !t_clo; i ++) { reOpn_prs[k] = iClose(NULL,0,Bars-i);      //(iOpen(NULL,0,Bars-i) * 5.0 + ...) / 6.0
//            haBull = HA_Bull(iOpen(NULL,0,Bars-i+2), iClose(NULL,0,Bars-i+2), iOpen(NULL,0,Bars-i+1), iClose(NULL,0,Bars-i+1), 
//               iHigh(NULL,0,Bars-i+1), iLow(NULL,0,Bars-i+1), iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i));
#ifndef v_opfx
            t_clo = f_mqh_code(1, pos, prv_pos, i, obj_liqTypes[pos], 0, reOpn_prs[k], 0); }          // boucle des reOps Label_Arrow_Test(Type= 1,      // * MQH *
#else
            if (iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) { Print("*** Error High - Low! (2) "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");   continue; }  //Period()<=5 && 
            else { haBull = HA_Bull(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
               if (ha_Prev || !ha_Buff || (haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell"))
                  t_clo = f_mqh_code_EA(1,pos,prv_pos,i,obj_liqTypes[pos],0,reOpn_prs[k],0,params,HighVal,MrktVal,HiLoVal,DDwnVal);                            // * MQH *
               if (ha_Prev && ha_Buff) { haBull = HA_Bull(1, iOpen(NULL,0,Bars-i-1), iClose(NULL,0,Bars-i-1), iHigh(NULL,0,Bars-i-1), iLow(NULL,0,Bars-i-1), Bars-i-1, NULL);
                  if ((haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell")) { t_clo = false;
                     total -= (prv_pos ? fabs(iClose(NULL,0,Bars-i-1) - iClose(NULL,0,Bars-i)) / Point + comm : 0); } } } }      // boucle des reOps Label_Arrow_Test(Type= 1,
#endif
          if (t_clo) { //if (t_clo2 < 13) { t_clo2 ++;   Label_Arrow_Test(1,pos,p,i,k,reOpn_prs[k],!bull,pX,pY,total,obj_pos0,obj_pos);   pY += 34; }
            if (ea_show) { DrawArrowInt(iClose(NULL,0,Bars-i+1), Bars-i+1, 3, true);         DrawArrowInt(iClose(NULL,0,Bars-i+1), Bars-i+1, 5, true); }
            t_clo = false;   t_opn = true;                                                   // boucle de recherche des reCls Label_Arrow_Test(Type= 2,
            for (i=i; i<(obj_bars[obj_pos0[p+1]]>j? obj_bars[obj_pos0[p+1]]: obj_bars[obj_pos[p+1]]) && ! t_clo; i ++) {
               reClo_prs[k] = iClose(NULL,0,Bars-i);        reClo_brs[k] = i;
//               haBull = HA_Bull(iOpen(NULL,0,Bars-i+2), iClose(NULL,0,Bars-i+2), iOpen(NULL,0,Bars-i+1), iClose(NULL,0,Bars-i+1), 
//                  iHigh(NULL,0,Bars-i+1), iLow(NULL,0,Bars-i+1), iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i));
#ifndef v_opfx
               t_clo = f_mqh_code(2, pos, prv_pos, i, obj_liqTypes[pos], 0, 0, reClo_prs[k]); }                                                    // * MQH *
#else
               if (iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) { Print("*** Error High - Low! (3) "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");   continue; }  //Period()<=5 && 
               else { haBull = HA_Bull(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
                  if (ha_Prev || !ha_Buff || !((haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell")))
                     t_clo = f_mqh_code_EA(2,pos,prv_pos,i,obj_liqTypes[pos],0,0,reClo_prs[k],params,HighVal,MrktVal,HiLoVal,DDwnVal);                         // * MQH *
                  if (ha_Prev && ha_Buff) { haBull = HA_Bull(1, iOpen(NULL,0,Bars-i-1), iClose(NULL,0,Bars-i-1), iHigh(NULL,0,Bars-i-1), iLow(NULL,0,Bars-i-1), Bars-i-1, NULL);
                     if ((haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell")) { t_clo = false;
                        total -= (prv_pos ? fabs(iClose(NULL,0,Bars-i-1) - iClose(NULL,0,Bars-i)) / Point + comm : 0); } } } }
#endif
            if (ea_show && t_clo) { //&& t_clo3 < 13) { t_clo3 ++;    Label_Arrow_Test(2,pos,p,i,k,reClo_prs[k],bull,pX,pY,total,obj_pos0,obj_pos);     pY += 34; }
               DrawArrowInt(iClose(NULL,0,Bars-i+1), Bars-i+1, 3, false);        DrawArrowInt(iClose(NULL,0,Bars-i+1), Bars-i+1, 5, false); }
            if (! t_clo) reClo_prs[k] = obj_Prices[obj_bars[obj_pos0[p+1]]>j? obj_pos0[p+1]: obj_pos[p+1]];
            pos_bar_cl = Bars-i+(t_clo?1:0); }        k ++; }                                                  // fin de boucle While **
         obj_reOps[pos][0] = obj_reOps[obj_pos[p-1]==obj_pos[p]?obj_pos[p-2]:obj_pos[p-1]][1];
         obj_reOps[pos][1] = k - 1;    if (! obj_reOps[pos][0] && prv_pos) obj_reOps[pos][0] = k_ - 1;
         if (t_opn) { tst1 = (obj_liqTypes[pos] == "Buy");// && (! prv_pos || obj_liqTypes[prv_pos] == "Sell"));     // -> (0 && *(1)*
            tst2 = (obj_liqTypes[pos] == "Sell");  //(! prv_pos || obj_liqTypes[prv_pos] == "Buy") && 
            for (int l=obj_reOps[pos][0]+(obj_reOps[pos][0]?1:0); l<=obj_reOps[pos][1]; l ++) if (reClo_prs[l]) {   // ou  && reClo_prs[l]
               total += (tst1 ? -1 : (tst2 ? 1 : 0)) * (reOpn_prs[l] - reClo_prs[l]) / Point - (tst1 || tst2 ? 1 : 0) * comm;       if (ea_show && Op_Show) 
               CreateLabel(reClo_prs[l],Bars-reClo_brs[l],pos,!bull,"   px:"+DoubleToStr(reClo_prs[l],5)+" tot: "+DoubleToStr(total,0)+" - "+IntegerToString(pos)+" - "+IntegerToString(l),0,1);/*
      total0 = total;      // avant la ligne < total += (tst1 ? ...> et < total += (prv_pos ? ...>
      stotal = DoubleToStr(reOpn_prs[l],5)+" "+DoubleToStr(reClo_prs[l],5)+" "+DoubleToStr(Point,5);     // avant < CreateLabel(reClo_prs[l],...>
      string stotal2 = DoubleToStr((reOpn_prs[l] - reClo_prs[l]),5)+" "+IntegerToString(total0)+" "+IntegerToString(total);   // idem
         CreateLabel(reClo_prs[l],Bars-reClo_brs[l],pos,!bull,"   -> "+stotal,1,1);
         CreateLabel(reClo_prs[l],Bars-reClo_brs[l],pos,!bull,"   -> "+stotal2,2,1);
//if (l < obj_reOps[pos][0] + 1)
               CreateLabel(reClo_prs[l],Bars-reClo_brs[l],pos,!bull,"   px:"+/*DoubleToStr(reClo_prs[l],5)+" tot: "+DoubleToStr(total,0)+* /" - "+IntegerToString(pos)+"-"+
         IntegerToString(obj_pos0[p])+"-"+IntegerToString(obj_pos0[p+1])+"-"+IntegerToString(obj_pos[p])+"-"+IntegerToString(obj_pos[p+1])+" - "+
         IntegerToString(obj_pos0[p-1])+"-"+IntegerToString(obj_pos[p-1])+" - "+IntegerToString(obj_pos0[p-5])+"-"+IntegerToString(obj_pos[p-5])+" - "+
         IntegerToString(obj_pos0[p-4])+"-"+IntegerToString(obj_pos[p-4])+" - "+IntegerToString(l)+" - "+IntegerToString(Bars-reClo_brs[l]),0,1);/*
               Print (pos, " (2) object ", ObjectName(pos), " | ", prv_pos, " - ", obj_Prices[prv_pos], " - ", obj_prClots[prv_pos][1], " - ", obj_Prices[pos], " - total : ", total, " *");*/ } }
            if (total - hightotal < drawdown / 4 * 3 && Op_DDw) Print ("(1) ", pos," object "," | ",prv_pos," - ",obj_Prices[prv_pos]," - total : ",total," - hightotal : ",
               hightotal," - drawdown : ",drawdown," - ",drawdwnp?DoubleToStr(drawdwnp,1):"-.-"," % - ",obj_reOps[pos][0]," - ",obj_reOps[pos][1]," - t_clo/bleu : ",
               TimeToStr(Time[obj_bar_cl],TIME_DATE|TIME_MINUTES)," *");
            if (hightotal < total) hightotal = total;          else if (drawdown > total - hightotal) { drawdown = total - hightotal;
                  if (hightotal) drawdwnp = (drawdown*1.0 / hightotal*1.0) * 100.0; } }
//      Print (pos, " object ", ObjectName(pos), " | ", prv_pos, " - ", obj_Prices[prv_pos], " - total : ", total, " *");
      obj_liqTyp_2 = obj_liqTyp_1;     obj_liqTyp_1 = obj_liqTypes[pos];
      if ((obj_liqTypes[pos] == "Buy" && obj_liqTypes[prv_pos] != "Buy") ||
         (obj_liqTypes[pos] == "Sell" && obj_liqTypes[prv_pos] != "Sell")) prv_pos = pos;    p ++; }

/* - partie finale ---------------------------------------------------------------------------------------------------------------- */
#ifdef v_opfx_0
   if (Minute()) { test0 = -1;       test1 = -1;       test2 = -1; }
   if (! (Minute() % PERIOD_M5) && Seconds() < 7 && DayOfWeek() == 5 && H1 > H3 && Hour() == H1 && test0 < Seconds()) { test0 = Seconds();
      Print("** -> TEST(0) DrawArrow_OS n ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," ",OS5_tick," ",TimeToStr(tim_Chart_M5,TIME_MINUTES)," **"); }
   if (!(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<H3 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8)) &&
      (Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow) return;    // 23
   if (Hour() >= 3 && ! (Minute() % PERIOD_M5 * 60) && Seconds() < 7 && test1 < Seconds()) { test1 = Seconds();
      Print("** -> TEST(1) DrawArrow_OS n ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," / ",fl_Trade," ",(!(((Hour()>1 || (Hour() && 
         Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8)) && (Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",!(((Hour()>1 ||
         (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8))," ",((Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",
         (Period() > PERIOD_M15 || DayOfWeek() == 5)," ",t_rsi515," ",OS5_tick," ",Hour()," ",TimeToStr(tim_Chart_M5,TIME_MINUTES)," ",TimeToStr(tim_M15,TIME_MINUTES) +" **"); }
#endif
   double tmp, tmp2, this_Order_Price;     datetime this_Order_Time;       St_Trd2 = FileIsExist("St-Trd_On.txt", FILE_COMMON);
   if (prevMinute != Time[0]) { t3 = 0;    prevMinute = Time[0]; }
   if (! total2) total2 = total;       if (! total3 && ! total3_) { total3 = total;    AccBalance = AccountBalance(); }
   obj_reOps[pos][1] = 0;     pos --;     //pos = prv_pos;     prv_pos = prv_pos0;     name = ObjectName(pos);    k_ = k;
   obj_Prices[pos] = (iOpen(NULL,0,Bars-obj_bars[obj_pos[p-1]]) * (rate1c? 5.0: rate2c? 4.0: rate3c? 3.0: rate4c? 2.0: 1.0) + 
         iClose(NULL,0,Bars-obj_bars[obj_pos[p-1]]) * (rate1c? 1.0: rate2c? 2.0: rate3c? 3.0: rate4c? 4.0: 5.0)) / 6.0;
   if (obj_liqTypes[pos] == "Error") CreateLabel0(obj_Levels[pos],Bars-obj_bars[pos],"- NO LIQUID LINE - "+IntegerToString(pos)+" *",0,0,0);    // && Op_HiLo
   if (obj_liqTypes[pos] == "Error-2") CreateLabel0(obj_Levels[pos],Bars-obj_bars[pos],"- 2 LIQUID LINES - "+IntegerToString(pos)+" *",0,0,0);  // && Op_HiLo
   t_clo = false;    j = 0;   while(! Time[j]) j ++;     //bool op_case0;    // op_case0 juste provisoire, à revoir *
   for (i=obj_bars[obj_pos[p-1]]+1; i <= Bars && ! t_clo; i ++) { obj_prClots[pos] = iClose(NULL,0,Bars-i);
/*Print("*** ",i," - ",p," - ",(Bars-i)," - ",pos," - ",obj_pos[p-2]," - ",obj_pos[p-1]," - ",obj_pos[p]," - ",obj_liqTypes[prv_pos]," - ",
   iOpen(NULL,0,Bars-i)," - ",iHigh(NULL,0,Bars-i)," - ",iLow(NULL,0,Bars-i)," - ",iClose(NULL,0,Bars-i)," - ",obj_prClots[pos]," - ",
((obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (obj_prClots[pos]-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i)) > 0.3 &&
         ((obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i) - iOpen(NULL,0,Bars-i+1)) > 20 * Point ||
         ((obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i+1) - iOpen(NULL,0,Bars-i+1))) > 20 * Point)),
         " - ",((obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i) - iOpen(NULL,0,Bars-i+1)) > 20 * Point ||
            ((obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i+1) - iOpen(NULL,0,Bars-i+1))) > 20 * Point),
         " - ",(obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (obj_prClots[pos]-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i)),
         " - ",(obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i) - iOpen(NULL,0,Bars-i+1)),
         " - ",((obj_liqTypes[prv_pos]=="Buy" ? -1 : 1) * (iClose(NULL,0,Bars-i+1) - iOpen(NULL,0,Bars-i+1)))," ***"); */
//      haBull = HA_Bull(iOpen(NULL,0,Bars-i+2), iClose(NULL,0,Bars-i+2), iOpen(NULL,0,Bars-i+1), iClose(NULL,0,Bars-i+1), 
//         iHigh(NULL,0,Bars-i+1), iLow(NULL,0,Bars-i+1), iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i));
      if ((op_case0=(iCustom(NULL,PERIOD_H1,"New folder\\ADX.ex4",0,0)>45 || ADX_time>0 || St_Trd || St_Trd2 || 
            (H1 < H3 && (! DayOfWeek() || (DayOfWeek()==1 && Hour()<H2))) || (DayOfWeek()==5 && Hour()>21)))) {
         if ((! ((H1<H3 && (!DayOfWeek() || (DayOfWeek()==1 && Hour()<H2))) || (DayOfWeek()==5 && Hour()>21)) || t_clo) && t3 < 3) { t3 ++;     // 8
            Print("** -> op_case0 (1): "+IntegerToString(iCustom(NULL,PERIOD_H1,"New folder\\ADX.ex4",0,0))+" - "+IntegerToString(ADX_time)+" - "+St_Trd+" - "+St_Trd2+" - "+t_clo_+" - "+t_clo+" **"); }
#ifndef v_opfx
         t_clo =#ifdef v_opfx_0 Period() > PERIOD_M5 && 
                #endif f_mqh_code(3, pos, prv_pos, i, obj_liqTypes[prv_pos], obj_prClots[pos], 0, 0); }                                                  // * MQH *
#else
      if (iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) { Print("*** Error High - Low! (4) "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");   continue; }  //Period()<=5 && 
      else if (! obj_bar_liq[pos] || Bars - i > obj_bar_liq[pos] + 2) {
         haBull = HA_Bull(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
         if (ha_Prev || !ha_Buff || !((haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell")))
            t_clo = f_mqh_code_EA(3,pos,prv_pos,i,obj_liqTypes[prv_pos],obj_prClots[pos],0,0,params,HighVal,MrktVal,HiLoVal,DDwnVal); } }                      // * MQH *
#endif
      if (ea_show && t_clo) { //&& (!prv_pos || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell") || (obj_liqTypes[prv_pos]=="Buy" && obj_liqTypes[prv_pos]=="Sell"))) {
         DrawArrow_pf(obj_prClots[pos], Bars-i, 3, !bull, 1);         DrawArrow_pf(obj_prClots[pos], Bars-i, 5, !bull, 1); }       // 1er niveau de sortie en bleu
      if (t_clo && ticket) { blue_time = Time[Bars-i+j];    ADX_time = Time[Bars-i+j]; }     else ADX_time = 0;         if (t_clo && ticket && i == Bars-j) { //t_blue = false;
         if (t_blue) Print("** -> DrawArrow_OS *1 ",bull_," ",bull," ",t_clo_," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i)," ",TimeToStr(Time[Bars-j-i],
            TIME_MINUTES)," ",TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," **");   t_blue = false;      blue_time2 = Time[j]; }
      if ((t_clo_ || t_clo) && i == Bars-j-1 && ticket && blue_time2 == Time[Bars-j-i]#ifdef v_opfx_0 && OS1_tick && time_allow) { OS1_tick = false;#else) {#endif   //t_clo_ = false;   t_clo = false;
         if (blue_time3 != Time[0]) { DrawArrow_pf(bull? Bid: Ask, j, 2, !bull, 1);        DrawArrow_pf(bull? Bid: Ask, j, 6, !bull, 1);      total2_ = total2;
            Print("** -> op_case0 (2): "+IntegerToString(blue_time)+" - "+IntegerToString(blue_time2)+" - "+IntegerToString(ADX_time)+" - "+St_Trd+" - "+St_Trd2+" - "+t_clo_+" - "+t_clo+" **");
//            total2 += (prv_pos ? (obj_liqTypes[prv_pos] == "Buy" ? -1 : (obj_liqTypes[prv_pos] == "Sell" ? 1 : 0)) * (obj_Prices[pos] - obj_prClots[pos]) / Point -
//               (obj_liqTypes[prv_pos] == "Buy" || obj_liqTypes[prv_pos] == "Sell" ? 1 : 0) * comm : 0);
            total2 += total3 - total3_;            blue_time3 = Time[0]; }                            // total2 à revoir dans cette partie  ***
         if (op_case01 || op_case0) {
            Print("** -> DrawArrow_OS 1* ",bull_," ",bull," ",t_clo_," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i)," ",TimeToStr(Time[Bars-j-i],TIME_MINUTES)," ",
               TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," | ",(tmp=AccountBalance())," **");      //t_clo_ = false;      t_clo = false;    t_blue = true;
            DrawArrow_OS(1, obj_prClots[pos]+(bull? 300*vScale*Point: 675*vScale*Point), Bars-i, 0, bull, ticket);      // 150*vScale*Point: 625*vScale
            Print("** --> total = ",total,", total2 = ",total2," (",DoubleToStr(obj_Prices[pos],5)," - ",DoubleToStr(obj_prClots[pos],5)," - ",TimeToStr(Time[Bars-obj_bars[obj_pos[p-1]]],
               TIME_MINUTES)," - ",TimeToStr(Time[Bars-i],TIME_MINUTES)," - ",DoubleToStr(Bid,5)," - ",DoubleToStr(Ask,5),"), total2_ = ",total2_," (",(total2-total2_),") ...");
            Print("** --> suite total3 = ",total3," (",OrderProfit()," - ",OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",DoubleToStr(OrderClosePrice(),5),
               " - ",TimeToStr(OrderOpenTime(),TIME_MINUTES)," - ",TimeToStr(OrderCloseTime(),TIME_MINUTES),", p_Coef: ",p_Coef,", ",(OrderProfit()*p_Coef)," ",(OrderSwap()*p_Coef)," ",
               (OrderCommission()*p_Coef),") ...");                    Print("** --> suite total3_ = ",total3_," (",(total3-total3_)," - ",(AccountBalance()-tmp),") | ",
            tmp," - ",AccountBalance()," - ",AccBalance," -",(AccountBalance()-AccBalance)>-0.015?" ok":"> BALANCE"," | (",ntot,") ",pos," - ",DoubleToStr(obj_Prices[pos],5)," - ",
               DoubleToStr(obj_prClots[pos],5)," | ticket = ",ticket," **");#ifdef v_opfx
         if (((op_Liq_ && obj_bars[obj_pos0[p-1]] > Bars-2 && ((bull && Bid > op_Liq_pr) || (! bull && Ask < op_Liq_pr) || op_Liq_sp < 100 * Point)) ||
         (lastliq && obj_bars[obj_pos0[p-1]] == Bars-2)) && OS6_tick && time_allow) { OS6_tick = false;        lastliq = false;        lastliq_ = false;
            DrawArrow_OS(6, obj_prClots[pos]+(bull? 150*vScale*Point: 625*vScale*Point), Bars-i, 0, bull, 0);           PlaySound("1673.wav");
            Print("** -> DrawArrow_OS 6 ",bull_," ",bull," ",t_clo_," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i)," ",TimeToStr(Time[Bars-j-i],TIME_MINUTES),
               " ",TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," | ",(tmp=AccountBalance())," **");
            Print("** --> total = ",total,", total2 = ",total2," (",DoubleToStr(tmp,5)," - ",DoubleToStr(iClose(NULL,0,0),5)," - ",TimeToStr(Time[Bars-obj_bars[obj_pos[p-
               (Bars!=obj_bars[obj_pos[p-1]]?1:2)]]],TIME_MINUTES)," - ",TimeToStr(Time[Bars-i+1],TIME_MINUTES)," | ",DoubleToStr(Bid,5)," - ",DoubleToStr(Ask,5),"), total2_ = ",
               total2_," (",(total2-total2_),") ...");
            Print("** --> suite total3 = ",total3," (",OrderProfit()," - ",OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",DoubleToStr(OrderClosePrice(),5),
               " - ",TimeToStr(OrderOpenTime(),TIME_MINUTES)," - ",TimeToStr(OrderCloseTime(),TIME_MINUTES),", p_Coef: ",p_Coef,", ",(OrderProfit()*p_Coef)," ",(OrderSwap()*p_Coef)," ",
               (OrderCommission()*p_Coef),") ...");                    Print("** --> suite total3_ = ",total3_," (",(total3-total3_)," ",(AccountBalance()-tmp2),") | ",
               tmp2," - ",AccountBalance()," - ",AccBalance," -",(AccountBalance()-AccBalance)>-0.015?" ok":"> BALANCE"," | ticket = ",ticket," ...");
            Print("** --> suite (",ntot,") ",pos," - ",DoubleToStr(obj_Prices[pos],5)," - ",DoubleToStr(obj_prClots[pos],5)," - ",prv_pos," - ",
               DoubleToStr(obj_Prices[prv_pos],5)," - ",DoubleToStr(obj_prClots[prv_pos],5)," **"); }
         if (obj_bars[obj_pos0[p-1]] == Bars-3) lastliq_ = true;#endif }
         t_clo_ = false;      t_clo = false;    t_blue = true; }     // <- déplacés à cause de op_case0 *
      else if (i==Bars-j-1 && t_clo_ && ticket && blue_time2 == Time[Bars-j-i]) 
         Print("** -> DrawArrow_OS 1 Error: ",t_clo_," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",(Bars-i)," | ",pos," ",obj_prClots[pos]," ***");
      else if (i == Bars-j-1 && blue_time2 == Time[Bars-j-i]) t_blue = true;
      t_clo_ = (i == Bars-j-1 && t_clo_ ? t_clo_ : (i == Bars-j && t_clo));
      if (ea_show && !(iHigh(NULL,0,Bars-i) - iLow(NULL,0,Bars-i))) CreateLabel0_pf(iOpen(NULL,0,Bars-i),Bars-i,"- HIGH() = LOW() - "+DoubleToStr(iOpen(NULL,0,  // && Op_HiLo
      Bars-i),4)+" - "+DoubleToStr(iHigh(NULL,0,Bars-i),4)+" - "+DoubleToStr(iLow(NULL,0,Bars-i),4)+" - "+DoubleToStr(iClose(NULL,0,Bars-i),4)+" *",0,0,0); }
   if ((obj_liqTypes[prv_pos]=="Buy" && obj_liqTyp_2 == "Sell") || (obj_liqTyp_2 == "Buy" && obj_liqTypes[prv_pos]=="Sell")) obj_bar_cl = Bars-i+(t_clo?1:0);
   if (! t_clo) { i --;       obj_prClots[pos] = (iOpen(NULL,0,Bars-i) * (rate1c? 5.0: rate2c? 4.0: rate3c? 3.0: rate4c? 2.0: 1.0) +
         iClose(NULL,0,Bars-i) * (rate1c? 1.0: rate2c? 2.0: rate3c? 3.0: rate4c? 4.0: 5.0)) / 6.0; }        ntot = 1;
   total += (prv_pos ? (obj_liqTypes[prv_pos] == "Buy" ? -1 : (obj_liqTypes[prv_pos] == "Sell" ? 1 : 0)) *     // && obj_Prices[pos]>0 && obj_prClots[pos]>0
         (obj_Prices[pos] - obj_prClots[pos]) / Point - (obj_liqTypes[prv_pos] == "Buy" || obj_liqTypes[prv_pos] == "Sell" ? 1 : 0) * comm : 0);
   if (((t_clo_ || t_clo) && i == Bars-j && ticket && blue_time2 == Time[Bars-j-i+1]) || pass1) Print("** --> (1a) total = ",total,", total2 = ",total2,
         ", total2_ = ",total2_,", total3 = ",total3,", total3_ = ",total3_,", ticket = ",ticket," **");
//Print("*** ",i," - ",p," - ",(Bars-i)," - ",pos," - ",obj_pos[p-2]," - ",obj_pos[p-1]," - ",obj_pos[p]," - ",obj_liqTypes[prv_pos]," - ",obj_Prices[pos]," - ",obj_prClots[pos]," - ",total," ***");
   if (! ((obj_liqTypes[prv_pos]=="Buy" && obj_liqTyp_2=="Sell") || (obj_liqTyp_2=="Buy" && obj_liqTypes[prv_pos]=="Sell"))) { temp = "final";
      // dans ce bloc la logique d'apparition des flèches est différente par rapport au précédent (-> prv_pos)
      if (ea_show) { DrawArrow_pf(obj_Prices[pos], Bars-obj_bars[obj_pos[p-1]], 3, bull, 0);    DrawArrow_pf(obj_Prices[pos], Bars-obj_bars[obj_pos[p-1]], 5, bull, 0); }
      if (obj_bar_cl >= Bars-obj_bars[obj_pos[p-1]]) { ntot = 2;
         total += (obj_liqTypes[prv_pos] == "Buy" ? -1 : (obj_liqTypes[prv_pos] == "Sell" ? 1 : 0)) * (obj_Prices[pos] - obj_prClots[pos]) / Point - comm;
         if (pass1) Print("** --> (1b) total = ",total,", total2 = ",total2,", total2_ = ",total2_,", total3 = ",total3,", total3_ = ",total3_,", ticket = ",ticket," **");
#ifndef v_opfx_0
         if (obj_bars[obj_pos[p-1]] >= Bars-1 && (! ticket || FileIsExist("ATS-Int_On.txt", FILE_COMMON))) { total2_ = total2;
#else
         if ((Hour() != H1 || H1 < H3 || Minute() >= 2) && obj_bars[obj_pos[p-1]] >= Bars-1 && (! ticket || FileIsExist("ATS-Int_On.txt", FILE_COMMON)) &&
            OS2_tick && time_allow) { OS2_tick = false;           total2_ = total2;
#endif
            DrawArrow_pf(bull? Ask: Bid, Bars-obj_bars[obj_pos[p-1]], 2, bull, 0);     DrawArrow_pf(bull? Ask: Bid, Bars-obj_bars[obj_pos[p-1]], 6, bull, 0);
            total2 += (obj_liqTypes[prv_pos] == "Buy" ? -1 : (obj_liqTypes[prv_pos] == "Sell" ? 1 : 0)) * (obj_Prices[pos] - obj_prClots[pos]) / Point - comm;
            Print("** -> DrawArrow_OS 2 ",bull_," ",bull," ",ticket," ",Bid," ",Ask," ",p," ",obj_pos[p-1]," ",obj_bars[obj_pos[p-1]]," | ",pos," ",obj_Prices[pos]," ",vScale," **");
            DrawArrow_OS(2, obj_Prices[pos]+(bull? 400*vScale*Point: 675*vScale*Point), Bars-obj_bars[obj_pos[p-1]], 0, bull, 0);   // 250*vScale*Point: 625*vScale
            Print("** --> total = ",total,", total2 = ",total2," (",obj_Prices[pos]," - ",obj_prClots[pos],"), total2_ = ",total2_,", total3 = ",total3," (",OrderProfit()," - ",
               OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",DoubleToStr(OrderClosePrice(),5),"), total3_ = ",total3_,", ticket = ",ticket," **");
            bull_ = bull; } }       // en principe inutile ici, sauf si bug sur précédent OS 5 -> 16-07 7:00 (vérifier à cause de sortie 5* > 7200 sec.)
      if (ea_show && Op_Show) { name = ObjectName(prv_pos);
         nam_B = StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name, StringFind(name, "tral")+4);
         nam_S = StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_sell"+StringSubstr(name, StringFind(name, "tral")+4);
         obj_Levels[prv_pos] = (ObjectGet((obj_liqTypes[prv_pos]=="Buy"?nam_B:nam_S),OBJPROP_PRICE1)+ObjectGet(name,OBJPROP_PRICE1))/2.0;
         CreateLabel_pf(obj_Levels[prv_pos],Bars-obj_bars[obj_pos[p-1]],obj_pos[p-1],bull,"  total: "+DoubleToStr(total,0)+" ("+temp+") "+
               IntegerToString(Bars-obj_bars[obj_pos[p-1]])+" "+IntegerToString(obj_bar_cl),1,2); } }
   if (hightotal < total) hightotal = total;          else if (drawdown > total - hightotal) { drawdown = total - hightotal;
         if (hightotal) drawdwnp = (drawdown*1.0 / hightotal*1.0) * 100.0; }
#ifndef v_opfx_0
   if (t_clo) { //CreateLabel0_pf(iOpen(NULL,0,Bars-obj_bars[obj_pos0[p+1]]),Bars-obj_bars[obj_pos0[p+1]],"- test reOps - "+IntegerToString(pos)+" *",0,0,0);     // -> (0 && *(1)*
#else
   if (t_clo || (haCoef == 5 && ticket <= 7 && tim_flt >= Time[0] - Period()*60 * 7)) {
#endif
      if (ea_show && ! ((obj_liqTypes[prv_pos]=="Buy" && obj_liqTyp_2=="Sell") || (obj_liqTyp_2=="Buy" && obj_liqTypes[prv_pos]=="Sell")) && Op_Show) 
         CreateLabel0_pf(iOpen(NULL,0,Bars-obj_bars[obj_pos0[p]]),Bars-obj_bars[obj_pos0[p]],"- test reOps - "+IntegerToString(prv_pos)+"*"+
            IntegerToString(obj_pos0[p-1])+"*"+IntegerToString(obj_pos0[p])+"*"+IntegerToString(obj_pos[p-1])+"-"+IntegerToString(obj_pos[p])+" *",0,0,0);
      t_opn=false;      while (i <= (obj_pos0[p]?obj_bars[obj_pos0[p]]:Bars)) { reOpn_prs[k] = 0.0;   reClo_prs[k] = 0.0;
       t_clo=false;     for (i=i; i <= (obj_pos0[p]?obj_bars[obj_pos0[p]]:Bars) && ! t_clo; i ++) { reOpn_prs[k] = iClose(NULL,0,Bars-i);   reOpn_brs[k] = i;
//         haBull = HA_Bull(iOpen(NULL,0,Bars-i+2), iClose(NULL,0,Bars-i+2), iOpen(NULL,0,Bars-i+1), iClose(NULL,0,Bars-i+1), 
//            iHigh(NULL,0,Bars-i+1), iLow(NULL,0,Bars-i+1), iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i));
#ifndef v_opfx
         t_clo =#ifdef mkt_stocks (Period() != PERIOD_M1 || magic_nb != 50100600) && 
                #endif f_mqh_code(4, pos, prv_pos, i, obj_liqTypes[prv_pos], 0, reOpn_prs[k], 0); }      // boucle des reOps Label_Arrow_Test(Type= 1,      // * MQH *
#else
         if (iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) { Print("*** Error High - Low! (5) "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");   continue; }  //Period()<=5 && 
         else { haBull = HA_Bull(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
            if (ha_Prev || !ha_Buff || (haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell"))              // boucle des reOps Label_Arrow_Test(Type= 1,
               t_clo = f_mqh_code_EA(4,pos,prv_pos,i,obj_liqTypes[prv_pos],0,reOpn_prs[k],0,params,HighVal,MrktVal,HiLoVal,DDwnVal); } }                       // * MQH *
#endif
       if (t_clo) { //if (t_clo2 < 13) { t_clo2 ++;   Label_Arrow_Test(1,prv_pos,p,i,k,reOpn_prs[k],!bull,pX,pY,total,obj_pos0,obj_pos);   pY += 34; }
         if (ea_show) { DrawArrowInt_pf(iClose(NULL,0,Bars-i+1), Bars-i+1, 3, true);         DrawArrowInt_pf(iClose(NULL,0,Bars-i+1), Bars-i+1, 5, true); }
/*         if (i >= Bars-1 && ! ticket) { DrawArrowInt_pf(bull? Bid: Ask, Bars-i+1, 2, true);        DrawArrowInt_pf(bull? Bid: Ask, Bars-i+1, 6, true);
            Print("** -> DrawArrow_OS 3 ",bull_," ",bull," ",ticket," ",Bid," ",Ask," ",i," ",(Bars-i+1)," | ",pos," ",iClose(NULL,0,Bars-i+1)," ",vScale," **");
            DrawArrow_OS(3, iClose(NULL,0,Bars-i+1)+(bull? 250*vScale*Point: 625*vScale*Point), Bars-i+1, 0, bull, 0); }   */
         orge_time = Time[Bars-i+j];                      if (i == Bars-j+1) { //t_orge = false;
            if (t_orge) Print("** -> DrawArrow_OS *3 ",bull_," ",bull," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i+1)," ",TimeToStr(Time[Bars-j-i+1],
               TIME_MINUTES)," ",TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," **");   t_orge = false;   orge_time2 = Time[j]; }
         if (i == Bars-j && ! ticket && orge_time2 == Time[Bars-j-i+1]#ifdef v_opfx_0 && OS3_tick && time_allow) { OS3_tick = false;#else) {#endif
            DrawArrowInt_pf(bull? Ask: Bid, j, 2, true);           DrawArrowInt_pf(bull? Ask: Bid, j, 6, true);
            Print("** -> DrawArrow_OS 3* ",bull_," ",bull," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i+1)," ",TimeToStr(Time[Bars-j-i+1],
               TIME_MINUTES)," ",TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," **");      t_clo = false;    t_orge = true;
            if (! DrawArrow_OS(3, iClose(NULL,0,Bars-i+1)+(bull? 400*vScale*Point: 675*vScale*Point), j+1, 0, bull, 0))    // 250*vScale*Point: 625*vScale
                  Print("*** DrawArrow_OS 3 Error: ",GetLastError()," ***");
            else Print("** --> total = ",total,", total2 = ",total2,", total2_ = ",total2_,", total3 = ",total3,", total3_ = ",total3_,", ticket = ",ticket," **"); }
         else if (i == Bars-j && orge_time2 == Time[Bars-j-i+1]) t_orge = true;
         t_clo = false;   t_opn = true;                                                      // boucle de recherche des reCls Label_Arrow_Test(Type= 2,
         for (i=i; i <= Bars && ! t_clo; i ++) { reClo_prs[k] = iClose(NULL,0,Bars-i);       reClo_brs[k] = i;
//            haBull = HA_Bull(iOpen(NULL,0,Bars-i+2), iClose(NULL,0,Bars-i+2), iOpen(NULL,0,Bars-i+1), iClose(NULL,0,Bars-i+1), 
//               iHigh(NULL,0,Bars-i+1), iLow(NULL,0,Bars-i+1), iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i));
#ifndef v_opfx
            t_clo = f_mqh_code(5, pos, prv_pos, i, obj_liqTypes[prv_pos], 0, 0, reClo_prs[k]); }                                                   // * MQH *
#else
            if (iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) { Print("*** Error High - Low! (6) "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");   continue; }  //Period()<=5 && 
            else { haBull = HA_Bull(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
               if (ha_Prev || !ha_Buff || !((haBull && obj_liqTypes[pos]=="Buy") || (!haBull && obj_liqTypes[pos]=="Sell")))
                  t_clo = f_mqh_code_EA(5,pos,prv_pos,i,obj_liqTypes[prv_pos],0,0,reClo_prs[k],params,HighVal,MrktVal,HiLoVal,DDwnVal); } }                    // * MQH *
#endif
         if (ea_show && t_clo) { //&& t_clo3 < 13) { t_clo3 ++;    Label_Arrow_Test(2,prv_pos,p,i,k,reClo_prs[k],bull,pX,pY,total,obj_pos0,obj_pos);     pY += 34; }
            DrawArrowInt_pf(iClose(NULL,0,Bars-i+1), Bars-i+1, 3, false);        DrawArrowInt_pf(iClose(NULL,0,Bars-i+1), Bars-i+1, 5, false); }
/*         if (t_clo && i == Bars-1 && ticket) { DrawArrowInt_pf(bull? Bid: Ask, Bars-i+1, 2, false);      DrawArrowInt_pf(bull? Bid: Ask, Bars-i+1, 6, false);
            Print("** -> DrawArrow_OS 4 ",bull_," ",bull," ",ticket," ",Bid," ",Ask," ",i," ",(Bars-i+1)," | ",pos," ",iClose(NULL,0,Bars-i+1)," ",vScale," **");
            DrawArrow_OS(4, iClose(NULL,0,Bars-i+1)+(bull? 250*vScale*Point: 625*vScale*Point), Bars-i+1, 0, bull, 1); }   //ticket */
         if (t_clo) vilt_time = Time[Bars-i+j];                      if (t_clo && i == Bars-j+1) { //t_vilt = false;
            if (t_vilt) Print("** -> DrawArrow_OS *4 ",bull_," ",bull," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i+1)," ",TimeToStr(Time[Bars-j-i+1],
               TIME_MINUTES)," ",TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," **");   t_vilt = false;   vilt_time2 = Time[j]; }
         if (op_case01 && t_clo && i == Bars-j && ticket && vilt_time2 == Time[Bars-j-i+1]#ifdef v_opfx_0 && OS4_tick && time_allow) { OS4_tick = false;#else) {#endif
            if (vilt_time3 != Time[0]) { DrawArrowInt_pf(bull? Bid: Ask, j, 2, false);        DrawArrowInt_pf(bull? Bid: Ask, j, 6, false);      total2_ = total2;
               total2 += (obj_liqTypes[prv_pos] == "Buy" ? -1 : (obj_liqTypes[prv_pos] == "Sell" ? 1 : 0)) * (reOpn_prs[k] - reClo_prs[k]) / Point - 
                  (obj_liqTypes[prv_pos] == "Buy" || obj_liqTypes[prv_pos] == "Sell" ? 1 : 0) * comm;          vilt_time3 = Time[0]; }
            Print("** -> DrawArrow_OS 4* ",bull_," ",bull," ",t_clo," ",ticket," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-j-i+1)," ",TimeToStr(Time[Bars-j-i+1],
               TIME_MINUTES)," ",TimeToStr(Time[j],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," | ",(tmp=AccountBalance())," **");   t_clo = false;   t_vilt = true;
            if (! DrawArrow_OS(4, iClose(NULL,0,Bars-i+1)+(bull? 300*vScale*Point: 675*vScale*Point), j+1, 0, bull, ticket))     // 150*vScale*Point: 625*vScale
                  Print("*** DrawArrow_OS 4 Error: ",GetLastError()," ***");
            else { Print("** --> total = ",total,", total2 = ",total2," (",DoubleToStr(reOpn_prs[k],5)," - ",DoubleToStr(reClo_prs[k],5)," - ",TimeToStr(Time[Bars-reOpn_brs[k]],
            TIME_MINUTES)," - ",TimeToStr(Time[Bars-reClo_brs[k]],TIME_MINUTES)," - ",DoubleToStr(Bid,5)," - ",DoubleToStr(Ask,5),"), total2_ = ",total2_," (",(total2-total2_),") ...");
            Print("** --> suite total3 = ",total3," (",OrderProfit()," - ",OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",DoubleToStr(OrderClosePrice(),5),
               " - ",TimeToStr(OrderOpenTime(),TIME_MINUTES)," - ",TimeToStr(OrderCloseTime(),TIME_MINUTES),", p_Coef: ",p_Coef,", ",(OrderProfit()*p_Coef)," ",(OrderSwap()*p_Coef)," ",
               (OrderCommission()*p_Coef),") ...");                    Print("** --> suite total3_ = ",total3_," (",(total3-total3_)," ",(AccountBalance()-tmp),") | ",
               tmp," - ",AccountBalance()," - ",AccBalance," -",(AccountBalance()-AccBalance)>-0.015?" ok":"> BALANCE"," | (",ntot,") ",pos," - ",DoubleToStr(obj_Prices[pos],5)," - ",
               DoubleToStr(obj_prClots[pos],5)," | ticket = ",ticket," **"); } }
         else if (i == Bars-j && vilt_time2 == Time[Bars-j-i+1]) t_vilt = true;
         if (! t_clo) reClo_prs[k] = (obj_liqTypes[prv_pos]=="Buy" ? Bid : Ask); }     k ++; }                      // fin de boucle While **
      obj_reOps[pos][0] = obj_reOps[obj_pos[p-2]][1];      obj_reOps[pos][1] = k - 1;
      if (! obj_reOps[pos][0] && prv_pos) obj_reOps[pos][0] = k_ - 1;
      if (t_opn) { tst1 = (obj_liqTypes[prv_pos] == "Buy");// && (! prv_pos || obj_liqTypes[prv_pos] == "Sell"));     // -> (0 && *(1)*
         tst2 = (obj_liqTypes[prv_pos] == "Sell");  //(! prv_pos || obj_liqTypes[prv_pos] == "Buy") && 
         for (l = obj_reOps[pos][0]+1; l <= obj_reOps[pos][1]; l ++) if (reClo_prs[l]) {   // ou  && reClo_prs[l]
            total += (tst1 ? -1 : (tst2 ? 1 : 0)) * (reOpn_prs[l] - reClo_prs[l]) / Point - (tst1 || tst2 ? 1 : 0) * comm;    ntot = 3;
            if (pass1) Print("** --> (1c) total = ",total,", total2 = ",total2,", total2_ = ",total2_,", total3 = ",total3,", total3_ = ",total3_,
                  ", ticket = ",ticket," **");                                                                       if (ea_show && Op_Show)
            CreateLabel_pf(reClo_prs[l],Bars-reClo_brs[l],pos,!bull,"   px:"+DoubleToStr(reClo_prs[l],5)+" tot: "+DoubleToStr(total,0)+" - "+IntegerToString(pos)+" - "+IntegerToString(l),0,1); } }
//         if (obj_reOps[pos][0]+1 <= obj_reOps[pos][1]) Print("** --> (2) total = ",total,", total2 = ",total2,", total3 = ",total3,", total3_ = ",total3_,", ticket = ",ticket," **"); }
      if (total - hightotal < drawdown / 4 * 3 && Op_DDw) Print ("(2) ", pos," object "," | ",prv_pos," - ",obj_Prices[prv_pos]," - total : ",total," - hightotal : ",
         hightotal," - drawdown : ",drawdown," - ",drawdwnp?DoubleToStr(drawdwnp,1):"-.-"," % - ",obj_reOps[pos][0]," - ",obj_reOps[pos][1]," - t_clo/bleu : ",
         TimeToStr(Time[obj_bar_cl],TIME_DATE|TIME_MINUTES)," *");
      if (hightotal < total) hightotal = total;          else if (drawdown > total - hightotal) { drawdown = total - hightotal;
            if (hightotal) drawdwnp = (drawdown*1.0 / hightotal*1.0) * 100.0; } }
//   Print (pos, " object ", ObjectName(pos), " | ", prv_pos, " - ", obj_Prices[prv_pos], " - total : ", total, " *");
/* -------------------------------------------------------------------------------------------------------------------------------- */

#ifdef v_opfx
bool SO_ATS=GlobalVariableGet("Send-Order_ATS"), 
   SO_BS=GlobalVariableGet("Send-Order_BS"), SO_1=GlobalVariableGet("Send-Order_1"), 
   SO_2=GlobalVariableGet("Send-Order_2"), SO_3=GlobalVariableGet("Send-Order_3"), 
   SO_4=GlobalVariableGet("Send-Order_4"), SO_5=GlobalVariableGet("Send-Order_5");

if (SO_ATS) { temp = "** -> DrawArrow_OS ATS "+(obj_bars[prv_pos] >= Bars-1)+" "+bull+" "+Bid+" "+Ask+" "+prv_pos+" "+
      obj_bars[prv_pos]+" "+(Bars-obj_bars[prv_pos])+" "+TimeToStr(Time[Bars-obj_bars[prv_pos]],TIME_MINUTES)+" | "+pos+" "+iClose(NULL,0,Bars-i+1)+" "+vScale+
      " - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **";      DrawArrow_OS_(0, temp); }
if (SO_1) { temp = "** -> DrawArrow_OS *1 "+bull+" "+t_clo+" "+Bid+" "+Ask+" "+i+" "+j+" "+Bars+" "+(Bars-i)+" "+
      TimeToStr(Time[Bars-i],TIME_MINUTES)+" | "+pos+" "+obj_prClots[pos]+" "+vScale+" - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **";
   DrawArrow_OS_(1, temp); }
if (SO_2) { temp = "** -> DrawArrow_OS *2 "+bull+" "+Bid+" "+Ask+" "+p+" "+obj_pos[p-1]+" "+
      obj_bars[obj_pos[p-1]]+" | "+pos+" "+obj_Prices[pos]+" "+vScale+" - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **";
   DrawArrow_OS_(2, temp); }
if (SO_3) { temp = "** -> DrawArrow_OS *3 "+bull+" "+t_clo+" "+Bid+" "+Ask+" "+i+" "+Bars+" "+(Bars-i+1)+" "+
      TimeToStr(Time[Bars-i+1],TIME_MINUTES)+" | "+pos+" "+obj_prClots[pos]+" "+vScale+" - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **";
   DrawArrow_OS_(3, temp); }
if (SO_4) { temp = "** -> DrawArrow_OS *4 "+bull+" "+t_clo+" "+Bid+" "+Ask+" "+i+" "+Bars+" "+(Bars-i+1)+" "+
      TimeToStr(Time[Bars-i+1],TIME_MINUTES)+" | "+pos+" "+obj_prClots[pos]+" "+vScale+" - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **";
   DrawArrow_OS_(4, temp); }
if (SO_5) { temp = "** -> DrawArrow_OS *5 "+(obj_bars[prv_pos] >= Bars-1)+" "+bull+" "+Bid+" "+Ask+" "+prv_pos+" "+
      obj_bars[prv_pos]+" "+(Bars-obj_bars[prv_pos])+" "+TimeToStr(Time[Bars-obj_bars[prv_pos]],TIME_MINUTES)+" | "+pos+" "+iClose(NULL,0,Bars-i+1)+" "+vScale+
      " - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **";      DrawArrow_OS_(5, temp); }

GlobalVariableSet("Send-Order_ATS", false);     GlobalVariableSet("Send-Order_1", false);
GlobalVariableSet("Send-Order_2", false);       GlobalVariableSet("Send-Order_3", false);
GlobalVariableSet("Send-Order_4", false);       GlobalVariableSet("Send-Order_5", false);
#endif
  if (WM != WindowPriceMax()) ObjectsPositions(vScale);
//  if (bull != bull_) Print("*** -> bull CHANGED! ",ticket," - ",bull_," - ",bull," ***");
  if (ObjectType("EA_Check-"+stmfr+"-1_0 "+IntegerToString(Time[0])) > 0 || ObjectType("EA_Check-"+stmfr+"-5_0 "+IntegerToString(Time[0])) > 0) {}
//      Print("** -> DrawArrow_chk EXISTS! EA_Check1_0 "+IntegerToString(Time[0])+" **");
#ifndef v_opfx_0
  else if (! DrawArrow_chk(WindowPriceMax()-50 * vScale*Point,0, 1)) Print("*** DrawArrow_chk Error (1): ",GetLastError()," ***");
  if (obj_bars[prv_pos] >= Bars-1 && (! ticket || (bull_ == NULL && bull_ != false) || ((bull && ! bull_) || (! bull && bull_)))) {
#else
  else if (! DrawArrow_chk(WindowPriceMax()-(t_night?130: 50) * vScale*Point, 0, t_night? 5: 1)) Print("*** DrawArrow_chk Error (1): ",GetLastError()," ***");
  if (Liqu_x2 && obj_bars[prv_pos] >= Bars-1 && time_allow) { if (liqu_x2_n < 3) Liqu_x2_tf(str);     liqu_x2_n ++; }
  if (obj_bars[prv_pos] >= Bars-1 && OS5_tick && time_allow && (!ticket || (bull_==NULL && bull_!=false) || ((bull && ! bull_) || (! bull && bull_)) ||
   (tmf_Diff && ((! OrderType() && obj_liqTypes[prv_pos] == "Sell") || (OrderType() && obj_liqTypes[prv_pos] == "Buy")))) && (! t_rsi515 || H1 > H3 || 
   (Hour() > 9 && Time[0] - OrderOpenTime() > 7200)) && haCoef < 5 && tim_flt < TimeCurrent() - Period()*60 * 2 && ((last_ntr_pr > Ask && ! bull) || 
   (last_ntr_pr < Bid && bull)) && last_ntr_pr) {           // du à un faux signal sur XAUUSD le 04-06-2021 à 14h45 mk-time, la Liquid_Sell a disparu après
#endif
      if (ObjectType("EA_Check-"+stmfr+"-2_0 "+IntegerToString(Time[0])) > 0) {}
//         Print("** -> DrawArrow_chk EXISTS! EA_Check2_0 "+IntegerToString(Time[0])+" **");
      else if (! DrawArrow_chk(WindowPriceMax()-310*vScale*Point,0,#ifdef v_opfx_0 t_night?5:2#else 2#endif)) Print("*** DrawArrow_chk Error (2): ",GetLastError()," ***");   //iClose(NULL,0,0)
     #ifdef v_opfx_0 if (Hour() > H2 - 2 && m3_RSI(0, 2) > 40 && m3_RSI(0, 2) < 60 && Period() == PERIOD_M5 && (H1 < H3 || Hour() > H2 + 2)) { t1 = 0;         // Hour() != H1
         while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M15)) && t1 < 17) { t1 ++;        Sleep(100); }
         if (tst) { t_M5_M15 = true;           GlobalVariableSet(tmfr0_str, PERIOD_M15);     tim_M15 = Time[0];         liqu_x2_n = 0;       tmf_Diff = true;
            temp = "** Passage en M15 (1) à "+TimeToStr(TimeCurrent(),TIME_MINUTES)+" ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
            Print(temp);      copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }        else { OS5_tick = false;
     #endif if (Bars != obj_bars[obj_pos[p-1]]) tmp = obj_Prices[prv_pos];    else tmp = (iOpen(NULL,0,Bars-obj_bars[obj_pos[p-2]]) * (rate1c? 5.0: rate2c? 4.0: 
         rate3c? 3.0: rate4c? 2.0: 1.0) + iClose(NULL,0,Bars-obj_bars[obj_pos[p-2]]) * (rate1c? 1.0: rate2c? 2.0: rate3c? 3.0: rate4c? 4.0: 5.0)) / 6.0;
      total2_ = total2;   /* total2 += (prv_pos? (obj_liqTypes[prv_pos]=="Sell"? 1: obj_liqTypes[prv_pos]=="Buy"? -1: 0): 0) * (tmp - (bull? Bid: Ask))/Point
         - (obj_liqTypes[prv_pos] == "Buy" || obj_liqTypes[prv_pos] == "Sell" ? 1 : 0) * comm;  */    // total2 à revoir dans cette partie    ***
      Print("** -> DrawArrow_OS 5 ",(obj_bars[prv_pos] >= Bars-1 && (!ticket || bull_==NULL || (bull && ! bull_) || (! bull && bull_)))," ",
         (obj_bars[prv_pos] >= Bars-1)," ",(!ticket || bull_==NULL || (bull && ! bull_) || (! bull && bull_))," ",bull_," ",bull," ",
         ticket," ",Bid," ",Ask," ",prv_pos," ",obj_bars[prv_pos]," ",(Bars-obj_bars[prv_pos])," ",TimeToStr(Time[Bars-obj_bars[prv_pos]],
         TIME_MINUTES)," | ",pos," ",iClose(NULL,0,Bars-i+1)," ",vScale," | ",(tmp2=AccountBalance())," **");  // v Bars-obj_bars[prv_pos] */
      if (! DrawArrow_OS(5, obj_Levels[prv_pos]+(bull? 400*vScale*Point: 300*vScale*Point), 0, 0, bull, 0))    //250*vScale*Point: 250*vScale
            Print("*** DrawArrow_OS 5 Error: ",GetLastError()," ***");
//Print("** --> total = ",total,", total2 = ",total2,", total2_ = ",total2_,", total3 = ",total3,", total3_ = ",total3_,", ticket = ",ticket," **");     // ?
      else { total2 += total3 - total3_;              // total2 n'a pas d'intérêt dans cette partie
         Print("** --> total = ",total,", total2 = ",total2," (",DoubleToStr(tmp,5)," - ",DoubleToStr(iClose(NULL,0,0),5)," - ",TimeToStr(Time[Bars-obj_bars[obj_pos[p-
            (Bars!=obj_bars[obj_pos[p-1]]?1:2)]]],TIME_MINUTES)," - ",TimeToStr(Time[Bars-i+1],TIME_MINUTES)," | ",DoubleToStr(Bid,5)," - ",DoubleToStr(Ask,5),"), total2_ = ",
            total2_," (",(total2-total2_),") ...");
         Print("** --> suite total3 = ",total3," (",OrderProfit()," - ",OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",DoubleToStr(OrderClosePrice(),5),
            " - ",TimeToStr(OrderOpenTime(),TIME_MINUTES)," - ",TimeToStr(OrderCloseTime(),TIME_MINUTES),", p_Coef: ",p_Coef,", ",(OrderProfit()*p_Coef)," ",(OrderSwap()*p_Coef)," ",
            (OrderCommission()*p_Coef),") ...");                    Print("** --> suite total3_ = ",total3_," (",(total3-total3_)," ",(AccountBalance()-tmp2),") | ",
            tmp2," - ",AccountBalance()," - ",AccBalance," -",(AccountBalance()-AccBalance)>-0.015?" ok":"> BALANCE"," | ticket = ",ticket," ...");
         Print("** --> suite (",ntot,") ",pos," - ",DoubleToStr(obj_Prices[pos],5)," - ",DoubleToStr(obj_prClots[pos],5)," - ",prv_pos," - ",
            DoubleToStr(obj_Prices[prv_pos],5)," - ",DoubleToStr(obj_prClots[prv_pos],5)," **"); }
      if (tst_5b && ! DrawArrow_end(bull? Ask: Bid, Bars-obj_bars[prv_pos], 2, bull, 0)) Print("*** DrawArrow_end Error(1): ",GetLastError()," ***");
      if (tst_5b && ! DrawArrow_end(bull? Ask: Bid, Bars-obj_bars[prv_pos], 6, bull, 0)) Print("*** DrawArrow_end Error(2): ",GetLastError()," ***");
      this_Order_Time = TimeCurrent();    this_Order_Price = bull? Ask: Bid;     t_blue = true;     t_vilt = true;     t_orge = true;     bull_ = bull;
      GlobalVariableSet("th_O_P", this_Order_Price);     GlobalVariableSet("th_O_T", this_Order_Time);      GlobalVariableSet("th_O_B", bull); }#ifdef v_opfx_0 }
  else if (obj_bars[prv_pos] >= Bars-1 && so_cpt < 2) { so_cpt ++;
      Print("*** DrawArrow_OS (*)5 "+(!ticket || (bull_==NULL && bull_!=false) || ((bull && ! bull_) || (! bull && bull_))) + " " + (bull_==NULL && bull_!=false) + " " +
         (bull && ! bull_)+" "+(! bull && bull_) + " " + IntegerToString(ticket) + " " + bull_ + " " + bull + " " + t_rsi515 + " " + OS5_tick + " " + time_allow + " " + haCoef + " " +
         TimeToStr(tim_flt, TIME_MINUTES) + " " + TimeToStr(Time[0], TIME_MINUTES) + " " + DoubleToStr(last_ntr_pr, Digits()) + " " + DoubleToStr(bull? Bid: Ask, Digits()) + " ***"); }
  else if (obj_bars[prv_pos] < Bars-1) so_cpt = 0;
#endif
//  total += (prv_pos ? (obj_liqTypes[prv_pos] == "Sell" ? 1 : obj_liqTypes[prv_pos] == "Buy" ? -1 : 0) : 0) * (obj_Prices[prv_pos] - iClose(NULL,0,0)) / Point;
  DrawArrow(((bull=(obj_liqTypes[prv_pos]=="Sell")) ? obj_Levels[prv_pos]+100*vScale*Point : obj_Levels[prv_pos]+250*vScale*Point), Bars-obj_bars[prv_pos], 0, bull,0);
  if (ea_show) { DrawArrow(obj_Prices[prv_pos], Bars-obj_bars[prv_pos], 3, !bull,0);     DrawArrow(obj_Prices[prv_pos], Bars-obj_bars[prv_pos], 5, !bull,0);
     CreateLabel(obj_Levels[prv_pos],Bars-obj_bars[prv_pos],pos,!bull,"   px: "+DoubleToStr(obj_Prices[prv_pos],5)+" "+DoubleToStr(obj_prClots[pos],5),0,0); }
  ObjectDelete(LabelNameEnd);          LabelNameEnd = NULL;
  CreateLabel_end(0,0,obj_total,!bull,"  total: "#ifdef v_opfx+"(opfx) "#endif+DoubleToStr(total/(strTot?100/myLot:1),2)+" ("+(ticket? endbull? "buy": "sell": "end")+")",0,0);
  if (exp_1 || exp_2) CreateLabel_end(0,0,exp_1+exp_2,NULL,"* exp_1: "+IntegerToString(exp_1)+" - exp_2: "+IntegerToString(exp_2)+" * ",1,0);
  if (hightotal < total) hightotal = total;           else if (drawdown > total - hightotal) { drawdown = total - hightotal;
         if (hightotal) drawdwnp = (drawdown*1.0 / hightotal*1.0) * 100.0; }
//  Print (pos, " (1) object LAST | ", (ObjectType(StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name, StringFind(name, "tral")+4)) 
//      > 0 ? "Sell" : (ObjectType(StringSubstr(name,0,(StringSubstr(name,5,1)==2?13:8))+"liquid_sell"+StringSubstr(name, StringFind(name,"tral")+4))>0? "Buy ": "Err ")), " ",
//      prv_pos, " - ", obj_Prices[prv_pos], " - ", iClose(NULL,0,0), " - ", iClose(NULL,0,0), " - ", pos, " - ", obj_pos[p+1], " - ", p, " - total : ", total, " *");

#ifndef v_opfx_0
  int tmpHiLo, total_;     tst = false;      ObjectsDelete(0, "Chck2");       ObjectsDelete(0, "Stop");
  bool bullish;      total = 0;     for (i = Bars-nBars; i <= Bars; i ++) {      // <- attention Bars-300 **
#else
  int ind_total = ChartIndicatorsTotal(0,0);    bool t_ind300;    temp = NULL;   for (int ind = 0; ind < ind_total && (t_ind300=(temp==NULL)); ind ++)
      if (StringFind((name=ChartIndicatorName(0,0,ind)), "ATS") > 0) temp = StringSubstr(name, StringFind(name, "(")+1, 3);
  int tmpHiLo, total_;     tst = false;      //if (! t_ind300 && pass1) { ObjectsDelete(0, "Chck2", 1, 0);      ObjectsDelete(0, "Stop", 1, 0); }
  bool bullish;      total = 0;        tim_flt_ = tim_flt > 0 ? tim_flt : tim_flt_;
  for (i = Bars - (pass1 ? nBars : fmin(nBars, iBarShift(NULL,0, fmax(tim_flt,tim_flt_), false))); i <= Bars; i ++) {
#endif
      tmpHiLo = int (((iHigh(NULL,0,Bars-i+5)-iLow(NULL,0,Bars-i+5)) + (iHigh(NULL,0,Bars-i+1)-iLow(NULL,0,Bars-i+1)) + (iHigh(NULL,0,Bars-i+2)-
         iLow(NULL,0,Bars-i+2)) + (iHigh(NULL,0,Bars-i+3)-iLow(NULL,0,Bars-i+3)) + (iHigh(NULL,0,Bars-i+4)-iLow(NULL,0,Bars-i+4))) / Point / 5);
//      StDev = iStdDev(NULL, 0, 5, Bars-i+1, MODE_SMA, PRICE_TYPICAL, 0) / Point / Mltp;    // écartype **
      if ((iHigh(NULL,0,Bars-i) - iLow(NULL,0,Bars-i)) / Point > tmpHiLo * 2.2) {   //&&
//      iCustom(NULL, PERIOD_H1, "New folder\\ADX.ex4", 0, Bars-i) < 45) {         // && StDev < 2   **
//         CreateLabel((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2-55*Point, Bars-i-1, 0, 1, DoubleToStr(StDev, 2), 0, 0);
//CreateLabel((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2-55*Point, Bars-i-1, 0, 1, DoubleToStr(iCustom(NULL,PERIOD_H1,"New folder\\ADX.ex4",0,Bars-i),2),0,0);
         DrawArrow_chst((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i+5, 3);
         DrawArrow_chst((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i+4, 3);
         DrawArrow_chst((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i+3, 3);
         DrawArrow_chst((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i+2, 3);
         DrawArrow_chst((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i+1, 3);
         DrawArrow_chst((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i, 4);
         tst1 = false;               tst = (i >= Bars-1);
         bullish = (iClose(NULL,0,Bars-i) > (iHigh(NULL,0,Bars-i)+iLow(NULL,0,Bars-i)) / 2);
         for (p = 1; obj_pos0[p] && ! tst1; p ++) if (obj_bars[obj_pos0[p]] > i) { tst1 = true;
            total += (total_=(obj_liqTypes[obj_pos0[p]]=="Buy" && ! bullish) || (obj_liqTypes[obj_pos0[p]]=="Sell" && bullish)? 
               (((iHigh(NULL, 0, Bars-i)-iLow(NULL, 0, Bars-i))*(1.0-Profit_Back)*(bullish? 1: -1) +
               (bullish? iLow(NULL, 0, Bars-i): iHigh(NULL, 0, Bars-i))) * (bullish? 1: -1) +
               obj_Prices[obj_pos0[p]] * (bullish? -1: 1)) / Point: 0); }
//Print("*** "+DoubleToStr(total_/(strTot?100/myLot:1),2)+" - "+DoubleToStr(total/(strTot?100/myLot:1),2)+" | "+IntegerToString(Bars-i)+" - "+IntegerToString(p)+" ***"); }
         if (total_) CreateLabel_st((WindowPriceMax(0)+iHigh(NULL,0,Bars-i+5))/2, Bars-i-1, DoubleToStr(iHigh(NULL,0,Bars-i), 0)+" "+
            DoubleToStr(iLow(NULL, 0, Bars-i), 0)+" "+DoubleToStr((iHigh(NULL, 0, Bars-i)-iLow(NULL, 0, Bars-i))*(1.0-Profit_Back), 0)+
            " "+DoubleToStr(total_/(strTot?100/myLot:1),2), bullish, 0);
         if (! tst1) total += (((iHigh(NULL, 0, Bars-i)-iLow(NULL, 0, Bars-i))*(1.0-Profit_Back)*(bullish? 1: -1) +
               (bullish? iLow(NULL, 0, Bars-i): iHigh(NULL, 0, Bars-i))) * (bullish? 1: -1) +
               (bullish? Bid: Ask) * (bullish? -1: 1)) / Point; } }        //obj_liqTypes[obj_pos0[p]]
#ifndef v_opfx_0
  ObjectDelete(LabelNameEnd2);            LabelNameEnd2 = NULL;         if (tst) { haCoef = 5;     tim_flt = Time[0]; }
  CreateLabel_end(0,0,obj_total,!bull," -> correction : "+DoubleToStr(total/(strTot?100/myLot:1),strTot?2:0)+(strTot?" $":"")+" (StTrd)",0,1);
  if (fl_Trade && tst && ticket && (Hour() || Minute() > 12) && (Hour() < H3 || Minute() < 44))    // 23
      FollowTrade(Bid > (iHigh(NULL,0,0)+iLow(NULL,0,0)) / 2); //*/
  if (St_Trd && TimeCurrent() > Time[0] && TimeCurrent() - Time[0] <= 2) { St_Trd = false;   Profit_Top = 0.0;    Profit_Bottom = 500000.0; }

#else
//Alert("*****1* "+Fl_Trade+" "+fl_Trade+" "+tst+" "+LabelNameStp+" *******");
  ObjectDelete(LabelNameEnd2);            LabelNameEnd2 = NULL;            if (tst) { haCoef = 5;
      tim_flt = Time[0];      fl_Trade = Fl_Trade;       ObjectSet(LabelNameStp, OBJPROP_ARROWCODE, fl_Trade ? 252: 253);
      if (((last_ntr_pr > Ask && ! OrderType()) || (last_ntr_pr < Bid && OrderType())) && last_ntr_pr && OrderSelect(ticket, SELECT_BY_TICKET) &&
         OrderModify(ticket,OrderOpenPrice(),fabs(OrderOpenPrice()-OrderStopLoss())*(OrderType()? 1.5: -1.5)+OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE)) {} }
  CreateLabel_end(0,0,obj_total,!bull," -> correction : "+DoubleToStr(total/(strTot?100/myLot:1),strTot?2:0)+(strTot?" $":"")+" (StTrd)",0,1);
  if (fl_Trade && tst && ticket && (Hour() || Minute() > 12) && (Hour() < H3 || Minute() < 44)) {  // 23
      FollowTrade(Bid > (iHigh(NULL,0,0)+iLow(NULL,0,0)) / 2); //*/
      if (cresult) { ticket = 0;       GlobalVariableSet(tck_vstr, 0);     cresult = false; } }
//if (cresult) Alert("******* Stop Suiveur Atteint (VM"+IntegerToString(Period())+") Trade Cloturé. ("+LabelNameStp+") *******");
//else  Alert("*****2* "+fl_Trade+" "+tst+" "+LabelNameStp+" *******");
  if (St_Trd && (! ticket || tim_flt < Time[0])) { St_Trd = false;
      Profit_Top = 0.0;       Profit_Bottom = 500000.0;        LabelNameSt2 = ""; }

  int dgts=Digits() > 3 ? Digits() : Bid > 10000 ? 2 : 3, K;      double douHiLo, rect_H;
  bool t_ngt1, t_Ntcks=(str=="-HKG" || str=="-CHN" || str=="-GLD");
  bull = ! bull;    // car inversé sur < DrawArrow(((bull=(obj_liqTypes[prv_pos]=="Sell")) ?... >, 45 lignes plus haut
  if (AccountEquity() > 0 && AccBalance_day - AccountEquity() > 0.2 * AccBalance_day) Close_All_Trades();
  if (curr_time < Time[0] && ((((H1 > H3 && Hour() == H2) || (H1 < H3 && Hour() == H1)) && ! Minute()) || ! AccBalance_day)) {
      AccBalance_day = AccountBalance();           if (GlobalVariableCheck("t_ngt_3")) GlobalVariableDel("t_ngt_3"); }
  if (curr_time < Time[0] && iHigh(NULL, 0, 1) > iLow(NULL, 0, 1)) { if (! pass1) /*
         if (! (Time[0] % (Period() * 120))) { ArrayResize(ExtOpenBuffer, nBars);    ArrayResize(ExtCloseBuffer, nBars);    HA_Buffers(1); }
         else */{ ha1Close = (iOpen(NULL, 0, 1) + iHigh(NULL, 0, 1) + iLow(NULL, 0, 1) + iClose(NULL, 0, 1)) / 4;
            ha1Open = (ExtOpenBuffer[ArraySize(ExtOpenBuffer)-2] + ExtCloseBuffer[ArraySize(ExtCloseBuffer)-2]) / 2;
            for(i = ArraySize(ExtOpenBuffer)-1; i >= 0; i --) {
               ExtCloseBuffer[ArraySize(ExtCloseBuffer) - i-1] = ExtCloseBuffer[ArraySize(ExtCloseBuffer) - i];
               ExtOpenBuffer[ArraySize(ExtOpenBuffer) - i-1] = ExtOpenBuffer[ArraySize(ExtOpenBuffer) - i]; }
            ExtCloseBuffer[ArraySize(ExtCloseBuffer) - 2] = ha1Close;
            ExtOpenBuffer[ArraySize(ExtOpenBuffer) - 2] = ha1Open; }
      habull = HA_Bull(3, iOpen(NULL, 0, 1), iClose(NULL, 0, 1), iHigh(NULL, 0, 1), iLow(NULL, 0, 1), 1, NULL);
      douHiLo = (((iHigh(NULL, 0, 5) - iLow(NULL, 0, 5)) + (iHigh(NULL, 0, 1) - iLow(NULL, 0, 1)) + (iHigh(NULL, 0, 2) -
         iLow(NULL, 0, 2)) + (iHigh(NULL, 0, 3) - iLow(NULL, 0, 3)) + (iHigh(NULL, 0, 4) - iLow(NULL, 0, 4))) / 5 +
         (fabs(iOpen(NULL,0,5) - iClose(NULL,0,5)) + fabs(iOpen(NULL,0,1) - iClose(NULL,0,1)) + fabs(iOpen(NULL,0,2) -
         iClose(NULL,0,2)) + fabs(iOpen(NULL,0,3)-iClose(NULL,0,3)) + fabs(iOpen(NULL,0,4)-iClose(NULL,0,4))) / 5) / 3 / haCoef;
      Alert ("***** "+str+" "+habull+" "+DoubleToStr(ha1Open, dgts)+" "+ha1Close+" "+DoubleToStr(haOpen, dgts)+" "+haClose+" "+
         DoubleToStr(haHigh, dgts)+" "+DoubleToStr(haLow, dgts)+" "+DoubleToStr(douHiLo, dgts)+" *****");
      curr_time = Time[0];       t_TST1 = true;    t_TST2 = true;    OS6_tick = true;     OS9_tick = true;
      OS1_tick = true;     OS2_tick = true;     OS3_tick = true;     OS4_tick = true;     OS5_tick = true;
      for (int n = ObjectsTotal()-1; n >= 0; n --) { str = ObjectName(n);     if (ObjectType(str) != OBJ_TREND) continue;
         if (StringGetChar(str, 0) != '#') continue;     int tick=StringSubstr(str, 1, StringFind(str, " ") - 1);
         ObjectSet(str,OBJPROP_COLOR, OrderSelect(tick, SELECT_BY_TICKET)? OrderProfit() > 0? Aqua: Khaki: White); }
      if (GlobalVariableCheck("t_ngt_1")) t_ngt1 = GlobalVariableGet("t_ngt_1");    if (t_ngt1 && (str=="-HKG" || str=="-CHN")) H3 = 10;
      if (t_Ntcks && Hour() < 6 && nb_ticks > 2 && nb_ticks == nb_tcks_N + 1) Print("** -> (2) nb_ticks > 2 && nb_ticks == nb_tcks_N + 1 : ",
         IntegerToString(nb_ticks) , " " , IntegerToString(nb_tcks_N) , " " , ticket , " " , t_night , " " , t_ngt1 , " " , TimeToStr(Time[0],TIME_MINUTES) , " **");
/*      for (i = 0; i < ArraySize(obj_LiqPrs); i ++) {  for (j = obj_bars[i]-1; j < nBars; j ++) {
            if ((obj_liqTypes[i] == "Buy" && iLow(NULL, 0, nBars-j-1) < obj_LiqPrs[i][0]) ||
            (obj_liqTypes[i] == "Sell" && iHigh(NULL, 0, nBars-j-1) > obj_LiqPrs[i][0])) { obj_LiqPrs[i][1] = 1;        break; } }
         if (obj_LiqPrs[i][1]==0) obj_LiqPrs[i][1] = ((obj_liqTypes[i]=="Buy" && Ask < obj_LiqPrs[i][0]) || (obj_liqTypes[i]=="Sell" && Bid > obj_LiqPrs[i][0])); } */
      double rHigh, rLow;     string Line_N;    if ((rect_H=set_Rectangles()) > 0.0) { for (i = 0; i < ArraySize(Rect_Hs) - 1; i ++) if (! Rect_Ks[i])
            for (j = 0; j < ArraySize(Rect_Hs) - 1; j ++) if ((fabs(Rect_Hs[i][0] - Rect_Hs[j][0]) < 1/Point()/100 ||      // Rect_Ks[j] && 
            fabs(Rect_Hs[i][1] - Rect_Hs[j][1]) < 1/Point()/100) && fmax(Rect_Hs[i][0], Rect_Hs[j][0]) - fmin(Rect_Hs[i][1], Rect_Hs[j][1]) > rect_H &&
            Rect_Ks[j] < rect_HG && Rect_Hs[i][1] > 0.0 && Rect_Hs[j][1] > 0.0) {
               rHigh = fmax(Rect_Hs[i][0], Rect_Hs[j][0]);     rLow = fmin(Rect_Hs[i][1], Rect_Hs[j][1]);
               if (rHigh > rLow && rLow > 0.0) rect_H = rHigh - rLow; }
         if (rHigh == 0.0 || rLow == 0.0) { j = NR-1;    while (Rect_Ks[j]) j --;   rHigh = Rect_Hs[j][0];      rLow = Rect_Hs[j][1]; }
         Line_N = LineCreate(bull_? rLow - rect_H / 4: rHigh + rect_H / 4);         K = ArrayMinimum(Rect_Ks, WHOLE_ARRAY, 0);
         Print("** -> Valeurs de Line_N : "+IntegerToString(rect_HG)+" "+DoubleToStr(rect_H, Digits())+" "+DoubleToStr(rLow, Digits())+" "+Line_N+" **");
         if (((bull_ && Ask > 0.0 && Ask < rLow - rect_H / 4 && (iHigh(NULL, 0, 0) > rLow || iHigh(NULL, 0, K) > rLow)) || (! bull_ && Bid > rHigh + rect_H / 4 &&
         ((iLow(NULL, 0, 0) > 0.0 && iLow(NULL, 0, 0) < rHigh) || (iLow(NULL, 0, K) > 0.0 && iLow(NULL, 0, K) < rHigh)))) && K < 3) { 
            Print("** -> DrawArrow_OS 12 ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," **");
            DrawArrow_OS(12, bull? Ask + 150*vScale*Point: Bid + 625*vScale*Point, 0, 0, bull, ticket); }
         if (((! bull_ && Ask > 0.0 && Ask < rLow - rect_H / 4 && (iHigh(NULL, 0, 0) > rLow || iHigh(NULL, 0, K) > rLow)) || (bull_ && Bid > rHigh + rect_H / 4 &&
         ((iLow(NULL, 0, 0) > 0.0 && iLow(NULL, 0, 0) < rHigh) || (iLow(NULL, 0, K) > 0.0 && iLow(NULL, 0, K) < rHigh)))) && K < 3) { fl_Trade = Fl_Trade;   haCoef = 5;
            Print("** -> Suivi de fl_Trade (1) : "+IntegerToString(K)+" "+IntegerToString(rect_HG)+" "+DoubleToStr(rect_H, Digits())+" "+DoubleToStr(rLow, Digits())+" "+
               IntegerToString(Time[0]) + " " + fl_Trade + " **");
            if (OrderSelect(ticket, SELECT_BY_TICKET) && OrderModify(ticket, OrderOpenPrice(), bull_ ? Bid - (Bid - fmin(iMA(NULL, 0, 5, 0, MODE_SMA, 
            PRICE_CLOSE, 1), iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, 2))) * Profit_Back : Ask + (fmax(iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, 1), 
               iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, 2)) - Ask) * Profit_Back, OrderTakeProfit(), 0, CLR_NONE)) 
               ObjectSetInteger(0, Line_N, OBJPROP_COLOR, clrAqua);        else  ObjectSetInteger(0, Line_N, OBJPROP_COLOR, clrCornsilk);    tim_flt = Time[0]; } }
      else if (tim_flt > 0 && Time[0] - tim_flt > 7200) { objRects_del(1, Line_N);     if (str != "-CHN") { fl_Trade = false;    haCoef = 1;    tim_flt = 0; }
         Print("** -> Suivi de fl_Trade (2) : "+IntegerToString(K)+" "+IntegerToString(rect_HG)+" "+DoubleToStr(rect_H, Digits())+" "+DoubleToStr(rLow, Digits())+" "+
            IntegerToString(Time[0]) + " " + fl_Trade + " **"); }          // ObjectDelete(Line_N);
      if (nb_ticks > 2 && nb_ticks == nb_tcks_N + 1 && m3_RSI(0, 2) > 35 && m3_RSI(0, 2) < 65 && ((t_M5_M15 = (Period() == PERIOD_M5)) ||
      Period() == PERIOD_M15) && Hour() > H2 - 2) { t1 = 0;    GlobalVariableSet(tmfr0_str, PERIOD_M5? PERIOD_M15: PERIOD_M5);      nb_ticks = 0;    nb_tcks_N = 0;  // (H1 < H3 || 
         while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M5? PERIOD_M15: PERIOD_M5)) && t1 < 17) { t1 ++;       Sleep(100); }     if (tst) { tim_M15 = Time[0];    tmf_Diff = true;
            temp = "** Passage en M15 (2) à "+TimeToStr(TimeCurrent(),TIME_MINUTES)+" ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
            Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }
      t_rsi51_ = t_rsi515;       t_rsi515 = (m3_RSI(PERIOD_M5, 3) > 38 && m3_RSI(PERIOD_M5, 3) < 62 && m3_RSI(PERIOD_M15, 3) > 38 && 
         m3_RSI(PERIOD_M15, 3) < 62 && (Period() == PERIOD_M5 || Period() == PERIOD_M15));                  if (t_rsi51_ && ! t_rsi515) tmf_Diff = true;
      if (tim_M15 > 0 && (Time[0] - tim_M15 > Period() * 60*8) && Period() == PERIOD_M15) { t1 = 0;    GlobalVariableSet(tmfr0_str, PERIOD_M5);    // || ! fl_Trade
         while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M5)) && t1 < 17) { t1 ++;      Sleep(100); }     if (tst) { tim_M15 = 0;    t_M5_M15 = false;    tmf_Diff = true;
            temp = "** Passage en M5 (1) à "+TimeToStr(TimeCurrent(),TIME_MINUTES)+" ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
            Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }
      if (! trd_on && mOrderSelect(mOrdersTotal(magic_nb)==1?0:2,SELECT_BY_POS) && OrderSymbol() == Symbol()) { ticket = OrderTicket();      bull2 = ! OrderType();
         if (OrderProfit() + OrderSwap() + OrderCommission() < -0.05 * AccBalance_day && OrderClose(ticket, lot, bull2? Bid: Ask, slip, clrMagenta)) {
           temp = "***** Trade STOP LOSS Reached. This Trade Has Been Closed. ("+DoubleToStr(OrderProfit(),Digits())+" - "+Hour()+" - "+DoubleToStr(AccBalance_day,2)+") *****";
           Alert(temp);          copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }
      else { bull2 = bull_;         if (! trd_on) { ticket = 0;      GlobalVariableSet(tck_vstr, 0); } }           trd_on = false; }
  if (tim_M15 < Time[0] && (! iBarShift(NULL,0,last_liq_t1,false) && m3_RSI(0, 2) > 40 && m3_RSI(0, 2) < 60 && Period() == PERIOD_M5 &&
   ((H1 < H3 && Hour() > H2 - 2) || Hour() > H2 + 2))) { t1 = 0;           GlobalVariableSet(tmfr0_str, PERIOD_M15);
      while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M15)) && t1 < 17) { t1 ++;     Sleep(100); }     if (tst) { tim_M15 = Time[0];   t_M5_M15 = true;   tmf_Diff = true;
         temp = "** Passage en M15 (3) à "+TimeToStr(TimeCurrent(),TIME_MINUTES)+" ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }
  if ((m3_RSI(PERIOD_M5, 2) < 32 || m3_RSI(PERIOD_M5, 2) > 68) && m3_RSI(PERIOD_H1, 2) > 28 &&
   m3_RSI(PERIOD_H1, 2) < 72 && Period() == PERIOD_M15) { t1 = 0;       GlobalVariableSet(tmfr0_str, PERIOD_M5);     // revoir si RSI H1 nécessaire
      while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M5)) && t1 < 17) { t1 ++;         Sleep(100); }        if (tst) { tim_M15 = 0;       tmf_Diff = true;
         temp = "** Passage en M5 (2) à "+TimeToStr(TimeCurrent(),TIME_MINUTES)+" ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); } }
  bool d_HiLo=((douHiLo > (Point() != 0.00001 && Point() != 0.001? str=="-HKG" || str=="-CHN"? 0.001: 0.0005: 0.00017) * Bid) && 
      (fabs(haOpen - haClose) > (Point() != 0.00001 && Point() != 0.001? str=="-HKG" || str=="-CHN" || str=="-BTC"? 0.001: 0.0005: 0.0003)*Bid) &&
      fabs(haOpen - haClose) >= douHiLo * 0.75);
  if ((Period() == PERIOD_M5 || Period() == PERIOD_M15) && ((iBarShift(NULL,0,last_liq_t1,false) >= 4 && d_HiLo) || 
  ((iBarShift(NULL,0,last_liq_t1,false) >= 5 && fmin(fabs(last_liq_pr-Ask), fabs(last_liq_pr-Bid)) >= douHiLo*0.8 && 
  d_HiLo) && ((last_liq_pr > Ask && ! bull2) || (last_liq_pr < Bid && bull2)) && last_liq_pr > 0)) && tim_flt < TimeCurrent() - Period()*60*3) {
      if (! ticket && ((! habull && bull2 && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0)) ||
      (habull && ! bull2 && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0))) && ! t_night && OS9_tick) {
         bull_ = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0);
         temp = "** -> DrawArrow_OS 9 " + bull_ + " " + bull + " " + bull2 + " " + habull + " " + ticket + " " + t_night + " " + TimeToStr(Time[0],TIME_MINUTES) + " " +
            FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)+" "+TimeToStr(last_liq_t1,TIME_MINUTES)+" "+TimeToStr(last_liq_t2,TIME_MINUTES)+" " +
            DoubleToStr(last_liq_pr, Digits())+" "+DoubleToStr(haOpen, Digits())+" "+DoubleToStr(haClose, Digits())+" "+DoubleToStr(douHiLo, Digits())+" " +
            DoubleToStr(0.0002*Bid, Digits()) + " **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
         DrawArrow_OS(9, (bull_? Ask: Bid)+(bull_? 150*vScale*Point: 625*vScale*Point), 0, 0, bull_, 0);    OS9_tick = false; }
/* else Alert("** -> DrawArrow_OS 9 TEST ",Symbol()," ",bull_," ",bull," ",habull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," ",
   FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)," ",TimeToStr(last_liq_t1,TIME_MINUTES)," ",TimeToStr(last_liq_t2,TIME_MINUTES)," ",
   DoubleToStr(last_liq_pr, Digits())," ",DoubleToStr(haOpen, Digits())," ",DoubleToStr(haClose, Digits())," ",DoubleToStr(douHiLo, Digits())," ",
   DoubleToStr(0.0002*Bid, Digits())," **"); //*/
      if (ticket && ((! habull && bull2 && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)) ||
      (habull && ! bull2 && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0)))) {
         temp = "** -> DrawArrow_OS 10 " + bull_ + " " + bull + " " + bull2 + " " + habull + " " + ticket + " " + t_night + " " + TimeToStr(Time[0],TIME_MINUTES) + " " +
            FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)+" "+TimeToStr(last_liq_t1,TIME_MINUTES)+" "+TimeToStr(last_liq_t2,TIME_MINUTES)+" " +
            DoubleToStr(last_liq_pr, Digits())+" "+DoubleToStr(haOpen, Digits())+" "+DoubleToStr(haClose, Digits())+" "+DoubleToStr(douHiLo, Digits())+" " +
            DoubleToStr(0.0002*Bid, Digits()) + " **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
         DrawArrow_OS(10, obj_prClots[pos]+(bull2? 150*vScale*Point: 625*vScale*Point), 0, 0, bull2, ticket); }
else if (t_TST1) { temp = "** -> DrawArrow_OS 10 TEST "+Symbol()+" "+bull_+" "+bull+" "+bull2+" "+habull+" "+ticket+" "+t_night+" "+TimeToStr(Time[0],TIME_MINUTES) + " " +
   FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)+" "+TimeToStr(last_liq_t1,TIME_MINUTES)+" "+TimeToStr(last_liq_t2,TIME_MINUTES)+" "+DoubleToStr(last_liq_pr, Digits())+" "+
   DoubleToStr(haOpen, Digits()) + " " + DoubleToStr(haClose, Digits()) + " " + DoubleToStr(douHiLo, Digits()) + " " + DoubleToStr(0.0002*Bid, Digits()) + " **";
      Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);         t_TST1 = false; } }
else if (t_TST2) { temp = "** -> DrawArrow_OS 10(b) TEST " + bull_ + " " + bull + " " + bull2 + " " + ticket + " " + t_night + " " + TimeToStr(Time[0],TIME_MINUTES) + " " +
   ((last_liq_pr > Ask && ! bull) || (last_liq_pr < Bid && bull)) + " " + (last_liq_pr > Ask && ! bull) + " " + (last_liq_pr < Bid && bull) + " " + (Time[0] % Period() * 120) +
   " " + TimeToStr(last_liq_t1,TIME_MINUTES) + " " + TimeToStr(last_liq_t2,TIME_MINUTES) + " " + DoubleToStr(last_liq_pr, Digits()) + " " + DoubleToStr(haOpen, Digits()) +
  " " + DoubleToStr(haClose, Digits()) + " " + DoubleToStr(douHiLo, Digits()) + " " + DoubleToStr(0.0002*Bid, Digits()) + " **";
      Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);         t_TST2 = false; }
  if (t_Ntcks && nb_ticks > 2 && nb_ticks == nb_tcks_N + 1 && Hour() < 6) { if (str=="-HKG" || str=="-CHN") { t_ngt0 = true;        GlobalVariableSet("t_ngt_1", 1.0); }
   Print("** -> (3) nb_ticks > 2 && nb_ticks == nb_tcks_N + 1 : ",IntegerToString(nb_ticks)," ",IntegerToString(nb_tcks_N)," ",ticket," ",t_night," ",t_ngt1," ",TimeToStr(Time[0],TIME_MINUTES)," **"); }

  if (GlobalVariableCheck(t_ATS_str)) ATS_Time = GlobalVariableGet(t_ATS_str);
  if (ATS_Time > 0 && (TimeCurrent() - ATS_Time) > PERIOD_H1*60 * 5 && (TimeCurrent() - ATS_Time) < PERIOD_H1*60 * 6 &&
   str == "-CHN" && (Period()==PERIOD_M5 || Period()==PERIOD_M15) && int (StringSubstr(TimeToStr(ATS_Time, TIME_MINUTES), 0, 2)) > H2 &&      // H1 > H3
   int (StringSubstr(TimeToStr(ATS_Time, TIME_DATE), 8, 2)) == Day() && ticket > 7) { t_night = true;       if (str=="-CHN") t_ngt0 = true;
      Print("** -> DrawArrow_OS 11 ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," **");
      DrawArrow_OS(11, obj_prClots[pos]+(bull? 150*vScale*Point: 625*vScale*Point), 0, 0, bull, ticket); }
/* else if (str == "-CHN") Print("** -> DrawArrow_OS 11 ATTENTE "+TimeToStr(ATS_Time,TIME_MINUTES)+" "+(TimeCurrent() - ATS_Time)+" "+(ATS_Time > 0 && (TimeCurrent() - ATS_Time) > 
   PERIOD_H1*60 * 5 && (TimeCurrent() - ATS_Time) < PERIOD_H1*60 * 6 && str == "-CHN" && Period() == PERIOD_M5 && int (StringSubstr(TimeToStr(ATS_Time, TIME_MINUTES), 0, 2)) > H2 &&  // H1 > H3
   int (StringSubstr(TimeToStr(ATS_Time, TIME_DATE), 8, 2)) == Day() && ticket)+" "+((TimeCurrent() - ATS_Time) > PERIOD_H1*60 * 5 && (TimeCurrent() - ATS_Time) < PERIOD_H1*60 * 6)+
   " "+(str == "-CHN" && Period() == PERIOD_M5 && int (StringSubstr(TimeToStr(ATS_Time, TIME_MINUTES), 0, 2)) > H2)+" "+
   (int (StringSubstr(TimeToStr(ATS_Time, TIME_DATE), 8, 2)) == Day() && ticket)+" "+ticket+" "+" **"); //*/

  if (OS6_tick && last_rct_==Time[0] && (Period()==PERIOD_H1 || Period()==PERIOD_M30)) { bull_ = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0);
      temp = "***** last_rct_ (2) -> while(! (tst=ChartSetSymbolPeriod(0, && DrawArrow_OS(6, *****";           OS6_tick = false;
      Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
      DrawArrow_OS(6, (bull_? Ask: Bid)+(bull_? 150*vScale*Point: 625*vScale*Point), 0, 0, bull_, 0);       GlobalVariableSet(bull_str, bull_); }
  if (Hour() == 3 && ! Minute() && Seconds() < 5 && test2 < Seconds()) { test2 = Seconds();
      Print("** -> TEST(2) DrawArrow_OS 7 ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," ",OS5_tick," **"); }
//  if ((DayOfWeek() < 5 || H1 < H3) && t_night && Hour() == H1 && (str != "-CHN" || Seconds() > 4) && ticket <= 7) {
  if ((DayOfWeek() < 5 || H1 < H3) && t_night && Hour() == H1 && ((str!="-CHN" && str!="-HKG") || Minute() >= 40) && (str!="-CHN" || (Seconds() > 4 &&
   ((bull && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)) || (! bull && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0))) &&
   (m3_RSI(PERIOD_H1, 2) < 38 || m3_RSI(PERIOD_H1, 2) > 62))) && ticket <= 7) { if (str == "-CHN") fl_Trade = Fl_Trade;          // && t_ind300
      Print("** -> DrawArrow_OS 7 ",bull_," ",bull," ",ticket," ",t_night," ",(str=="-CHN"? IntegerToString(Seconds())+" ": ""),TimeToStr(Time[0],TIME_MINUTES)," **");
      t_night = ! DrawArrow_OS(7, (bull? Ask: Bid)+(bull? 150*vScale*Point: 625*vScale*Point), 0, 0, bull, 0);          t_h6 = true; }    // 6
  if (Hour() == H1 && str == "-CHN" && Minute() > 40) GlobalVariableSet("t_ngt_2", (t_ngt0 = ! (((bull && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)) || 
   (! bull && FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0))) && (m3_RSI(PERIOD_H1, 2) < 38 || m3_RSI(PERIOD_H1, 2) > 62))));
  if (DayOfWeek() < 5 && !t_h6 && t_night && Hour() == H1 && Minute() >= 40 && (str == "-CHN" || str == "-HKG"))
      Print("** -> DrawArrow_OS 7 ATTENTE ",bull_," ",bull," ",ticket," ",t_night," ",(str == "-CHN"? FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)+" "+
         DoubleToStr(m3_RSI(PERIOD_H1, 2), 2) + " " + IntegerToString(Seconds()) + " ": ""), TimeToStr(Time[0],TIME_MINUTES), " **"); //*/
  if (H1 > H3 && t_night != t_night_) Print("** Suivi de t_night et tr_allow (3) : "+Symbol()+" / "+IntegerToString(Period())+" - t_night = "+t_night+" - tr_allow = "+tr_allow+" **");
  if (((DayOfWeek() == 5 && (((Hour() == 16 && Minute() > 39) || Hour() > 16 || t_night) && m3_RSI(0,3) > 38 && m3_RSI(0,3) < 62)) || (Hour()==23 && Minute() > 30)) && ticket > 7) {
//  if (((DayOfWeek() == 5 && ((Hour() == 16 && Minute() > 39) || Hour() > 16)) || (t_night && (H1 < H3 || Hour() != H1))) && ticket > 7) { t_night = true;
      Print("** -> DrawArrow_OS 8 ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," **");
      DrawArrow_OS(8, obj_prClots[pos]+(bull_? 150*vScale*Point: 625*vScale*Point), 0, 0, bull_, ticket);         t_night = true; }
  if ((DayOfWeek() == 5 && ((Hour() == 16 && Minute() > 39) || Hour() > 16)) || (H1 > H3 && DayOfWeek() == 1 && Hour() == H2 && ! Minute() && Seconds() < 7)) {
      GlobalVariableSet("t_ngt_2", 0.0);              if (str == "-CHN") fl_Trade = Fl_Trade; }
//if (str=="-CHN" || str=="-HKG") Print("** -> DrawArrow_OS 8 ATTENTE ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," **");

  if (Hour() != 8 && Hour() != 15 && Hour() != 23 && tmp_saved) tmp_saved = false;
  else if (! tmp_saved && (Hour() == 8 || Hour() == 15 || Hour() == 23) && MQLInfoInteger(MQL_DLLS_ALLOWED)) { tmp_saved = true;
      ChartSaveTemplate(0, "template_saved_"+Symbol());     ChartSaveTemplate(0, "template_saved_"+StringSubstr(Symbol(), 0, 6)); }
#endif
#ifdef v_opfx
  if (r_coptime == INVALID_HANDLE) r_coptime = copy_time(s_coptime);
#endif
  if (r1_coporder == INVALID_HANDLE) r1_coporder = copy_file(s1_coporder, 0);    // ordres en attente de transfert (handle)
  if (r2_coporder == INVALID_HANDLE) r2_coporder = copy_file(s2_coporder, 1);    else if (! r_copyFtp) r_copyFtp = copy_FTP();
  if (r3_coporder == INVALID_HANDLE) r3_coporder = copy_file(s3_coporder, 1);    else if (! r_copyFtp) r_copyFtp = copy_FTP();
  if (r4_coporder == INVALID_HANDLE) r4_coporder = copy_file(s4_coporder, 2);
  GlobalVariableSet("total", total);
  GlobalVariableSet("total2", total2);
  GlobalVariableSet("total3", total3);
  GlobalVariableSet("AccBalance", AccBalance);
//  CreateLabel_end(0,0,0,0,"  WM: "+DoubleToStr(WM,5));
  pass1 = false;     pass1b = Chart_M5 ? false : pass1b;
  return;
}

// calcul du profil de chaque bougie : (précédente obj_liqTypes[]=="Buy" ? -1 : 1) * (iClose() - iOpen()) / (iHigh() - iLow()) > 0.3  (> 30%)
//       testés entre deux bougies identifiées par deux valeurs de obj_bars[pos]

void OnDeinit(const int reason) {
#ifdef v_opfx
  if (mOrderSelect(mOrdersTotal(magic_nb)==1?0:2,SELECT_BY_POS)) ticket = OrderTicket();
#endif
#ifndef v_opfx_0
  GlobalVariableSet("Bullish", bull_);
  GlobalVariableSet(tr_allow? tck_vstr: "Ticket0", ticket);
  Print("*** -> Ticket SAVED! ",ticket," ***");
#else
  int ticket_=GlobalVariableGet(tck_vstr);         bool t_tick=(ticket_ > 7);
  GlobalVariableSet(tr_allow || t_tick ? tck_vstr : "Ticket0", ticket);
  Print("*** -> Ticket SAVED! ",IntegerToString(ticket)," - ",IntegerToString(bull_)," - ",DoubleToStr(OrderLots(),2)," ***");
  ObjectDelete(LabelNameEnd);                   GlobalVariableSet(bull_str, bull_);
  Print("*** END_EA -> ", TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES), " ("+IntegerToString(reason)+") ***");
#endif
//  if (reason == 3) ObjectsDelete(2);
  ObjectDelete(LabelNameEnd);    ObjectDelete(LabelNameEnd2);
  return;
}

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

#ifdef v_opfx_0
bool time_allow=true;
#endif
bool DrawArrow_OS(int Typ,double LinePrice,int BarNum,int Code,bool Bullish,int Clot) {
#ifdef v_opfx_0
   string str="-"+StringSubstr(EnumToString(magic_nb), 0, 3), temp;
   if (!Clot && ((!(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8)) &&
      (Period() > PERIOD_M15 || DayOfWeek() == 5)) || (t_night && (Hour() < H1 && (H1<H3 || Hour()>H3)) && (Hour() || Seconds() > 3)))) {    // 6
      if (time_allow) { Print("*** TRADE ANNULE A CAUSE FIN DE JOURNEE ! "+IntegerToString(Hour())+"h "+IntegerToString(Minute())+"m ***");
         CreateObText(LinePrice,BarNum,Bullish,"*ANNULE*"); }           Sleep(100);
         if (t_night) GlobalVariableSet(bull_str, Bullish);             return((time_allow=false)); }       else time_allow = true;
   if ((Period() == PERIOD_M30#ifdef mkt_stocks || (magic_nb==50100600 && Period()==PERIOD_M1)#endif) && (FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) ||
      FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0))) Bullish = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0)? true: false;
   bool t_monday=(DayOfWeek() < First_Day || (DayOfWeek() == First_Day && Hour() < 5) || ! TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)), tst_5, tst_6, tr_Allow, t_Night;
   tst_5b = Clot || tst_5c < Time[0] || (((tmfr == PERIOD_H1 || tmfr == PERIOD_M30) && ((FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) &&  // || tmfr == PERIOD_M5
      Bullish) || (FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0) && ! Bullish))) || Typ < 5 || tmfr == PERIOD_M1 || tmfr == PERIOD_M5);
// ** ou utiliser tr_allow_ = tr_allow au début et tr_allow = tr_allow_ à la fin, à la place de tr_Allow **
   tr_Allow = (tr_allow || Typ == 7);                    t_Night = ! (! t_night || Typ == 7);
   if (ticket <= 7 && tr_Allow) { ticket = 0;            GlobalVariableSet(tck_vstr, ticket); }
#endif
   Bullish = Clot? Bullish? false: true: Bullish;        int ticket_=ticket#ifdef v_opfx_0, cpt2=1, tmfr_n#endif;       //, tmfr;
   string ArrowName = "EA_OS-"+IntegerToString(Typ)+(Typ==1||Typ==4?"-out":"-in")+"_Arr"+(Bullish? "-Up_": "-Down_")+   //&&!Clot)||(!Bullish&&Clot)
      IntegerToString(Code?Code:Bullish?241:242)+"-"+IntegerToString(BarNum)+"-"+IntegerToString(Clot)+" "+IntegerToString(TimeCurrent());
   if (tst_5b && cpt == 1) { if (! ObjectCreate(ArrowName,OBJ_ARROW,0,Typ==1? blue_time: Time[BarNum],LinePrice)) return false;
      if (Typ > 5) DrawArrow(LinePrice, BarNum, Typ==6? 134: Typ==7? 135: Typ==8? 136: Typ==9? 137: 138, Bullish, Clot); }
   if (Typ==1) blue_time = 0;       if (Typ==3) orge_time = 0;          if (Typ==4) vilt_time = 0;    //: Typ==3? orge_time: Typ==4? vilt_time
   if (Typ==3 || Typ==5) { ADX_time = 0;        St_Trd = false;      FileMove("St-Trd_On.txt", FILE_COMMON, "St-Trd_Off.txt", FILE_COMMON); }
   if (Typ==2 || Typ==5) FileMove("ATS-Int_On.txt", FILE_COMMON, "ATS-Int_Off.txt", FILE_COMMON);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, tr_Allow? Bullish? SYMBOL_ARROWUP: SYMBOL_ARROWDOWN: Bullish? 233: 234);
   ObjectSet(ArrowName, OBJPROP_COLOR, Typ==1? clrSkyBlue: Typ==3? clrOrange: Typ==4? clrViolet: 
                                                Bullish? Typ==2? clrMediumSpringGreen: clrLimeGreen: Typ==2? clrViolet: clrDeepPink);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);               //ticket = Clot? 0: ticket;
   ObjectSet(ArrowName, OBJPROP_WIDTH, Typ==2? 4: 5);       bool t_close=false, t_tick=ticket#ifdef v_opfx_0, vtst=(DayOfWeek()==5 && Hour()==23 && Minute()>57)#endif;
   if (AccBalance != AccountBalance()) AccBalance = AccountBalance();         p_Coef = 100.0;   // revoir avec pips2dbl et lot
//Alert("TEST ALLOWED! (1) " + tr_allow + " " + ticket + " " + Clot + " " + t_close + " " + Bullish);
#ifndef v_opfx_0
   if ((Clot || ticket) && ((OrderSelect(floor(Clot? Clot: ticket), SELECT_BY_TICKET) && ! OrderCloseTime()) || ! tr_allow))
#else
   while ((Clot || ticket > 7) && ! t_close && cpt2 < 4) { if ((((vtst && mOrderSelect(mOrdersTotal(magic_nb)==1?0:2,SELECT_BY_POS)) ||
         OrderSelect(floor(Clot? Clot: ticket), SELECT_BY_TICKET)) && ! OrderCloseTime()) || ! tr_Allow)
#endif
      while (! t_close && cpt2 < 4) { t_close = OrderClose(floor(Clot? Clot: ticket), lot, Bullish? Bid: Ask, slip, clrNONE);
//Alert("TEST ALLOWED! (2) " + tr_allow + " " + ticket + " " + Clot + " " + t_close + " " + Bullish);
         if (t_close || ! tr_Allow) { ticket = 0;           total3_ = total3;          if (! tr_Allow) t_close = true;
            Print("** -> OrderClose ",ticket_," ",OrderProfit()," - ",OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",
   DoubleToStr(OrderClosePrice(),5)," - ",DoubleToStr(Bid,5)," - ",DoubleToStr(Ask,5)," - ",TimeToStr(OrderCloseTime(),TIME_MINUTES)," - ",TimeToStr(TimeCurrent(),TIME_MINUTES)," **");
//            p_Coef = fabs(OrderClosePrice() - OrderOpenPrice() / OrderProfit()) / Point; //p_Coef (= 100 pour lot = 0.01)
            total3 += (OrderProfit() + OrderSwap() + OrderCommission()) * p_Coef;
            AccBalance += OrderProfit() + OrderSwap() + OrderCommission();
            if (AccountBalance() - AccBalance > -0.015) Print("** -> AccountBalance() - AccBalance! (1) ",(AccountBalance() - AccBalance)," ***");
            else  Print("** -> AccountBalance() - AccBalance! (2) ",(AccountBalance() - AccBalance)," - ",AccountBalance()," - ",AccBalance," (",
               OrderProfit()," - ",OrderSwap()," - ",OrderCommission()," - ",DoubleToStr(OrderOpenPrice(),5)," - ",DoubleToStr(OrderClosePrice(),5),") ***");
            if (AccBalance != AccountBalance()) { total3 += (AccountBalance() - AccBalance) * p_Coef;
               if (AccountBalance() - AccBalance > -0.015) AccBalance = AccountBalance(); } }
#ifndef v_opfx_0
         else  Sleep(1000); }                             // v attention au spread en fin de marché -> ok si décalage favorable **
#else
         else if (infoMarket && !t_Night && (!vtst || cpt2 < 4)) { Sleep(1000);     if (vtst) cpt2 ++; }       else break; }   //if (vtst) cpt2 ++;
#endif
//Alert("TEST ALLOWED! (3) " + tr_allow + " " + ticket + " " + Clot + " " + t_close + " " + Bullish);
   if (ticket) { Print("** -> Ticket Select ERROR! (1) (cpt ",cpt,", typ ",Typ,") ",GetLastError(),", ticket ",ticket," ***");
#ifndef v_opfx_0
      if (Clot && (ticket==1 || cpt==2)) { ticket = 0;   cpt = 1; }     else cpt ++; }
#else
      if (ticket <= 7 || cpt > 2) { if (! vtst) ticket = 0;     cpt = 1; }       else { cpt ++;      //Clot && 
         if (infoMarket && !t_Night) Sleep(100);         if (mOrderSelect(mOrdersTotal(magic_nb)==1?0:2,SELECT_BY_POS)) {
            ticket = OrderTicket();          Print("*** -> (3) Ticket LOADED! ",ticket," - ... ***"); } } }    cpt2 ++; }
   if (ticket) Print("** -> Ticket Select ERROR! (2) (cpt ",cpt,", typ ",Typ,") ",GetLastError(),", ticket ",ticket,", tr_Allow ",tr_Allow,", t_Night ",t_Night," ***");
#endif
   else if (! Clot || ! tr_Allow) { if (! tr_Allow) { ticket = Clot ? 0 : ticket_ + 1;    //(tmfr=Period())
         if (! Clot) { Print((s2_coporder="** -> ATS 1.01 Ultimate PERIOD_" + (tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
               tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1") + " " + Symbol() + " " + (Bullish? "BUY": "SELL")));
            s1_coporder = "0 Liste_dObjets_EA 0 0 ATS 1.01 Ultimate PERIOD_" + (tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? 
               "M30": tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1") + " " + Symbol() + " " + (Bullish? "BUY": "SELL") + " - | " +
            IntegerToString(Typ) + " " + DoubleToStr(Bullish? Ask: Bid, 2) + " " + IntegerToString(int(Typ==1? blue_time: Time[BarNum])) + " " + IntegerToString(Code) + " " + IntegerToString(Bullish); }
         else { Print((s2_coporder="** -> ATS 1.01 Ultimate PERIOD_" + (tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
               tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1") + " " + Symbol() + " " + (Bullish? "BUY": "SELL") + " CLOT"));
            s1_coporder = "0 Liste_dObjets_EA 0 0 ATS 1.01 Ultimate PERIOD_" + (tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? 
               "M30": tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1") + " " + Symbol() + " " + (Bullish? "BUY": "SELL") + " CLOT | " +
            IntegerToString(Typ) + " " + DoubleToStr(Bullish? Ask: Bid, 2) + " " + IntegerToString(int(Typ==1? blue_time: Time[BarNum])) + " " + IntegerToString(Code) + " " + IntegerToString(Bullish); }
         s2_coporder = TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) + " " + s2_coporder + ", DrawArrow_OS(" + IntegerToString(Typ) + ")";
         r1_coporder = copy_file(s1_coporder, 0);           r2_coporder = copy_file(s2_coporder, 1);           r4_coporder = copy_file((s4_coporder=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) +
            ";Liste dObjets EA;" + DoubleToStr(LinePrice,1) + ";" + (Bullish? "Buy": "Sell") + ";B/A;" + DoubleToStr(Bullish? Ask: Bid, 1) + ";Typ=" + IntegerToString(Typ)), 2);
/*         Alert("ATS 1.01 Ultimate PERIOD_" + ((tmfr=Period())==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
      tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1") + " " + Symbol() + " " + (Bullish? "BUY": "SELL"));*/ }
      else#ifdef v_opfx_0 { if ((tst_5=(((tmfr == PERIOD_H1 || tmfr == PERIOD_M30) && ((FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) &&     // || tmfr == PERIOD_M5
      Bullish) || (FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0) && ! Bullish))) || Typ < 5 || (tmfr <= PERIOD_M15 && (str != "-CHN" || (tst_6 =
      (OrderProfit() / lot < 100 || m3_RSI(0, 2) < 38 || m3_RSI(0, 2) > 62))))))) {       // && (str=="-GLD" || t_night))
        #endif ticket = OrderSend(Symbol(), Bullish? ORDER_TYPE_BUY: ORDER_TYPE_SELL, lot, Bullish? Ask: Bid, slip,#ifndef v_opfx_0 0.0, 0.0, NULL#else str == "-HKG" ?
         round(Bullish ? Ask - SL : Bid + SL) : str == "-GER" && Typ == 9 ? Bullish ? iLowest(NULL, 0, MODE_CLOSE, 5, 0) : iHighest(NULL, 0, MODE_CLOSE, 5, 0) : Bullish ? 
         Ask - SL : Bid + SL, 0.0, (Bullish? "buy": "sell") + " - " + stmfr#endif, magic_nb);
#ifdef v_opfx
       if (OrderProfit() != 0 || OrderSwap() != 0 || OrderCommission() != 0) 
         copy_file_(2, TimeToStr(TimeCurrent())+":"+IntegerToString(Seconds())+"."+IntegerToString(getCurrentMs()%1000)+
            " ** -> OrderSend ("+Typ+") "+ticket+" "+OrderProfit()+" - "+OrderSwap()+" - "+OrderCommission()+" - "+
            DoubleToStr(OrderOpenPrice(),5)+" - "+DoubleToStr(OrderClosePrice(),5)+" **");
       if (OrderSelect(floor(ticket), SELECT_BY_TICKET)) 
         copy_file_(2, TimeToStr(TimeCurrent())+":"+IntegerToString(Seconds())+"."+IntegerToString(getCurrentMs()%1000)+
            " ** -> OrderSend ("+Typ+") "+ticket+" "+OrderProfit()+" - "+OrderSwap()+" - "+OrderCommission()+" - "+
            DoubleToStr(OrderOpenPrice(),5)+" - "+DoubleToStr(OrderClosePrice(),5)+" - Op_Liq2-4 "+Op_Liq2+"-"+Op_Liq4+" **"); }
#else }#endif
       if (! tr_Allow) { Print("NOT ALLOWED! ", tr_Allow);            Alert("NOT ALLOWED! " + tr_Allow); } }
#ifdef v_opfx_0
      if (str == "-CHN" && ! tst_6) t_ngt0 = true;       if (ticket < 0 && tr_Allow) { ticket = 0;
         Print("*** OrderSend failed with error #",GetLastError()," - "+Symbol()+"-"+(Bullish? "Buy": "Sell")+"-"+Period()+" - "+
            DoubleToStr(StringSubstr(str, 1, 3)=="HKG"? round(Bullish? Ask-SL: Bid+SL): Bullish? Ask-SL: Bid+SL, Digits())+" ***"); }
      if (Period() == PERIOD_M30) { FileMove("ATS-Ind_On-Off\\ATS-Ind_Buy.txt", 0, "ATS-Ind_On-Off\\ATS-Ind_Off.txt", 0);
         FileMove("ATS-Ind_On-Off\\ATS-Ind_Sell.txt", 0, "ATS-Ind_On-Off\\ATS-Ind_Off.txt", 0); }
      if (Typ == 5) { bool tst=false;        int t=0, t1=0, t2=0, err1, err2=0;       while(!tst && t<17 && tmfr_n!=Period()) {
         if (Period() == PERIOD_H1 || Period() == PERIOD_M30) { tmfr_ = Period();     GlobalVariableSet(t_ATS_str, Time[0]);
            while(! (tst=ChartSetSymbolPeriod(0, NULL, (tmfr_n=PERIOD_M5))) && t1 < 17) { t1 ++;      Sleep(100); }     err1 = GetLastError();
            if (tst) { Sleep(50);        ChartSetInteger(0, CHART_SCALE, 0, 4);                 tmfr = PERIOD_M5;
//               while((! Chart_M5 || ! int(ChartPeriod(Chart_M5))) && t2 < 17) { t2 ++;    Chart_M5 = chart_find();   Sleep(100); }
               if (! chk_chartm5(8)) { temp = "*** ERROR Chart_M5 (1) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***";
                  Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
               t2 = 0;     while(! ChartSetSymbolPeriod(Chart_M5, NULL, ENUM_TIMEFRAMES(tmfr_)) && t2 < 17) { t2 ++;    Sleep(100); }
               Sleep(50);           ChartSetInteger(Chart_M5, CHART_SCALE, 0, 5);               err2 = GetLastError();
               tim_Chart_M5 = TimeCurrent();       GlobalVariableSet(t1_Chart_str, tim_Chart_M5);
               t5a_Bullish = Bullish;              t5b_Bullish = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0);
               GlobalVariableSet(t1_Bull_str, t5a_Bullish);    GlobalVariableSet(t2_Bull_str, t5b_Bullish);
               GlobalVariableSet(tmfr1_str, tmfr_);            GlobalVariableSet(tmfr0_str, tmfr); } }
/*         else if (Period() == PERIOD_M5 && ! t_night) { tmfr_b = Period();
            while(! (tst=ChartSetSymbolPeriod(0, NULL, (tmfr_n=PERIOD_M1))) && t1 < 17) { t1 ++;      Sleep(100); }     err1 = GetLastError();
            if (tst) { Sleep(50);        ChartSetInteger(0, CHART_SCALE, 0, 4);              tmfr = PERIOD_M1;
//               while((! Chart_M5 || ! int(ChartPeriod(Chart_M5))) && t2 < 17) { t2 ++;    Chart_M5 = chart_find();   Sleep(100); }
               if (! chk_chartm5(9)) Alert("*** ERROR Chart_M5 (2) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***");
               t2 = 0;     while(! ChartSetSymbolPeriod(Chart_M5, NULL, ENUM_TIMEFRAMES(tmfr_b)) && t2 < 17) { t2 ++;     Sleep(100); }
               Sleep(50);           ChartSetInteger(Chart_M5, CHART_SCALE, 0, 5);            err2 = GetLastError();
               tim_Chart_M5b = TimeCurrent();      GlobalVariableSet(t2_Chart_str, tim_Chart_M5b);
               t5a_Bull_b = Bullish;               t5b_Bull_b = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0);
               GlobalVariableSet(t3_Bull_str, t5a_Bull_b);     GlobalVariableSet(t4_Bull_str, t5b_Bull_b);
               GlobalVariableSet(tmfr2_str, tmfr_b);           GlobalVariableSet(tmfr0_str, tmfr); } } */       else t = 17;
         if (tmfr_n==Period()) { temp = "** Passage SANS effet en M"+IntegerToString(tmfr_n)+" avec OrderSend "+(tst_5? "OK": "ANNULE")+" ! (Typ="+IntegerToString(Typ)+
               ", Period()=" + IntegerToString(Period()) + ", Bullish=" + (Bullish) + ") **";
            Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
         else if (tst) { temp = "** Passage en M"+IntegerToString(tmfr_n)+" avec OrderSend "+(tst_5? "OK": "ANNULE")+" ! (Typ="+IntegerToString(Typ)+
               ", Period()=" + IntegerToString(Period()) + ", Bullish=" + (Bullish) + ", t1="+IntegerToString(t1) + ", t2="+IntegerToString(t2) +
               (t2==17 ? ", err2=" + IntegerToString(err2) : "") + ") **";
            Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
            ObjectSet(ArrowName, OBJPROP_ARROWCODE, tr_Allow? tmf_Diff? 215: 216: tmf_Diff? 223: 224);         ObjectSet(ArrowName, OBJPROP_WIDTH, 4); }
         else { if (Period()>PERIOD_M1) { temp = "*** Erreur - Passage en M5 (ou M1) avec OrderSend "+(tst_5? "OK": "ANNULE")+" ! (Typ="+IntegerToString(Typ)+
               ", Period()=" + IntegerToString(Period()) + ", Bullish=" + (Bullish) + ", t1=" + IntegerToString(t1) + ", t=" + IntegerToString(t) +
               ", err1=" + IntegerToString(err1) + ") ***";
            Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }       tst_5b = tst_5;
            if (! tst_5) { tst_5c = Time[0];       ObjectSet(ArrowName, OBJPROP_WIDTH, 2); }       Sleep(100); }     t ++; }         tmf_Diff = false;          if (! tst_5) return true; }
#endif
      endbull = Bullish;      if (! t_tick) if (! OrderSelect(floor(Clot? Clot: ticket), SELECT_BY_TICKET) && ! OrderCloseTime())
            Print("** -> Ticket Select ERROR! (3) (cpt ",cpt,", typ ",Typ,") ",GetLastError(),", ticket ",ticket,", tr_Allow ",tr_Allow,", t_Night ",t_Night," ***");// }
//Alert("TEST ALLOWED! (4) " + tr_allow + " " + ticket + " " + Clot + " " + t_close + " " + Bullish);
      if (ticket > 7) Print("** -> OrderSend ", ticket, " - ", OrderProfit(), " - ", OrderSwap(), " - ", OrderCommission(), " - ",
            DoubleToStr(OrderOpenPrice(),Digits()), " - ", DoubleToStr(SL, Digits()), " **"); } //*/
   if (ticket_ != ticket) Print("** --> Ticket CHANGED! (",Typ,") ",ticket_," ",ticket," - ",Bullish," **");
#ifdef v_opfx_0
   if (GlobalVariableCheck(tck_vstr)) ticket_ = GlobalVariableGet(tck_vstr);           t_tick = (ticket_ > 7);
   if (nb_ticks && OrderSelect(ticket_, SELECT_BY_TICKET) && t_tick) if (OrderProfit() < 0.0) nb_tcks_N ++;    else { nb_ticks = 0;    nb_tcks_N = 0; }
   nb_ticks ++;      if (t_tick && OrderProfit() == 0.0) Alert("***** ATTENTION : OrderProfit() NON RENSEIGNE ! *****");
   bool t_Ntcks=(str=="-HKG" || str=="-CHN" || str=="-GLD");
   if (t_Ntcks && Hour() < 6 && nb_ticks > 2 && nb_ticks == nb_tcks_N + 1) 
      Print("** -> (1) nb_ticks > 2 && nb_ticks == nb_tcks_N + 1 : ",IntegerToString(nb_ticks)," ",IntegerToString(nb_tcks_N)," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," **");
   if (Typ==2 || Typ==5) GlobalVariableSet(bull_str, Bullish);    GlobalVariableSet(tr_Allow || t_tick? tck_vstr: "Ticket0", ticket);     op_Liq_ = false;   cpt = 1;   trd_on = true;
#else
   GlobalVariableSet(bull_str, Bullish);           GlobalVariableSet(tr_allow ? tck_vstr : "Ticket0", ticket);
#endif
//int ticket = OrderSend(parts[10], (parts[11]=="SELL"?1:0), lot, (parts[11]=="SELL"?vBid:vAsk), 1, 0.0, 0.0, tmp2);
//   DrawArrow_OS(LinePrice, BarNum, Code, Bullish, Clot);  */
   return (t_night ? ticket > 0 : true);
}

int copy_file(string tmp, int item) { int handle, it=0;
//   string filename="EA-write-file_Orders.txt";
   MqlDateTime t;   TimeLocal(t);   bool tst=false;
   string filename=item==2? "Price_List.csv": item? "EA_List_Orders_"+stmfr+".log": StringFormat("%d%02d%02d-o.log",t.year,t.mon,t.day);
   while (! tst && it < 7) { if (!FileIsExist(filename)) handle = FileOpen (filename,item==2? FILE_TXT|FILE_WRITE|FILE_COMMON: FILE_TXT|FILE_WRITE);
      else   handle = FileOpen (filename,item==2? FILE_TXT|FILE_READ|FILE_WRITE|FILE_COMMON: FILE_TXT|FILE_READ|FILE_WRITE);
      if (handle != INVALID_HANDLE) {
         if (FileSize(handle)) FileSeek(handle, FileSize(handle), 0);
         tst = FileWrite(handle, TimeToStr(TimeCurrent(), TIME_MINUTES) + " " + tmp);
         if (! tst) Print ("Problème : FileWrite(handle, ("+it+" - "+IntegerToString(GetLastError())+") / "+Symbol()+" ***");
         else if (item) r_copyFtp = copy_FTP(); }
      else Print ("Problème : handle == INVALID_HANDLE. ("+it+" - "+IntegerToString(GetLastError())+") / "+Symbol()+" ***");
   FileClose(handle);   it ++; }
   return(handle);
}

bool copy_FTP() { return(true);     int res=-1, timeout=5000;        char post[], result[];
   string filename="EA_List_Orders_M5.log", URL="http://www.ekom.ovh/logs_ATS/concat_files.php", headers;
   if (SendFTP(filename, NULL)) { Print("**  copy_FTP(): File HAS BEEN copied!  **");
      res = WebRequest("GET", URL, NULL, NULL, timeout, post, 0, result, headers);
      if(res < 0) Print("*** Error in WebRequest. Error code = ", GetLastError(), " ***");
      else {
         PrintFormat("** The file has been successfully loaded, File size = %d bytes **", ArraySize(result));
         int filehandle = FileOpen("EA_List_Orders_All.log", FILE_WRITE|FILE_BIN|FILE_COMMON);
         if (filehandle != INVALID_HANDLE) {
            FileWriteArray (filehandle, result, 0, ArraySize(result));
            FileClose(filehandle); }
      else Print("*** Error in FileOpen. Error code=", GetLastError(), " ***"); } }
   else  Print("*** copy_FTP(): File NOT copied! - error: ", GetLastError(), " ***");
   return(res >= 0);
}

//void DrawArrow(double linePrice,datetime time,bool bullish){
const string PREFIX = "EA_Test";
void DrawArrow(double LinePrice,int BarNum,int Code,bool Bullish,bool Clot) {
   string ArrowName = PREFIX+"_Arr"+(Bullish?"-Up_":"-Down_")+IntegerToString(Code?Code:Bullish?233:234)+"-"+IntegerToString(BarNum)+"-"+IntegerToString(Clot);
   if (ea_show) { ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice);
      ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code? Code: Bullish? 233: 234);
      ObjectSet(ArrowName, OBJPROP_COLOR, Code==3? clrBlack: Clot? clrSkyBlue: Bullish? clrLimeGreen: clrDeepPink);
      ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
      ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
      ObjectSet(ArrowName, OBJPROP_WIDTH, 2); }
}
// DrawArrowUp("Arr_up",Low[barre]-50*Point,DeepSkyBlue);
// DrawArrowDn("Arr_dn",High[barre]+150*Point,DeepPink);

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 CreateLabel(double LinePrice,int BarNum,int Pos,bool Bullish,string vText,int li,int Clot) {
   string LabelName = PREFIX+"_Label_"+IntegerToString(Bullish?233:234)+"-"+IntegerToString(Pos)+"-"+IntegerToString(BarNum)+"-"+IntegerToString(li+1)+"-"+IntegerToString(Clot);
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);     int vX, vY;
   ChartTimePriceToXY(0,0,Time[BarNum],LinePrice,vX,vY);
   ObjectSet(LabelName,OBJPROP_XDISTANCE,vX+(Clot? 5: 0));
   ObjectSet(LabelName,OBJPROP_YDISTANCE,vY+17*li-(Clot? 3: 0));
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,Clot? ANCHOR_LEFT: Bullish?ANCHOR_LEFT_LOWER:ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,12);
   ObjectSet(LabelName,OBJPROP_COLOR,#ifdef v_opfx Pos>=0?#endif  Clot? Clot==1? clrViolet: clrGold: Bullish? clrLimeGreen: clrDeepPink#ifdef v_opfx: clrOrangeRed#endif);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);     // clrAqua
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}
#ifdef v_opfx_0

void CreateObText(double LinePrice,int BarNum,bool Bullish,string vText) {
   double vScale=(WindowPriceMax()-WindowPriceMin())/(!WindowPriceMax()?1.154:WindowPriceMax())/1.154/(1.154-1.061);
   string LabelName = PREFIX+"_Label_"+IntegerToString(Bullish?233:234)+"-"+IntegerToString(BarNum)+" "+IntegerToString(TimeCurrent());
   ObjectCreate(LabelName,OBJ_TEXT,0,Time[BarNum],LinePrice+(Bullish?500:-500)*vScale*Point);
   ObjectSet(LabelName,OBJPROP_ANCHOR,Bullish?ANCHOR_LEFT_LOWER:ANCHOR_LEFT_UPPER);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,12);
   ObjectSet(LabelName,OBJPROP_COLOR, Bullish? clrLimeGreen: clrDeepPink);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);     // clrAqua
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}
#endif

void CreateLabel0(double LinePrice,int BarNum,string vText,int Item,int mX,int mY) {
   string LabelName = PREFIX+"_Label_"+StringSubstr(vText,0,7)+" "+IntegerToString(BarNum)+"-"+IntegerToString(mX)+"-"+IntegerToString(mY);
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);           int vX, vY;
   if (BarNum && LinePrice) ChartTimePriceToXY(0,0,Time[BarNum],LinePrice,vX,vY);
   ObjectSet(LabelName,OBJPROP_XDISTANCE,mX? mX: vX);
   ObjectSet(LabelName,OBJPROP_YDISTANCE,mY? mY: vY);
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,Item? 10: 13);
   ObjectSet(LabelName,OBJPROP_COLOR, !BarNum? clrAqua: !Item? clrYellow: Item==1? clrOrange: clrViolet);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}

void DrawArrowInt(double LinePrice,int BarNum,int Code,bool Bullish) {
   string ArrowName = PREFIX+"_Arr"+(Bullish?"-In_":"-Out_")+IntegerToString(Code?Code:Bullish?233:234)+"-"+IntegerToString(BarNum);
   ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice);
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code?Code:Bullish?233:234);
   ObjectSet(ArrowName, OBJPROP_COLOR, Bullish? clrOrange: clrViolet);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, true);
   ObjectSet(ArrowName, OBJPROP_SELECTED, false);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

void Label_Arrow_Test(int Type,int Pos,int P,int I,int K,double IClose,bool Bull,int mX,int mY,double Total,int &T1[],int &T2[]) {
   CreateLabel0(iClose(NULL,0,Bars-I+1),Bars-I+1,"- "+(Type==1?"reOps":"reCls")+" - "+IntegerToString(Pos)+" - "+
         DoubleToStr(iOpen(NULL,0,Bars-I+1),5)+" - "+DoubleToStr(iHigh(NULL,0,Bars-I+1),5)+" - "+DoubleToStr(iLow(NULL,0,Bars-I+1),5)+" - "+
         DoubleToStr(iClose(NULL,0,Bars-I+1),5)+" - "+IntegerToString(K)+" - "+DoubleToStr((Bull ? 1 : -1) * 
         (iClose(NULL,0,Bars-I+1)-iOpen(NULL,0,Bars-I+1)) / (iHigh(NULL,0,Bars-I+1)-iLow(NULL,0,Bars-I+1)), 2)+" *",Type,mX,mY); //Bull?1:2

   CreateLabel0(iClose(NULL,0,Bars-I+1),Bars-I+1,"- "+(Type==1?"reOps":"reCls")+" fnd - "+IntegerToString(Pos)+"-"+
         IntegerToString(T1[P])+"-"+IntegerToString(T1[P+1])+"-"+IntegerToString(T2[P])+"-"+IntegerToString(T2[P+1])+" - "+
         DoubleToStr((Bull ? 1 : -1) * (IClose - iOpen(NULL,0,Bars-I+1)) / (iHigh(NULL,0,Bars-I+1)-iLow(NULL,0,Bars-I+1)),2)+" - "+
         DoubleToStr((Bull ? 1 : -1) * (IClose - iOpen(NULL,0,Bars-I+1)),5)+" - "+
         DoubleToStr((Bull ? 1 : -1) * (iOpen(NULL,0,Bars-I+1) - (iHigh(NULL,0,Bars-I+1)+iLow(NULL,0,Bars-I+1)) / 2),5)+" - "+
//         DoubleToStr((Bull ? 1 : -1) * (IClose - iOpen(NULL,0,Bars-I+1)) / (iHigh(NULL,0,Bars-I+1)-iLow(NULL,0,Bars-I+1)),2)+
         IntegerToString(Total)+" *",Type,mX,mY+17);   //Bull?1:2 -> Type

   DrawArrowInt(iClose(NULL,0,Bars-I+1), Bars-I+1, 3, Type==1? 1: 0);      DrawArrowInt(iClose(NULL,0,Bars-I+1), Bars-I+1, 5, Type==1? 1: 0); }

void CreateButton(double LinePrice,int BarNum,string vText,int Item,int mX,int mY,int Color) {
   string LabelName = PREFIX+"_Label_"+StringSubstr(vText,0,7);
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);           int vX, vY;
   if (BarNum && LinePrice) ChartTimePriceToXY(0,0,Time[BarNum],LinePrice,vX,vY);
   ObjectSet(LabelName,OBJPROP_XDISTANCE,mX? mX: vX);
   ObjectSet(LabelName,OBJPROP_YDISTANCE,mY? mY: vY);
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE, Item? 10: 9);
   ObjectSet(LabelName,OBJPROP_COLOR, Color? Color==1 && Op_OHL? clrAqua: Color==2 && Op_Show? clrAqua: Color==3 && Op_DDw? 
      clrAqua: /*Color==4 && Op_DDw2? clrAqua: Color==5 && Op_DDw3? clrAqua: */Color==6 && Op_HiLo? clrAqua: clrSilver: clrSkyBlue);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}

void CreateLabel_end(double LinePrice,int BarNum,int Pos,bool Bullish,string vText,int Item,int Itm2) {
   string LabelName = PREFIX+"_end"+IntegerToString(Itm2)+"_Label_"+IntegerToString(Bullish?241:242)+"-"+IntegerToString(Pos)+"-"+IntegerToString(BarNum)+"-0-0";
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);                             if (!Itm2 && LabelNameEnd==NULL) LabelNameEnd = LabelName;
   ObjectSet(LabelName,OBJPROP_XDISTANCE,Item? 150: 10);                if (Itm2 && LabelNameEnd2==NULL) LabelNameEnd2 = LabelName;
   ObjectSet(LabelName,OBJPROP_YDISTANCE,(Pos? 30: 40) + Itm2 * 18);
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_RIGHT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_RIGHT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,Item || Itm2? 10: 12);
   ObjectSet(LabelName,OBJPROP_COLOR, Item?clrSilver:clrGold);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}

/* void ObjectsDelete(int P) {
   int obj_total=ObjectsTotal(), i=0, j=0;
   string name;   for (int pos=0; pos < obj_total; pos ++) {
     name = ObjectName(pos);                          // v OnDeinit(..reason=3), timeframe changé manuellement
     if (pos && (StringSubstr(name,0,8)=="EA_Test_" || StringSubstr(name,0,6) == "EA_pf_" ||
     (P==2 && StringSubstr(name,0,8)!="EA_Check"))) {
         j ++;       if (ObjectDelete(name)) { i ++;  pos --; } } }
   if (P) Print("** ", pos, " objects, DELETED: ", i, " / ", j, " / ", obj_total, " **");
   return; } //*/

void ObjectsPositions(double vScale) {                                              //,tmfr=Period()
#ifdef v_opfx_0
   string str="-"+StringSubstr(EnumToString(magic_nb), 0, 3);
#endif
   int j=0,bar=WindowFirstVisibleBar(),obj_total=ObjectsTotal(),bars=WindowBarsPerChart();       while(! Time[bar-bars+j]) j ++;
   string name/*, stmfr= tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
      tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1" */;
//   Print("** ---> ", WM, " ", WindowPriceMax(), " ", tmfr, " ", stmfr, " ", j, " ", bar, " ", bars, " ", TimeToStr(Time[bar],TIME_MINUTES), " ", TimeToStr(Time[bar-bars+j],TIME_MINUTES), " **");
   datetime OTime;      WM = WindowPriceMax();     for (int pos=0; pos < obj_total; pos ++) {
     name = ObjectName(pos);    OTime = ObjectGet(name,OBJPROP_TIME1);
/*     if (pos && (StringSubstr(name,0,8) == "EA_Check" || StringSubstr(name,0,8) == "EA_Test1" ||
        StringSubstr(name,0,8) == "EA_Test2") && Time[bar] <= OTime && Time[bar-bars+j] >= OTime)
   Print("** --> ",name," ",TimeToStr(OTime,TIME_MINUTES)," ",ObjectGet(name,OBJPROP_PRICE)," ",TimeToStr(ObjectGet(name,OBJPROP_TIME1),TIME_MINUTES)," ",ObjectGet(name,OBJPROP_PRICE1)," **");//*/
     if (pos && (StringSubstr(name,0,8) == "EA_Check" || StringSubstr(name,0,8) == "EA_Test1" || StringSubstr(name,0,8) == "EA_Test2")) //{
//   Print("**(1) -> ", name, " ", TimeToStr(OTime,TIME_MINUTES), " OBJPROP_COLOR: ", ColorToString(ObjectGet(name,OBJPROP_COLOR)), " **");
      if (Time[bar] <= OTime && Time[bar-bars+j]+Period()*60 >= OTime) {
         if (StringSubstr(name,9,StringFind(name,"-",StringFind(name,"-")+1)-9) != stmfr) {   // && stmfr!="M1"
            ObjectSet(name,OBJPROP_BACK,true);       #ifndef v_opfx_0 ObjectSet(name,OBJPROP_PRICE1, WM + 1500 * vScale * Point);
#endif #ifdef v_opfx_0 ObjectSet(name,OBJPROP_PRICE1, WM + 15 * vScale * Point);         ObjectSet(name,OBJPROP_WIDTH, 1);
#endif            if (ObjectGet(name,OBJPROP_COLOR)) { ObjectSet(name,OBJPROP_ZORDER,ObjectGet(name,OBJPROP_COLOR));    ObjectSet(name,OBJPROP_COLOR,clrIndigo); }
/*   Print("**(2a) -> ", name, " ", TimeToStr(OTime,TIME_MINUTES), " OBJPROP_COLOR: ", ColorToString(ObjectGet(name,OBJPROP_COLOR)), " OBJPROP_ZORDER: ", ObjectGet(name,OBJPROP_ZORDER), 
         " OBJPROP_PRICE1: ", ObjectGet(name,OBJPROP_PRICE1), " OBJPROP_BACK: ", ObjectGet(name,OBJPROP_BACK), " **");*/ }
         else {#ifdef v_opfx_0 string tmp=StringSubstr(name,StringSubstr(name,0,7) == "EA_Test"? 7: (StringSubstr(name,8,1)=="-"? StringFind(name,"-",StringFind(name,"-")+1)+1: 8), 1);
           #endif ObjectSet(name,OBJPROP_BACK,false);      ObjectSet(name,OBJPROP_PRICE1, WM -#ifdef v_opfx_0 (tmp=="1"||tmp=="5"? 50+(tmp=="5"? str=="-EUS"?120:80: 0)#else 50#endif: 310)*vScale*Point);
#ifdef v_opfx_0
            if (StringSubstr(name, StringFind(name, "_") - 1, 1) != "5") ObjectSet(name,OBJPROP_WIDTH, 2);
#endif
            if (ObjectGet(name,OBJPROP_ZORDER)) { ObjectSet(name,OBJPROP_COLOR,ObjectGet(name,OBJPROP_ZORDER));      ObjectSet(name,OBJPROP_ZORDER,0); }
/*   Print("**(2b) -> ", name, " ", TimeToStr(OTime,TIME_MINUTES), " OBJPROP_COLOR: ", ColorToString(ObjectGet(name,OBJPROP_COLOR)), " OBJPROP_ZORDER: ", ObjectGet(name,OBJPROP_ZORDER), 
         " OBJPROP_PRICE1: ", ObjectGet(name,OBJPROP_PRICE1), " OBJPROP_BACK: ", ObjectGet(name,OBJPROP_BACK), " **");*/ }
/*   Print("** -> ", name, " ", OTime, " ", ObjectGet(name,OBJPROP_PRICE1), " ", WM, " **");*/ } } //}
   return; }

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

void DrawArrow_pf(double LinePrice,int BarNum,int Code,bool Bullish,bool Clot) {
   string ArrowName = (Code==2||Code==6? "EA": PREFIX)+"_pf_Arr"+(Bullish?"-Up_":"-Down_")+IntegerToString(Code?Code:Bullish?241:242)+"-"+
      IntegerToString(BarNum)+"-"+IntegerToString(Clot)+(Code==2||Code==6? " "+IntegerToString(TimeCurrent()): "");
   ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice);
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code? Code: Bullish? 241: 242);
   ObjectSet(ArrowName, OBJPROP_COLOR, Code==3? clrBlack: Clot? clrSkyBlue: Bullish? clrLimeGreen: clrDeepPink);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

bool DrawArrow_end(double LinePrice,int BarNum,int Code,bool Bullish,bool Clot) {
   string ArrowName = "EA_end_Arr"+((Bullish&&!Clot)||(!Bullish&&Clot)?"-Up_":"-Down_")+IntegerToString(Code?Code:Bullish?241:242)+"-"+
      IntegerToString(BarNum)+"-"+IntegerToString(Clot)+" "+IntegerToString(TimeCurrent());
   if (! ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice)) return false;
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code?Code:Bullish?241:242);
   ObjectSet(ArrowName, OBJPROP_COLOR, Code==3? clrBlack: Clot? clrSkyBlue: Bullish? clrLimeGreen: clrDeepPink);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
   return true;
}

void CreateLabel_pf(double LinePrice,int BarNum,int Pos,bool Bullish,string vText,int li,int Clot) {
   string LabelName = PREFIX+"_pf_Label_"+IntegerToString(Bullish?241:242)+"-"+IntegerToString(Pos)+"-"+IntegerToString(BarNum)+"-"+IntegerToString(li+1)+"-"+IntegerToString(Clot);
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);     int vX, vY;
   ChartTimePriceToXY(0,0,Time[BarNum],LinePrice,vX,vY);
   ObjectSet(LabelName,OBJPROP_XDISTANCE,vX+(Clot? 5: 0));
   ObjectSet(LabelName,OBJPROP_YDISTANCE,vY+17*li-(Clot? 3: 0));
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,Clot? ANCHOR_LEFT: Bullish?ANCHOR_LEFT_LOWER:ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,12);
   ObjectSet(LabelName,OBJPROP_COLOR, Clot? Clot==1? clrViolet: clrGold: Bullish? clrLimeGreen: clrDeepPink);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);     // clrAqua
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}

void CreateLabel0_pf(double LinePrice,int BarNum,string vText,int Item,int mX,int mY) {
   string LabelName = PREFIX+"_pf_Label_"+StringSubstr(vText,0,7)+" "+IntegerToString(BarNum)+"-"+IntegerToString(mX)+"-"+IntegerToString(mY);
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);           int vX, vY;
   if (BarNum && LinePrice) ChartTimePriceToXY(0,0,Time[BarNum],LinePrice,vX,vY);
   ObjectSet(LabelName,OBJPROP_XDISTANCE,mX? mX: vX);
   ObjectSet(LabelName,OBJPROP_YDISTANCE,mY? mY: vY);
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,Item? 10: 13);
   ObjectSet(LabelName,OBJPROP_COLOR, !BarNum? clrAqua: !Item? clrYellow: Item==1? clrOrange: clrViolet);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}

void DrawArrowInt_pf(double LinePrice,int BarNum,int Code,bool Bullish) {
   string ArrowName = "EA_pf_Arr"+(Bullish?"-In_":"-Out_")+IntegerToString(Code?Code:Bullish?241:242)+"-"+IntegerToString(BarNum)+" "+IntegerToString(TimeCurrent());
   ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice);
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, Code?Code:Bullish?241:242);
   ObjectSet(ArrowName, OBJPROP_COLOR, Bullish? clrOrange: clrViolet);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
}

void Label_Arrow_Test_pf(int Type,int Pos,int P,int I,int K,double IClose,bool Bull,int mX,int mY,double Total,int &T1[],int &T2[]) {
   CreateLabel0_pf(iClose(NULL,0,Bars-I+1),Bars-I+1,"- "+(Type==1?"reOps":"reCls")+" - "+IntegerToString(Pos)+" - "+
         DoubleToStr(iOpen(NULL,0,Bars-I+1),5)+" - "+DoubleToStr(iHigh(NULL,0,Bars-I+1),5)+" - "+DoubleToStr(iLow(NULL,0,Bars-I+1),5)+" - "+
         DoubleToStr(iClose(NULL,0,Bars-I+1),5)+" - "+IntegerToString(K)+" - "+DoubleToStr((Bull ? 1 : -1) * 
         (iClose(NULL,0,Bars-I+1)-iOpen(NULL,0,Bars-I+1)) / (iHigh(NULL,0,Bars-I+1)-iLow(NULL,0,Bars-I+1)), 2)+" *",Type,mX,mY); //Bull?1:2

   CreateLabel0_pf(iClose(NULL,0,Bars-I+1),Bars-I+1,"- "+(Type==1?"reOps":"reCls")+" fnd - "+IntegerToString(Pos)+"-"+
         IntegerToString(T1[P])+"-"+IntegerToString(T1[P+1])+"-"+IntegerToString(T2[P])+"-"+IntegerToString(T2[P+1])+" - "+
         DoubleToStr((Bull ? 1 : -1) * (IClose - iOpen(NULL,0,Bars-I+1)) / (iHigh(NULL,0,Bars-I+1)-iLow(NULL,0,Bars-I+1)),2)+" - "+
         DoubleToStr((Bull ? 1 : -1) * (IClose - iOpen(NULL,0,Bars-I+1)),5)+" - "+
         DoubleToStr((Bull ? 1 : -1) * (iOpen(NULL,0,Bars-I+1) - (iHigh(NULL,0,Bars-I+1)+iLow(NULL,0,Bars-I+1)) / 2),5)+" - "+
//         DoubleToStr((Bull ? 1 : -1) * (IClose - iOpen(NULL,0,Bars-I+1)) / (iHigh(NULL,0,Bars-I+1)-iLow(NULL,0,Bars-I+1)),2)+
         IntegerToString(Total)+" *",Type,mX,mY+17);   //Bull?1:2 -> Type

   DrawArrowInt_pf(iClose(NULL,0,Bars-I+1), Bars-I+1, 3, Type==1? 1: 0);      DrawArrowInt(iClose(NULL,0,Bars-I+1), Bars-I+1, 5, Type==1? 1: 0); }

bool DrawArrow_chst(double LinePrice,int BarNum,int I) { //int tmfr=Period();
   string/* stmfr= tmfr==PERIOD_M1? "M1": tmfr==PERIOD_M5? "M5": tmfr==PERIOD_M15? "M15": tmfr==PERIOD_M30? "M30": 
      tmfr==PERIOD_H1? "H1": tmfr==PERIOD_H4? "H4": tmfr==PERIOD_D1? "D1": tmfr==PERIOD_W1? "W1": "MN1", */
      ArrowName="EA_Chck2-"+stmfr+"-"+IntegerToString(I)+"_"+IntegerToString(BarNum)+" "+IntegerToString(Time[BarNum]);
   if (! ObjectCreate(ArrowName,OBJ_ARROW,0,Time[BarNum],LinePrice)) {
//      Print("*** ObjectCreate Error : "+IntegerToHexString(GetLastError())+" / "+DoubleToStr(LinePrice,5)+" - "+IntegerToHexString(BarNum)+" ***");
      return false; }
   if (I) LabelNameStp = ArrowName;
   ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
#ifndef v_opfx_0
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, I==3? 251: 252);
#else
   ObjectSet(ArrowName, OBJPROP_ARROWCODE, I==3? 251: I==4? fl_Trade? 252: 253: I==5? 187: 252); // I==4? 252 si FollowTrade activé
#endif
   ObjectSet(ArrowName, OBJPROP_COLOR, I==1||I>=4? I==1&&ticket>7? clrGold: clrSilver: clrSkyBlue);
   ObjectSet(ArrowName, OBJPROP_SELECTABLE, 0);
   ObjectSet(ArrowName, OBJPROP_SELECTED, 0);
   ObjectSet(ArrowName, OBJPROP_WIDTH, 2);
//   ObjectSet(ArrowName, OBJPROP_YDISTANCE, 55);
   return true;
}

void CreateLabel_st(double LinePrice,int BarNum,string vText,bool bullish,bool now) {
   string LabelName = "EA_Stop-Trade-"+IntegerToString(BarNum)+" "+IntegerToString(Time[BarNum]);
   ObjectCreate(LabelName,OBJ_TEXT, 0, Time[BarNum], LinePrice);
   LabelNameSt2 = LabelName;
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,9);
   ObjectSet(LabelName,OBJPROP_COLOR, now? clrPink: bullish? clrLightGreen: clrGold);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}

bool op_case0;
void ObjectsDelete(int P, string str#ifdef v_opfx_0, bool chk, bool old#endif) {
   int obj_total=ObjectsTotal(), i=0, j=0;
   string name;
   for (int pos=0;pos<obj_total;pos++) {
     name = ObjectName(pos);
#ifndef v_opfx_0
     if (pos && ((str!="" && StringSubstr(name,0,StringLen(str)+4)=="EA_"+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 ++;  pos --; } } }
#else
     if (pos && ((str!="" && StringSubstr(name,0,StringLen(str)+4)=="EA_"+str+"-") || 
     (str=="" && ((old && Period() >= PERIOD_M5 && (ObjectGet(name, OBJPROP_TIME2) > 0 ?
        ObjectGet(name, OBJPROP_TIME2) : ObjectGet(name, OBJPROP_TIME1)) < Time[H1 < H3? 500: 300]) ||
     (chk && (StringSubstr(name,0,9)=="EA_Chck2-" || StringSubstr(name,0,9)=="EA_Chck3-")) || 
     (! chk && (StringSubstr(name,0,8) == "EA_Test_" || (op_case0 && StringSubstr(name,0,6) == "EA_pf_" && 
     ! iBarShift(NULL,0,fmax(ObjectGetInteger(0,name,OBJPROP_TIME1),ObjectGetInteger(0,name,OBJPROP_TIME)),false)) ||
     (P==2 && StringSubstr(name,0,8) != "EA_Check"))))))) { j ++;     if (ObjectDelete(name)) { i ++;  pos --; } } }
#endif
   if (P) Print (pos, " objects, DELETED: ", i, " / ", j, " / ", obj_total);
   return; }
#ifdef v_opfx_0

void OnTimer() {
   if (TimeCurrent() == prevTimeCurrent){
      Comment ("Market is CLOSED - Local Time : ",TimeLocal()," - ",Hour(),":",Minute()," *");
      infoMarket = FALSE; }

   else {
//      Comment ("Market is OPEN - Local Time : ",TimeLocal()," - ",Hour(),":",Minute()," *");
      infoMarket = TRUE; }

  prevTimeCurrent = TimeCurrent(); }

void copy_file_(int Item, string tmp) { int handle;
   string filename=Item < 3? "EA-write-file_List-Trades("+IntegerToString(Item+1)+").txt": "EA-write-file_List TF + HA.txt";
   if (!FileIsExist(filename)) handle = FileOpen (filename,FILE_TXT|FILE_WRITE);
   else   handle = FileOpen (filename,FILE_TXT|FILE_READ|FILE_WRITE);
   if (handle != INVALID_HANDLE) {
       if (FileSize(handle)) FileSeek(handle, FileSize(handle), 0);
       FileWrite(handle, tmp); }
//   else Print ("Problème : handle == INVALID_HANDLE. (2) / "+vSymbol+" ***");
   FileClose(handle); }

int copy_time(string str) { int handle;
   string filename="EA_Time_Synchro.txt";
   handle = FileOpen (filename,FILE_TXT|FILE_WRITE);
   if (handle != INVALID_HANDLE) {
       FileWrite(handle, str==""? (s_coptime=TimeToStr(TimeCurrent())+":"+IntegerToString(Seconds())): str); }
//   else Print ("Problème : handle == INVALID_HANDLE. (2) / "+vSymbol+" ***");
   FileClose(handle);
   return(handle); }

void DrawArrow_OS_(int Mode, string temp) {
/*  switch(Mode) {
      case 0 : 
temp = "** -> DrawArrow_OS ATS "+(obj_bars[prv_pos] >= Bars-1)+" "+bull+" "+Bid+" "+Ask+" "+prv_pos+" "+
      obj_bars[prv_pos]+" "+(Bars-obj_bars[prv_pos])+" "+TimeToStr(Time[Bars-obj_bars[prv_pos]],TIME_MINUTES)+" | "+pos+" "+iClose(NULL,0,Bars-i+1)+" "+vScale+" **");
      case 1 :
temp = "** -> DrawArrow_OS *1 "+bull+" "+t_clo+" "+Bid+" "+Ask+" "+i+" "+j+" "+Bars+" "+(Bars-i)+" "+
               TimeToStr(Time[Bars-i],TIME_MINUTES)+" | "+pos+" "+obj_prClots[pos]+" "+vScale+" **";
      case 2 :
temp = "** -> DrawArrow_OS *2 "+bull+" "+Bid+" "+Ask+" "+p+" "+obj_pos[p-1]+" "+
               obj_bars[obj_pos[p-1]]+" | "+pos+" "+obj_Prices[pos]+" "+vScale+" **";
      case 3 :
temp = "** -> DrawArrow_OS *3 "+bull+" "+t_clo+" "+Bid+" "+Ask+" "+i+" "+Bars+" "+(Bars-i+1)+" "+
               TimeToStr(Time[Bars-i+1],TIME_MINUTES)+" | "+pos+" "+obj_prClots[pos]+" "+vScale+" **";
      case 4 :
temp = "** -> DrawArrow_OS *4 "+bull+" "+t_clo+" "+Bid+" "+Ask+" "+i+" "+Bars+" "+(Bars-i+1)+" "+
                  TimeToStr(Time[Bars-i+1],TIME_MINUTES)+" | "+pos+" "+obj_prClots[pos]+" "+vScale+" **";
      case 5 :
temp = "** -> DrawArrow_OS *5 "+(obj_bars[prv_pos] >= Bars-1)+" "+bull+" "+Bid+" "+Ask+" "+prv_pos+" "+
      obj_bars[prv_pos]+" "+(Bars-obj_bars[prv_pos])+" "+TimeToStr(Time[Bars-obj_bars[prv_pos]],TIME_MINUTES)+" | "+pos+" "+iClose(NULL,0,Bars-i+1)+" "+vScale+" **";
      }*/
copy_file_(1, TimeToStr(TimeCurrent())+":"+IntegerToString(Seconds())+"."+IntegerToString(getCurrentMs()%1000)+" "+temp); }

uint prevSecondTick=0;
uint getCurrentMs() {
    return(GetTickCount() - prevSecondTick); }

bool DCC_Check() { // Dark Cloud Cover
      int i=0;    double tmpOpClo, tmpClose, midOpClo;      str_DCC = "";
      tmpOpClo = (fabs(iOpen(NULL,0,i+4) - iClose(NULL,0,i+4)) + fabs(iOpen(NULL,0,i+2) -
         iClose(NULL,0,i+2)) + fabs(iOpen(NULL,0,i+3) - iClose(NULL,0,i+3))) / 3.0;
      tmpClose = (fmax(iOpen(NULL,0,i+4), iClose(NULL,0,i+4)) + fmax(iOpen(NULL,0,i+2), 
         iClose(NULL,0,i+2)) + fmax(iOpen(NULL,0,i+3), iClose(NULL,0,i+3))) / 3.0;
      midOpClo = (iOpen(NULL,0,i+1) + iClose(NULL,0,i+1)) * 0.5;

      if (Open[i+1] < Close[i+1] && //Open[i+1] < Close[i] &&
         Open[i] > (High[i+1] - (Close[i+1] - Open[i+1]) / 7.0) &&
         Close[i] < (Open[i+1] + (Close[i+1] - Open[i+1]) / 3.0) &&
         fabs(iOpen(NULL,0,i+1) - iClose(NULL,0,i+1)) > tmpOpClo * 1.75 &&
         midOpClo > tmpClose) {      //  && i == 114     (^ attention ,Bars-i+1) dans d'autres codes)
//Print("** Dark Cloud Cover: ",TimeToStr(Time[i],TIME_DATE|TIME_MINUTES)," - "+DoubleToStr(tmpOpClo, 5)+" "+DoubleToStr(fabs(iOpen(NULL,0,i+1) - iClose(NULL,0,i+1)), 5)+" **");

         ObjectCreate("Dark Cloud Cover "+DoubleToStr(i,0),OBJ_ARROW,0,Time[i],High[i]+25*Point);
         ObjectSet("Dark Cloud Cover "+DoubleToStr(i,0),OBJPROP_ARROWCODE,234);
         ObjectSet("Dark Cloud Cover "+DoubleToStr(i,0),OBJPROP_COLOR,Yellow);
         ObjectSet("Dark Cloud Cover "+DoubleToStr(i,0),OBJPROP_WIDTH,1);
         str_DCC = "Dark Cloud Cover";    return(true); }

      tmpClose = (fmin(iOpen(NULL,0,i+4), iClose(NULL,0,i+4)) + fmin(iOpen(NULL,0,i+2), 
         iClose(NULL,0,i+2)) + fmin(iOpen(NULL,0,i+3), iClose(NULL,0,i+3))) / 3.0;

      if (Open[i+1] > Close[i+1] && //Open[i+1] > Close[i] &&
         Open[i] < (Low[i+1] + (Close[i+1] - Open[i+1]) / 7.0) &&
         Close[i] > (Open[i+1] - (Close[i+1] - Open[i+1]) / 3.0) &&
         fabs(iOpen(NULL,0,i+1) - iClose(NULL,0,i+1)) > tmpOpClo * 1.75 &&
         midOpClo < tmpClose) {      //  && i == 114
//Print("** Piercing Line: ",TimeToStr(Time[i],TIME_DATE|TIME_MINUTES)," - "+DoubleToStr(tmpOpClo, 5)+" "+DoubleToStr(fabs(iOpen(NULL,0,i+1) - iClose(NULL,0,i+1)), 5)+" **");

         ObjectCreate("Piercing Line "+DoubleToStr(i,0),OBJ_ARROW,0,Time[i],High[i]-55*Point);
         ObjectSet("Piercing Line "+DoubleToStr(i,0),OBJPROP_ARROWCODE,233);
         ObjectSet("Piercing Line "+DoubleToStr(i,0),OBJPROP_COLOR,Pink);
         ObjectSet("Piercing Line "+DoubleToStr(i,0),OBJPROP_WIDTH,1);
         str_DCC = "Piercing Line";       return(true); }

   return(false); }

int mOrdersTotal(int mag_nb) { int total=OrdersTotal(), mtotal=0;
  if (! mag_nb || ! magic_on) return(total);

  for (int pos=0; pos < total; pos ++) {
     if (! OrderSelect(pos, SELECT_BY_POS)) continue;
     if (OrderMagicNumber() == mag_nb || (OrderSymbol() == Symbol() && Symbol() != "EURUSDp")) mtotal ++; }
  return(mtotal); }

bool mOrderSelect(int Pos, bool notused) {
  if (! magic_nb || ! magic_on) return(OrderSelect(Pos, SELECT_BY_POS));
  int total=OrdersTotal();    bool tst=false;

  for (int pos=0; pos < total && ! tst; pos ++) {
     if (! OrderSelect(pos, SELECT_BY_POS)) continue;
     if (OrderMagicNumber() == magic_nb || (OrderSymbol() == Symbol() && Symbol() != "EURUSDp")) { tst = true;    break; } }
  return(tst); }

long chart_find() { // recherche le chart de même symbole et autre période
   long currChart, thisChart=0, prevChart=ChartFirst(), this_ID=ChartID();
   int i=0, limit=25, thisTmfr;    // = ChartPeriod(prevChart);
//   sym_target = EnumToString(Symbol_Target);       //per_target = PERIOD_H1;                // chart cible pour le multi timeframe **
//   per_target = !Period_Target? PERIOD_M1: Period_Target==1? PERIOD_M5: Period_Target==2? PERIOD_M15: Period_Target==3? PERIOD_M30: 
//      Period_Target==4? PERIOD_H1: Period_Target==5? PERIOD_H4: Period_Target==6? PERIOD_D1: Period_Target==7? PERIOD_W1: PERIOD_MN1;
   if (! Chart_M5) Chart_M5 = GlobalVariableGet(Chart_str);
   tmfr_ = Period() == PERIOD_H1 || Period() == PERIOD_M30 ? Period() : tmfr_ ? tmfr_ : PERIOD_H1;
//   per_target = Period() == PERIOD_H1 || Period() == PERIOD_M30 || Period() == PERIOD_M1 ? PERIOD_M5 : NULL;
   while(i < limit && ! thisTmfr) {
      currChart = ChartNext(prevChart);      if (currChart < 0) break;        if (currChart != this_ID &&
      ChartSymbol(currChart) == Symbol() && ChartPeriod(currChart) == PERIOD_M5) { thisChart = currChart;      thisTmfr = ChartPeriod(currChart);
         Print("* Chart ",(i+2)," ",ChartSymbol(currChart)," ",(thisTmfr==PERIOD_M1? "M1": thisTmfr==PERIOD_M5? "M5": thisTmfr==PERIOD_M15? "M15": thisTmfr == 
            PERIOD_M30? "M30": thisTmfr==PERIOD_H1? "H1": thisTmfr==PERIOD_H4? "H4": thisTmfr==PERIOD_D1? "D1": thisTmfr==PERIOD_W1? "W1": "MN1")," ID = ",currChart); }
      prevChart = currChart;        i ++; }
   if (! thisTmfr) { Print("*** PAS DE CHART CIBLE TROUVE ! ***");         return(Chart_M5); }
   else { GlobalVariableSet(Chart_str, thisChart);          Print("** CHART CIBLE TROUVE ! "+thisChart+" **"); }
   return(thisChart); }

bool chk_chartm5(int i) { int t=0;
   while((! Chart_M5 || (!int(ChartPeriod(Chart_M5)) && !int(ChartPeriod(Chart_M5+t)) && !int(ChartPeriod(Chart_M5-t)))) && t < 13) t ++;

   if ((ChartPeriod(Chart_M5 + t) > 0 || ChartPeriod(Chart_M5 - t) > 0) && t > 0)
      if (ChartPeriod(Chart_M5 + t) > 0) Chart_M5 = Chart_M5 + t;
      else if (ChartPeriod(Chart_M5 - t) > 0) Chart_M5 = Chart_M5 - t;

   if (! Chart_M5) Chart_M5 = chart_find();

   if (GlobalVariableCheck(i_Cht_str)) i_Cht_M5 = GlobalVariableGet(i_Cht_str);
   if (i!=2 || t) if (t < 13) Print("** ChartPeriod(Chart_M5 +/- t) : "+IntegerToString(i)+" / "+IntegerToString(t)+" - "+TimeToStr(i_Cht_M5, TIME_SECONDS)+" **");
      else  Print("*** ChartPeriod(Chart_M5 +/- t) : PAS TROUVE ! -> i_Cht_M5 "+TimeToStr(i_Cht_M5, TIME_SECONDS)+" ***");
   return(t < 13); }    // Chart_M5 > 0

datetime tim_L_Objs7(long thisChart) { int obj_total=ObjectsTotal(thisChart);
   string name;      datetime OTim1;      bool t_neutral, t_liquid_s, t_liquid_b;
   for (int pos = 0; pos < obj_total; pos ++) {
      name = ObjectName(thisChart,pos);     //type = ObjectGetInteger(thisChart,name,OBJPROP_TYPE);
//      t_neutral0 = t_neutral;   t_liquid_b0 = t_liquid_b;   t_liquid_s0 = t_liquid_s;
      if ((t_neutral=(StringFind(name, "neutral") > 0)) ||
      (t_liquid_b=(StringFind(name, "liquid_buy") > 0)) || (t_liquid_s=(StringFind(name, "liquid_sell") > 0)))
         if (ObjectGet(name, OBJPROP_TIME1) > OTim1 && (t_liquid_b || t_liquid_s) && (! t_liquid_b || ! t_liquid_s))
//         if ((! t_neutral0 && t_neutral) || (! t_liquid_b0 && t_liquid_b) || (! t_liquid_s0 && t_liquid_s)) i = 0;
            OTim1 = ObjectGetInteger(thisChart, name, OBJPROP_TIME1); }
   return(OTim1); }

datetime tim_L_Rects() { int obj_total=ObjectsTotal();
   string name;      datetime OTim1;
   for (int pos = 0; pos < obj_total; pos ++) {
      name = ObjectName(pos);     //type = ObjectGetInteger(thisChart,name,OBJPROP_TYPE);
      if (StringFind(name, "rect") > 0) OTim1 = ObjectGet(name, OBJPROP_TIME1); }
   return(OTim1); }

bool typ_L_Rects() { int obj_total=ObjectsTotal();
   string name;      bool t_neutral, t_liquid_s, t_liquid_b, liquid_buy;
   for (int pos = 0; pos < obj_total; pos ++) { name = ObjectName(pos);
      if (((t_neutral=(StringFind(name, "neutral") > 0)) ||
      (t_liquid_b=(StringFind(name, "liquid_buy") > 0)) || (t_liquid_s=(StringFind(name, "liquid_sell") > 0)))
      && (! t_liquid_b || ! t_liquid_s)) liquid_buy = t_liquid_b; }
   return(liquid_buy); }

double set_Rectangles() { if (pass1) { objRects_del(0, "");    // ArrayInitialize(Rect_Ns, "");
      ArrayInitialize(Rect_Hs, 0);     ArrayInitialize(Rect_Ks, -1); }
   else { for (int i = 0; i < ArraySize(Rect_Hs) - 1; i ++) if (! Rect_Ks[i] &&
      Rect_Ns[i][0] != "") { ObjectDelete(Rect_Ns[i][0]);      ObjectDelete(Rect_Ns[i][1]);      if (NR && i > 7) { NR --;
         Rect_Hs[i][0] = 0.0;       Rect_Hs[i][1] = 0.0;       Rect_Ks[i] = -1;     Rect_Ns[i][0] = "";     Rect_Ns[i][1] = ""; } }
      while (Rect_Hs[40][0] > 0.0) { for (i = ArraySize(Rect_Hs)-1; i >= 0; i --) {
            Rect_Hs[ArraySize(Rect_Hs) - i-1][0] = Rect_Hs[ArraySize(Rect_Hs) - i][0];
            Rect_Hs[ArraySize(Rect_Hs) - i-1][1] = Rect_Hs[ArraySize(Rect_Hs) - i][1];
            Rect_Ns[ArraySize(Rect_Ns) - i-1][0] = Rect_Ns[ArraySize(Rect_Ns) - i][0];
            Rect_Ns[ArraySize(Rect_Ns) - i-1][1] = Rect_Ns[ArraySize(Rect_Ns) - i][1];
            Rect_Ks[ArraySize(Rect_Ks) - i-1] = Rect_Ks[ArraySize(Rect_Ks) - i]; }
         Rect_Hs[ArraySize(Rect_Hs)-1][0] = 0.0;   Rect_Hs[ArraySize(Rect_Hs)-1][1] = 0.0;
         Rect_Ks[ArraySize(Rect_Ks) - 1] = -1;     Rect_Ns[ArraySize(Rect_Ns) - 1][0] = "";
         Rect_Ns[ArraySize(Rect_Ns) - 1][1] = "";        NR --; } }
   double ADX_bars[50][3], rHigh, rLow, rHigh_, rLow_, tmp, rect_H;
   int nr, j_, J, K, vX1, vY1, vX2, vY2;        bool tst, r_on=false;
   for (int k = 0; k < (pass1? 100: 1); k += 15) { ArrayInitialize(ADX_bars, 0);
      for (i = k; i < k + 50; i ++) if ((rHigh_ = iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,i-k,k))) > 
      (rLow_ = iLow(NULL,0,iLowest(NULL,0,MODE_LOW,i-k,k)))) { ADX_bars[i-k][0] = i > k+4 ? (i-k) / (rHigh_ - rLow_) : 0;
         ADX_bars[i-k][1] = iCustom(NULL, 0, "New folder\\ADX.ex4", 0, i) < 30 && iCustom(NULL, 0, "New folder\\ADX.ex4", 1, i) < 30 &&
            iCustom(NULL, 0, "New folder\\ADX.ex4", 2, i) < 30 ? 1.0 : 0.0;
         if (i > k + 4) { for (int j = k; j < i; j ++) ADX_bars[i-k][2] += ADX_bars[j-k][1];
if (ADX_bars[i-k][2] > (i-k)) Alert("*** ADX_bars[i-k][2] > (i - k) : "+IntegerToString(ADX_bars[i-k][2])+" "+IntegerToString(i - k)+" ***");
            ADX_bars[i-k][2] = ADX_bars[i-k][2] / (i-k) * 1.0; } }
      int iRange, l;    j = 0;   for (i = k + 4; i < k + 50; i ++) if (ADX_bars[i-k][0] * ADX_bars[i-k][2] > iRange) {
         if (ADX_bars[i-k][2] > 0.8) { iRange = ADX_bars[i-k][0] * ADX_bars[i-k][2];      l = j;      j = i; } }
      if (rHigh != iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,j-k,k)) || rLow != iLow(NULL,0,iLowest(NULL,0,MODE_LOW,j-k,k))) { vY1 = 0;   vY2 = 0;
         rHigh = 0;        rLow = 0;      while (rHigh == 0.0 || rLow == 0.0) {
            rHigh = iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,j-k,k));     rLow = iLow(NULL,0,iLowest(NULL,0,MODE_LOW,j-k,k)); }
         ChartTimePriceToXY(0, 0, Time[j], rHigh, vX1, vY1);
         ChartTimePriceToXY(0, 0, Time[k], rLow, vX2, vY2);          J = j;      K = k;      tst = !j_ || j_ < j;
if (j && vY1 == vY2) Alert("***** vY1 == vY2 : "+IntegerToString(vY1)+" "+IntegerToString(vY2)+" "+IntegerToString(vY2-vY1)+" "+IntegerToString(nr)+" *****");
         if (j && ADX_bars[j-k][2] > 0.8 && (((vY2-vY1)*1.0 < (vX2-vX1)*0.8 && tst) || ((vY2-vY1)*1.0 < (vX2-vX1)*1.25 && !tst))) {
            while (iHigh(NULL, 0, J+2) < rHigh && iLow(NULL, 0, J+2) > rLow && J-j < 17) J ++;
            while (iHigh(NULL, 0, K-2) < rHigh && iLow(NULL, 0, K-2) > rLow && K && k-K < 17) K --;
            if (tst) { while (J && (iStdDev(NULL, 0, J-K, K, MODE_SMA, PRICE_TYPICAL, 0) / Point() / 100 > 1.0 ||
                  (tmp=iMA(NULL, 0, J-K, 0, MODE_SMA, PRICE_CLOSE, K)) < rLow + (rHigh-rLow)*0.3 ||
                  tmp > rLow + (rHigh-rLow) * 0.7)) { J --;       K ++; }
               while (iStdDev(NULL, 0, J+2-K, K, MODE_SMA, PRICE_TYPICAL, 0) / Point() / 100 < (Point()==0.00001 ||
                  Point()==0.001? 0.8: 1.0) && (tmp=iMA(NULL, 0, J-K, 0, MODE_SMA, PRICE_CLOSE, K)) > rLow + (rHigh-rLow)*0.3 &&
                  tmp < rLow + (rHigh-rLow) * 0.7 && J - j < 17) J ++;
               while (K && iStdDev(NULL, 0, J-K+2, K-2, MODE_SMA, PRICE_TYPICAL, 0) / Point() / 100 < (Point()==0.00001 ||
                  Point()==0.001? 0.8: 1.0) && (tmp=iMA(NULL, 0, J-K, 0, MODE_SMA, PRICE_CLOSE, K)) > rLow + (rHigh-rLow)*0.3 &&
                  tmp < rLow + (rHigh-rLow) * 0.7 && K && k - K < 17) K --; }
            if (J - K > 4) { rHigh = 0;      rLow = 0;      while (rHigh == 0.0 || rLow == 0.0) {
                  rHigh = iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,J-K,K));      rLow = iLow(NULL,0,iLowest(NULL,0,MODE_LOW,J-K,K)); }
               Rect_Ns[NR][0] = RectangleCreate(Time[J], rHigh, Time[K] + Period()*60, rLow, tst? 0: 1);             if (tst)
               Rect_Ns[NR][1] = CreateLabelR(rHigh, J, IntegerToString(nr+1)+" - "+IntegerToString(J-K)+" "+IntegerToString(K)+" "+DoubleToStr(ADX_bars[j-k][2],2)+" "+
               DoubleToStr((vY2-vY1)*1.0/(vX2-vX1)*1.0, 2)+" "+DoubleToStr(iStdDev(NULL, 0, J-K, K, MODE_SMA, PRICE_TYPICAL, 0)/Point()/100, 2), nr, tst? 0: 1);
               Rect_Hs[NR][0] = rHigh;       Rect_Hs[NR][1] = rLow;     Rect_Ks[NR] = K;        NR ++;
               if (! K && iBarShift(NULL, 0, Time[J]) > rect_HG) rect_HG = iBarShift(NULL, 0, Time[J]);
               if (! K && rect_H < rHigh - rLow) rect_H = rHigh - rLow; }     nr ++;      j_ = tst? J: j_;     r_on = r_on? r_on: ! K; } } }
   return(r_on? rect_H: 0.0); }

void ChangeRectangleEmptyPoints(datetime &time1,double &price1,datetime &time2,double &price2) {
   if (! time1) time1=TimeCurrent();
   if (! price1) price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID);
   if (! time2) { datetime temp[10];
      CopyTime(Symbol(), Period(), time1, 10, temp);
      time2 = temp[0]; }
   if (! price2) price2 = price1 - 300 * SymbolInfoDouble(Symbol(),SYMBOL_POINT); }

string RectangleCreate(datetime time1,double price1,datetime time2,double price2,int Item) {
   ChangeRectangleEmptyPoints(time1, price1, time2, price2);         ResetLastError();
   string RectName = "EA_Rectangle_"+IntegerToString(iBarShift(NULL,0,time1,false))+"-"+IntegerToString(iBarShift(NULL,0,time2,false))+
      " " + IntegerToString(TimeCurrent());
   if (! ObjectCreate(RectName, OBJ_RECTANGLE, 0, time1, price1, time2, price2)) {
      Print(__FUNCTION__, ": failed to create a rectangle! Error code = ",GetLastError());   return(false); }
   ObjectSetInteger(0, RectName, OBJPROP_COLOR, Item? clrCornsilk: clrAqua);
   ObjectSetInteger(0, RectName, OBJPROP_STYLE, Item? STYLE_DOT: STYLE_SOLID);
   ObjectSetInteger(0, RectName, OBJPROP_WIDTH, 1);
   ObjectSetInteger(0, RectName, OBJPROP_FILL, false);
   ObjectSetInteger(0, RectName, OBJPROP_BACK, false);
   ObjectSetInteger(0, RectName, OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0, RectName, OBJPROP_SELECTED, false);
   ObjectSetInteger(0, RectName, OBJPROP_HIDDEN, true);
   ObjectSetInteger(0, RectName, OBJPROP_ZORDER, 0);
   return(RectName); }

void objRects_del(bool L,string Line_N) {  // int P
   int I=0, J=0, P=0, obj_total=ObjectsTotal();
   string name;   for (int pos=0; pos < obj_total; pos ++) { name = ObjectName(pos);      if (! L || name != Line_N)
      if (StringSubstr(name,0,(L? 10: 13)) == "EA_"+(L? "R-Line": "Rectangle")+"_" || StringSubstr(name,0,13) == "EA_Rec-Label_") {
         J ++;       if (ObjectDelete(name)) { I ++;     pos --; } } }
   if (P) Print("** ", pos, " objects, DELETED: ", I, " / ", J, " / ", obj_total, " **");
  return; }

string CreateLabelR(double LinePrice,int BarNum,string vText,int Nr,int Item) {
   string LabelName = "EA_Rec-Label_"+DoubleToStr(LinePrice,Digits())+"-"+IntegerToString(BarNum)+"-"+IntegerToString(Nr)+" "+IntegerToString(TimeCurrent());
   ObjectCreate(LabelName,OBJ_TEXT, 0, Time[BarNum], LinePrice);
   ObjectSet(LabelName,OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
   ObjectSetString(0,LabelName,OBJPROP_TEXT, vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE, 8);
   ObjectSet(LabelName,OBJPROP_COLOR, Item? clrCornsilk: clrTurquoise);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
   ObjectSet(LabelName, OBJPROP_ZORDER, 10);
   return(LabelName); }

string LineCreate(double price) { ResetLastError();
   string LineName = "EA_R-Line_" + IntegerToString(TimeCurrent());
   if (! ObjectCreate(LineName, OBJ_HLINE, 0, 0, price)) {
      Print(__FUNCTION__, ": failed to create a rectangle! Error code = ",GetLastError());   return(false); }
   ObjectSetInteger(0, LineName, OBJPROP_COLOR, clrCornsilk);
   ObjectSetInteger(0, LineName, OBJPROP_STYLE, STYLE_DOT);
   ObjectSetInteger(0, LineName, OBJPROP_WIDTH, 1);
   ObjectSetInteger(0, LineName, OBJPROP_FILL, false);
   ObjectSetInteger(0, LineName, OBJPROP_BACK, false);
   ObjectSetInteger(0, LineName, OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0, LineName, OBJPROP_SELECTED, false);
   ObjectSetInteger(0, LineName, OBJPROP_HIDDEN, true);
   ObjectSetInteger(0, LineName, OBJPROP_ZORDER, 0);
   return(LineName); }

void Liqu_x2_tf(string str) { int t1=0, t2=0, err;       bool tst;     string temp;
   if (Period() == PERIOD_M15) { GlobalVariableSet(tmfr0_str, PERIOD_M5);
      while(! (tst=ChartSetSymbolPeriod(0, NULL, PERIOD_M5)) && t1 < 17) { t1 ++;      Sleep(100);       tim_M15 = Time[0]; }       if (tst) 
         temp = "** Passage en M5 (x2) à "+TimeToStr(TimeCurrent(),TIME_MINUTES)+" ! (Period()="+IntegerToString(Period())+", t1="+IntegerToString(t1)+") **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
      return; }

   if (Period() > PERIOD_M15 || Period() <= PERIOD_M5) {
    if (! chk_chartm5(10)) Alert("*** ERROR Chart_M5 (10) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***");
    if (StringTrimLeft(ChartSymbol(Chart_M5)) != "") {   if (Period() > PERIOD_M15) tmfr_ = Period();
      if (Period() == PERIOD_M5) tmfr_b = Period();      if (Period() == PERIOD_M1) tmfr_ = PERIOD_H1;
      while(! (tst=ChartSetSymbolPeriod(0, NULL, Period()==PERIOD_M5?PERIOD_M1:Period()==PERIOD_M1?PERIOD_M15:PERIOD_M5)) && t1 < 17) { t1 ++;  Sleep(100); }
      err = GetLastError();   if (tst) { if (! chk_chartm5(3)) Alert("*** ERROR Chart_M5 (11) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***");
         Sleep(50);      ChartSetInteger(0, CHART_SCALE, 0, Period() > PERIOD_M15? 5: 4);             tmfr = Period()==PERIOD_M5? PERIOD_M1: PERIOD_M5;
         while(! ChartSetSymbolPeriod(Chart_M5, NULL, ENUM_TIMEFRAMES(tmfr_)) && t2 < 17) { t2 ++;    Sleep(100); }
         Sleep(50);           ChartSetInteger(Chart_M5, CHART_SCALE, 0, Period() == PERIOD_M5? 5: 4);    int err2 = GetLastError();
         if (Period() == PERIOD_M5) { tim_Chart_M5b = TimeCurrent();      GlobalVariableSet(t2_Chart_str, tim_Chart_M5b);
            t5a_Bull_b = bull_;                 t5b_Bull_b = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0);
            GlobalVariableSet(t3_Bull_str, t5a_Bull_b);     GlobalVariableSet(t4_Bull_str, t5b_Bull_b);
            GlobalVariableSet(tmfr2_str, tmfr_b);           GlobalVariableSet(tmfr0_str, tmfr); }
/*         else { tim_Chart_M5 = TimeCurrent();       GlobalVariableSet("t_Chart_M5", tim_Chart_M5);
            t5a_Bullish = bull_;                t5b_Bullish = FileIsExist("ATS-Ind_On-Off\\ATS-Ind5_Buy.txt", 0);
            GlobalVariableSet(t1_Bull_str, t5a_Bullish);    GlobalVariableSet(t2_Bull_str, t5b_Bullish);
            GlobalVariableSet(tmfr1_str, tmfr_);            GlobalVariableSet(tmfr0_str, tmfr); }*/ }
      if (tst) { temp = "** Passage en " + (Period()==PERIOD_M5? "M1": "M5") + " à " + TimeToStr(TimeCurrent(),TIME_MINUTES) + " ! (Period()=" + IntegerToString(Period()) +
            ",t1=" + IntegerToString(t1)+", t2=" + IntegerToString(t2) + (t2==17 ? ", err2=" + IntegerToString(err2) : "") + ") **";
         Print(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp); }
      else { temp = "*** Erreur - Passage en " + (Period()==PERIOD_M5?"M1":"M5") + " à " + TimeToStr(TimeCurrent(),TIME_MINUTES) + " ! (Period()=" + IntegerToString(Period()) +
            ", t1=" + IntegerToString(t1) + ", err1=" + IntegerToString(err) + ") ***";
         Alert(temp);         copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);         Sleep(100); } } } }

int f_Params(int mode) { int new_set=5;   // <- changer à chaque élément nouveau
  if (mode) {
   GlobalVariableSet("EURUSD_Comm", 13);         GlobalVariableSet("EURUSD_Sprd", 20);          GlobalVariableSet("EURUSD_Mag_N", 101);
/*   GlobalVariableSet("USDZAR_Comm", 706);        GlobalVariableSet("USDZAR_Sprd", 1600);
   GlobalVariableSet("EURZAR_Comm", 706);        GlobalVariableSet("EURZAR_Sprd", 1600);
   GlobalVariableSet("USDMXN_Comm", 606);        GlobalVariableSet("USDMXN_Sprd", 1500); */
   GlobalVariableSet("CADJPY_Comm", 13);         GlobalVariableSet("CADJPY_Sprd", 20);          GlobalVariableSet("CADJPY_Mag_N", 102);
   GlobalVariableSet("EURGBP_Comm", 13);         GlobalVariableSet("EURGBP_Sprd", 20);          GlobalVariableSet("EURGBP_Mag_N", 103);
   GlobalVariableSet("EURJPY_Comm", 13);         GlobalVariableSet("EURJPY_Sprd", 20);          GlobalVariableSet("EURJPY_Mag_N", 104);
   GlobalVariableSet("GBPJPY_Comm", 13);         GlobalVariableSet("GBPJPY_Sprd", 20);          GlobalVariableSet("GBPJPY_Mag_N", 105);
   GlobalVariableSet("USDTRY_Comm", 13);         GlobalVariableSet("USDTRY_Sprd", 20);          GlobalVariableSet("USDTRY_Mag_N", 106);

   GlobalVariableSet("BTCUSD_Comm", 3506);       GlobalVariableSet("BTCUSD_Sprd", 5000);        GlobalVariableSet("BTCUSD_Mag_N", 201);
/*   GlobalVariableSet("ETHUSD_Comm", 506);        GlobalVariableSet("ETHUSD_Sprd", 715);
   GlobalVariableSet("LTCUSD_Comm", 66););       GlobalVariableSet("LTCUSD_Sprd", 85);
   GlobalVariableSet("XRPUSD_Comm", 56);         GlobalVariableSet("XRPUSD_Sprd", 50); */

//   GlobalVariableSet("USTECH_Comm", 136);      GlobalVariableSet("USTECH_Sprd", 200);
   GlobalVariableSet("CHINAA_Comm", 13500);      GlobalVariableSet("CHINAA_Sprd", 42000);       GlobalVariableSet("CHINAA_Mag_N", 501);
   GlobalVariableSet("HKG50_Comm", 22000);       GlobalVariableSet("HKG50_Sprd", 65000);        GlobalVariableSet("HKG50_Mag_N", 502);
   GlobalVariableSet("SPX500_Comm", 55);         GlobalVariableSet("SPX500_Sprd", 170);         GlobalVariableSet("SPX500_Mag_N", 503);
   GlobalVariableSet("AUS200_Comm", 485);        GlobalVariableSet("AUS200_Sprd", 1500);        GlobalVariableSet("AUS200_Mag_N", 504);
   GlobalVariableSet("UK100_Comm", 105);         GlobalVariableSet("UK100_Sprd", 320);          GlobalVariableSet("UK100_Mag_N", 505);
   GlobalVariableSet("US30_Comm", 170);          GlobalVariableSet("US30_Sprd", 520);           GlobalVariableSet("US30_Mag_N", 506);
   GlobalVariableSet("GER30_Comm", 170);         GlobalVariableSet("GER30_Sprd", 520);          GlobalVariableSet("GER30_Mag_N", 507);
   GlobalVariableSet("JPN225_Comm", 1105);       GlobalVariableSet("JPN225_Sprd", 3320);        GlobalVariableSet("JPN225_Mag_N", 508);
   GlobalVariableSet("NAS100_Comm", 300);        GlobalVariableSet("NAS100_Sprd", 930);         GlobalVariableSet("NAS100_Mag_N", 509);
   GlobalVariableSet("FRA40_Comm", 130);         GlobalVariableSet("FRA40_Sprd", 380);          GlobalVariableSet("FRA40_Mag_N", 510);
   GlobalVariableSet("ESTX50_Comm", 160);        GlobalVariableSet("ESTX50_Sprd", 500);         GlobalVariableSet("ESTX50_Mag_N", 511);
   GlobalVariableSet("ITA40_Comm", 120);         GlobalVariableSet("ITA40_Sprd", 380);          GlobalVariableSet("ITA40_Mag_N", 512);
   GlobalVariableSet("SUI20_Comm", 45);         GlobalVariableSet("SUI20_Sprd", 150);           GlobalVariableSet("SUI20_Mag_N", 513);

   GlobalVariableSet("XAUUSD_Comm", 13);         GlobalVariableSet("XAUUSD_Sprd", 20);          GlobalVariableSet("XAUUSD_Mag_N", 301);
   GlobalVariableSet("BRENT_Comm", 56);          GlobalVariableSet("BRENT_Sprd", 100);          GlobalVariableSet("BRENT_Mag_N", 303);

   GlobalVariableSet("EURUSD_H1", 6);    GlobalVariableSet("EURUSD_H2", 8);    GlobalVariableSet("EURUSD_H3", 23);    GlobalVariableSet("EURUSD_Diff", 0);
/*   GlobalVariableSet("USDZAR_H1", 6);    GlobalVariableSet("USDZAR_H2", 8);    GlobalVariableSet("USDZAR_H3", 23);    GlobalVariableSet("USDZAR_Diff", 0);
   GlobalVariableSet("EURZAR_H1", 6);    GlobalVariableSet("EURZAR_H2", 8);    GlobalVariableSet("EURZAR_H3", 23);    GlobalVariableSet("EURZAR_Diff", 0);
   GlobalVariableSet("USDMXN_H1", 6);    GlobalVariableSet("USDMXN_H2", 8);    GlobalVariableSet("USDMXN_H3", 23);    GlobalVariableSet("USDMXN_Diff", 0); */
   GlobalVariableSet("CADJPY_H1", 6);    GlobalVariableSet("CADJPY_H2", 8);    GlobalVariableSet("CADJPY_H3", 23);    GlobalVariableSet("CADJPY_Diff", 0);
   GlobalVariableSet("EURGBP_H1", 6);    GlobalVariableSet("EURGBP_H2", 8);    GlobalVariableSet("EURGBP_H3", 23);    GlobalVariableSet("EURGBP_Diff", 0);
   GlobalVariableSet("EURJPY_H1", 6);    GlobalVariableSet("EURJPY_H2", 8);    GlobalVariableSet("EURJPY_H3", 23);    GlobalVariableSet("EURJPY_Diff", 0);
   GlobalVariableSet("GBPJPY_H1", 6);    GlobalVariableSet("GBPJPY_H2", 8);    GlobalVariableSet("GBPJPY_H3", 23);    GlobalVariableSet("GBPJPY_Diff", 0);
   GlobalVariableSet("USDTRY_H1", 6);    GlobalVariableSet("USDTRY_H2", 8);    GlobalVariableSet("USDTRY_H3", 23);    GlobalVariableSet("USDTRY_Diff", 0);

   GlobalVariableSet("BTCUSD_H1", 1);    GlobalVariableSet("BTCUSD_H2", 1);    GlobalVariableSet("BTCUSD_H3", 0);     GlobalVariableSet("BTCUSD_Diff", 0);
/*   GlobalVariableSet("ETHUSD_H1", 1);    GlobalVariableSet("ETHUSD_H2", 1);    GlobalVariableSet("ETHUSD_H3", 0);     GlobalVariableSet("ETHUSD_Diff", 0);
   GlobalVariableSet("LTCUSD_H1", 1);    GlobalVariableSet("LTCUSD_H2", 1);    GlobalVariableSet("LTCUSD_H3", 0);     GlobalVariableSet("LTCUSD_Diff", 0);
   GlobalVariableSet("XRPUSD_H1", 1);    GlobalVariableSet("XRPUSD_H2", 1);    GlobalVariableSet("XRPUSD_H3", 0);     GlobalVariableSet("XRPUSD_Diff", 0); */

// fin de journée : 22 h 45 - reprise lundi matin : 04 h 00 - reprise matin semaine : 03 h 45 
   GlobalVariableSet("CHINAA_H1", 22);   GlobalVariableSet("CHINAA_H2", 4);   GlobalVariableSet("CHINAA_H3", 14);    GlobalVariableSet("CHINAA_Diff", 0);
// fin de journée : 21 h 00 - reprise lundi matin : 04 h 15 - reprise matin semaine : 03 h 45 
   GlobalVariableSet("HKG50_H1", 20);    GlobalVariableSet("HKG50_H2", 4);    GlobalVariableSet("HKG50_H3", 14);     GlobalVariableSet("HKG50_Diff", 0);
   GlobalVariableSet("SPX500_H1", 3);    GlobalVariableSet("SPX500_H2", 6);   GlobalVariableSet("SPX500_H3", 23);    GlobalVariableSet("SPX500_Diff", 0);
   GlobalVariableSet("FRA40_H1", 8);     GlobalVariableSet("FRA40_H2", 8);    GlobalVariableSet("FRA40_H3", 20);     GlobalVariableSet("FRA40_Diff", 0);
// fin de journée : 23 h 00 - reprise lundi matin : 02 h 50 - reprise matin semaine : 02 h 50 
   GlobalVariableSet("AUS200_H1", 22);   GlobalVariableSet("AUS200_H2", 4);   GlobalVariableSet("AUS200_H3", 19);    GlobalVariableSet("AUS200_Diff", 0);
   GlobalVariableSet("UK100_H1", 6);     GlobalVariableSet("UK100_H2", 8);    GlobalVariableSet("UK100_H3", 23);     GlobalVariableSet("UK100_Diff", 0);
   GlobalVariableSet("US30_H1", 3);      GlobalVariableSet("US30_H2", 6);     GlobalVariableSet("US30_H3", 23);      GlobalVariableSet("US30_Diff", 0);
   GlobalVariableSet("GER30_H1", 8);     GlobalVariableSet("GER30_H2", 8);    GlobalVariableSet("GER30_H3", 20);     GlobalVariableSet("GER30_Diff", 0);
// fin de journée : 00 h 00 - reprise lundi matin : 01 h 50 - reprise matin semaine : 01 h 50 
   GlobalVariableSet("JPN225_H1", 23);   GlobalVariableSet("JPN225_H2", 1);   GlobalVariableSet("JPN225_H3", 19);    GlobalVariableSet("JPN225_Diff", 0);
   GlobalVariableSet("NAS100_H1", 3);    GlobalVariableSet("NAS100_H2", 6);   GlobalVariableSet("NAS100_H3", 23);    GlobalVariableSet("NAS100_Diff", 0);
   GlobalVariableSet("ESTX50_H1", 6);    GlobalVariableSet("ESTX50_H2", 8);   GlobalVariableSet("ESTX50_H3", 23);    GlobalVariableSet("ESTX50_Diff", 0);
   GlobalVariableSet("ITA40_H1", 8);     GlobalVariableSet("ITA40_H2", 8);    GlobalVariableSet("ITA40_H3", 20);     GlobalVariableSet("ITA40_Diff", 0);
   GlobalVariableSet("SUI20_H1", 8);     GlobalVariableSet("SUI20_H2", 8);    GlobalVariableSet("SUI20_H3", 20);     GlobalVariableSet("SUI20_Diff", 0);

   GlobalVariableSet("XAUUSD_H1", 1);    GlobalVariableSet("XAUUSD_H2", 8);   GlobalVariableSet("XAUUSD_H3", 23);     GlobalVariableSet("XAUUSD_Diff", 40);
   GlobalVariableSet("BRENT_H1", 6);     GlobalVariableSet("BRENT_H2", 8);    GlobalVariableSet("BRENT_H3", 23);     GlobalVariableSet("BRENT_Diff", 40);

   GlobalVariableSet("All_SL", 25); }    // / 1000

  comm = GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_Comm");
  sprd = GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_Sprd");
  H1 =   GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_H1");
  H2 =   GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_H2");    HOp = H2;
  H3 =   GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_H3");    H3_ = H3;
  diff = GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_Diff");
  Mg_N = GlobalVariableGet(StringSubstr(Symbol(), 0, 6) + "_Mag_N");
  SL =   GlobalVariableGet("All_SL") / 1000.0 * (Ask > 1000 ? round((Bid+Ask) / 2000.0) * 1000 :
      Ask > 100? round((Bid+Ask)/200.0) * 100.0: Ask > 10? round((Bid+Ask)/20.0) * 10.0: Ask > 1? round((Bid+Ask) / 2.0): 1.0);

  Alert("** f_Params("+IntegerToString(mode)+") OK-"+IntegerToString(new_set)+" : "+Symbol()+" / "+IntegerToString(Period())+" - comm "+IntegerToString(comm)+" - sprd "+
   IntegerToString(sprd)+" - H1 "+IntegerToString(H1)+" - H2 "+IntegerToString(H2)+" - H3 "+IntegerToString(H3)+" - diff "+IntegerToString(diff)+" - SL "+DoubleToStr(SL, Digits())+" **");
  GlobalVariableSet(p_Ver_str, new_set);
  return(mode ? 1 : new_set); }

void Close_All_Trades() { string temp;
  for (int i = OrdersTotal()-1; i >= 0; i --) {
    if (OrderSelect(i, SELECT_BY_POS)) {
       int type = OrderType();      bool result = false;
       switch(type) {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
                         break;
          //Close pending orders
            case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );     break;
            case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );     break;
            case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );     break;
            case OP_SELLSTOP  : result = OrderDelete( OrderTicket() ); }
       if (result == false) Sleep(2000); } } //*/

  temp = "***** Account STOP LOSS Reached. All Trades Have Been Closed. ("+DoubleToStr(AccountBalance(),2)+" - "+Hour()+" - "+DoubleToStr(AccBalance_day,2)+") *****";
  Alert(temp);          copy_file_(3, TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES) +" "+Symbol()+","+stmfr+": " + temp);
  t_ngt0 = true;        GlobalVariableSet("t_ngt_3", 1.0);        Sleep(100);          ExpertRemove(); }

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

/* if (pass1) for (i = 1; i < Bars; i ++) {
         ha1Close = (iOpen(NULL,0,Bars-i) + iClose(NULL,0,Bars-i) + iHigh(NULL,0,Bars-i) + iLow(NULL,0,Bars-i)) / 4;
         ha1Open = ((i==1 ? iOpen(NULL, 0, Bars-1) : haOpen) + ha1Close) / 2;
         haOpen = (ha1Open + ha1Close) / 2;
         ha1Open = (iOpen(NULL, 0, Bars-i) + iClose(NULL, 0, Bars-i)) / 2;
         if (i > Bars - 17) { DrawArrow_HA(ha1Open, Bars-i-1, 4, 1);    DrawArrow_HA(ha1Close, Bars-i-1, 4, 0); } }
  else { ha1Close = (iOpen(NULL,0,1) + iClose(NULL,0,1) + iHigh(NULL,0,1) + iLow(NULL,0,1)) / 4;
         ha1Open = (haOpen + ha1Close) / 2;        haOpen = (ha1Open + ha1Close) / 2; }
//         ha1Open = (iOpen(NULL, 0, 1) + iClose(NULL, 0, 1)) / 2; * /
//      DrawArrow_HA(ha1Open, 0, 4, 0);           DrawArrow_HA(ha1Close, 0, 4, 0);

-------------------------------------------

if (Symbol() == "HKG50" && (Hour() >= 6 || local.hour >= 5) && (Hour() < 8 || (Hour() == 8 && Minute() <= 5))) 
         Print("** -> TEST-0 (6-8) DrawArrow_OS n ",bull_," - ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," / ",
         (!(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8)) &&
         (Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",
         !(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8))," ",
         ((Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",(Period() > PERIOD_M15 || DayOfWeek() == 5)," ",OS5_tick," ",Hour()," **");
. . .
if (Symbol() == "HKG50" && (Hour() >= 6 || local.hour >= 5) && (Hour() < 8 || (Hour() == 8 && Minute() <= 5))) 
         Print("** -> TEST-4 (6-8) DrawArrow_OS n ",bull_," ",bull," ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," / ",
         (!(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8)) &&
         (Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",
         !(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8))," ",
         ((Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",(Period() > PERIOD_M15 || DayOfWeek() == 5)," ",OS5_tick," ",Hour()," **");

   MqlDateTime local;      TimeLocal(local);       string str="-"+StringSubstr(EnumToString(magic_nb), 0, 3);
   if (Symbol() == "HKG50") { if (local.hour == 5 && (! local.min || ChartPeriod(Chart_M5) != PERIOD_M5)) { int t = 0;
         if (! chk_chartm5(5)) Alert("*** ERROR Chart_M5 (chk) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***");
         if (ChartPeriod(Chart_M5) != PERIOD_M5) { while(! ChartSetSymbolPeriod(Chart_M5, NULL, PERIOD_M5) && t < 17) { t ++;       Sleep(100); }
            Alert("** PASSAGE EN M5 pour Chart_M5 ! ("+IntegerToString(ChartPeriod(Chart_M5))+", t = "+IntegerToString(t)+", err. : "+IntegerToString(GetLastError())+") **");
            ChartSetInteger(Chart_M5, CHART_SCALE, 0, 4); } }
      if (Symbol() == "HKG50" && local.hour >= 5 && (local.hour < 7 || local.min < 15) && ((FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Buy.txt", 0) && ! bull_) ||
         (FileIsExist("ATS-Ind_On-Off\\ATS-Ind5"+str+"_Sell.txt", 0) && bull_))) DrawArrow_OS(12, LinePrice, BarNum, 0, ! bull_, 0);
      if (local.hour == 7 && (! local.min || ChartPeriod(Chart_M5) != PERIOD_H1)) { t = 0;
         if (! chk_chartm5(5)) Alert("*** ERROR Chart_M5 (chk) "+IntegerToString(ChartPeriod(Chart_M5))+" - "+IntegerToString(Chart_M5)+" ***");
         if (ChartPeriod(Chart_M5) != PERIOD_H1) { while(! ChartSetSymbolPeriod(Chart_M5, NULL, PERIOD_H1) && t < 17) { t ++;       Sleep(100); }
            Alert("** REPASSAGE EN H1 pour Chart_M5 ! ("+IntegerToString(ChartPeriod(Chart_M5))+", t = "+IntegerToString(t)+", err. : "+IntegerToString(GetLastError())+") **");
            ChartSetInteger(Chart_M5, CHART_SCALE, 0, 5); } } }
if (Symbol() == "HKG50" && (Hour() >= 5 || local.hour >= 4) && (Hour() < 8 || (Hour() == 8 && Minute() <= 5))) 
         Print("** -> TEST-5 (6-8) DrawArrow_OS n ",bull_," § ",ticket," ",t_night," ",TimeToStr(Time[0],TIME_MINUTES)," / ",
         (!(((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) || (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8)) &&
         (Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",! (((Hour()>1 || (Hour() && Minute()>2)) && (Hour()<23 || Minute()<59)) ||
         (Bid>0 && Ask>Bid && (Ask-Bid)*Point < 8))," ",((Period() > PERIOD_M15 || DayOfWeek() == 5) && ! time_allow)," ",(Period() > PERIOD_M15 ||
         DayOfWeek() == 5)," ",OS5_tick," ",Hour()," ",local.hour," **"); */
