#property indicator_chart_window

bool show=false,Op_OHL=true,Op_Show=false,Op_DDw=false,Op_HiLo=false, Op_Liq2=false,Op_Liq3=false,Op_Liq4=false,
   script=false, rate1c=false,rate2c=true,rate3c=false,rate4c=false, ha_Buff=true, ha_Opt=false, haBull;
string bar_Dirs[], bar_Dir, sym_target, LabelNameEnd, tmp3;
int frameX=20,frameY=35,per_target,Op_Liqu;        double bar_OPrs[];
double ha1Open, ha1Close, haOpen, haClose, haHigh, haLow;

#include <Liste dObjets (n).mqh>   // pour une utilisation manuelle
//#include <Liste dObjets (all).mqh>

void OnInit() { //while(!Bars || !Period()) Sleep(100);
  EventSetMillisecondTimer(100);
  IndicatorSetString(INDICATOR_SHORTNAME,"Ind Liste dObjets (all)");
//  ChartSetInteger(0,CHART_SHOW_GRID,true);

//  if (GlobalVariableCheck("H_A_Opt")) ha_Opt = GlobalVariableGet("H_A_Opt");
//  if (GlobalVariableCheck("H_A_Buff")) ha_Buff = GlobalVariableGet("H_A_Buff");

  ObjectsDelete(1);
  return; }

int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],
                const double &open[],const double &high[],const double &low[],const double &close[],
                const long &tick_volume[],const long &volume[],const int &spread[]) {

  int comm=13,ind_total=ChartIndicatorsTotal(0,0);
  string name, m_log_file_name, temp, tmp2;
  string opt_num3t[] = {"RateOC*","Op_Liq*","op_HAp*","H_A_Buff","Op_Case*","Op_Case*;op_case01","Op_Case*;op_case11","Op_Case*;op_case21","Op_Case*;op_case22",
      "Op_Case*;op_case23","Op_Case*;op_case25","Op_Case*;op_case26","Op_Case*;op_case12","Op_Case*;op_case21","Op_Case*;op_case13","Op_Case*;op_case21",
      "Op_Case*;op_case02","Op_Case*;op_case11","Op_Case*;op_case21","Op_Case*;op_case03","Op_Case*;op_case11","Op_Case*;op_case21","H_A_Opt"};
  temp = NULL;    for (int ind=0; ind < ind_total && temp==NULL; ind ++)
     if (StringFind((name=ChartIndicatorName(0,0,ind)), "ATS") > 0)
         temp = StringSubstr(name, StringFind(name, "(")+1, StringFind(name, ")") - StringFind(name, "(")-1);
  if (temp != NULL) Sleep(StringToInteger(temp));

  if (GlobalVariableCheck("ShowAll")) show = GlobalVariableGet("ShowAll");
  if (GlobalVariableCheck("Op_Show")) Op_Show = GlobalVariableGet("Op_Show"); // modifiable par "Liste dObjets (6).mq4"
  if (GlobalVariableCheck("OScript")) script = GlobalVariableGet("OScript");
  if (GlobalVariableCheck("RateOC1")) rate1c = GlobalVariableGet("RateOC1");
  if (GlobalVariableCheck("RateOC2")) rate2c = GlobalVariableGet("RateOC2");
  if (GlobalVariableCheck("RateOC3")) rate3c = GlobalVariableGet("RateOC3");
  if (GlobalVariableCheck("RateOC4")) rate4c = GlobalVariableGet("RateOC4");
  if (GlobalVariableCheck("H_A_Opt")) ha_Opt = GlobalVariableGet("H_A_Opt");
  if (GlobalVariableCheck("H_A_Buff")) ha_Buff = GlobalVariableGet("H_A_Buff");
  if (GlobalVariableCheck("Op_Liqu")) Op_Liqu = GlobalVariableGet("Op_Liqu");
  if (GlobalVariableCheck("Op_Liq2")) Op_Liq2 = GlobalVariableGet("Op_Liq2");
//  if (GlobalVariableCheck("Op_Err")) Op_Err = GlobalVariableGet("Op_Err");
  if (GlobalVariableCheck("Op_Liq3")) Op_Liq3 = GlobalVariableGet("Op_Liq3");
  if (GlobalVariableCheck("Op_Liq4")) Op_Liq4 = GlobalVariableGet("Op_Liq4");

  if (script && show) { Alert("Les options ShowAll et OScript ne peuvent pas être 'true' en même temps !");
      copy_file (0, "** -> Les options ShowAll et OScript ne peuvent pas être 'true' en même temps ! **");
      return(0); }

  double LastSize, CurrSize;
  m_log_file_name="EA-write-file_Liste-Objets.txt";
  int handle = FileOpen (m_log_file_name,FILE_TXT);
  LastSize = FileSize(handle);   FileClose(handle);
  CurrSize = LastSize;

  while (CurrSize == LastSize) {
  int islp=0;  while(!Bars || !Period() || ObjectsTotal()<7) {
      islp += 100;      Sleep(islp);
      if (islp > 1200 && !(islp % 1000)) ChartRedraw(0);
      if (islp > 2000) { int tmfr=Period();
         copy_file (0, (script?"":TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES))+" * -> "+Symbol()+", "+(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")+", total : N/A - $ N/A, Highest :"+
            " N/A - $ N/A, Drawdown : N/A - $ N/A  (-.- % -.- %) - N/A pips/d., N/A pips/m. (NbDDw: N/A - MaxBars: N/A) *");         break; } }

  Sleep(500);     if (islp < 2000) {      // sript complet "Liste dObjets (5b).mq4" jusqu'au bout du OnInit()
  ObjectsDelete(0);            if (show) ChartSetInteger(0,CHART_SHOW_GRID,true);        if (! ha_Buff) HA_Buffers(1);

  int obj_total=ObjectsTotal(), i, j, k=0, k_, p=0, exp_1=0, exp_2=0, MrktVal, HighVal=0, DDwnVal=0, HiLoVal;
  int obj_bar_cl, obj_bar_cl2, obj_bar_cl3, prv_pos=0, total=0, total0, hightotal=0, drawdown=0, obj_bar_liq[];   //, type
  int obj_bars[], obj_pos[], obj_pos0[], obj_reOps[][2], reClo_brs[], first_bar, nb_pos;   //, reOpn_brs[]       // v [2]
  string obj_liqTypes[], obj_liqTyp_1="", obj_liqTyp_2="";  double drawdwnp, obj_Prices[], reOpn_prs[], obj_prClots[], reClo_prs[], obj_Levels[], params[5];
  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(reClo_brs, obj_total);      ArrayResize(obj_Neutrals, obj_total);  ArrayResize(obj_liqTypes, obj_total);
  ArrayResize(bar_Dirs, Bars);            ArrayResize(bar_OPrs, Bars);           ArrayResize(obj_bar_liq, Bars);
  string nam_B, nam_S, nam_B2, nam_S2, nam_B3, nam_S3;                           bool bull, pos_prem=true, tst;
  if (ha_Buff) { ArrayResize(ExtOpenBuffer, Bars);       ArrayResize(ExtCloseBuffer, Bars);     HA_Buffers(1); }
//  params[1] = true;              params[2] = false;     // High_Low_sup0     Expansion_Level

  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;
     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;
            if (ObjectType((nam_B=StringSubstr(name, 0, (StringSubstr(name,5,1)==2?13:8))+"liquid_buy"+StringSubstr(name, 
               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) {     if (Op_HiLo) 
               Print("*** -> 2 liquid lines | ",pos," - ",(Bars-i)," - ",obj_Prices[pos]," - ",StringToUpper(obj_liqTypes[pos])," - ",
                  StringToUpper(obj_liqTyp_1)," - 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": "Error-2": "Error-2";
                  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; } 
                     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]) + comm;      nb_pos ++; } } }
            if (Op_Liq2) { temp = ObjectName(pos-1);  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);
               temp = ObjectName(pos-2);  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 (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]))) { */
            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 &&
               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)) > 100 * 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)) < 100*Point &&
               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)) > 100 * 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]))) {
                  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; }
                  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]) + 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)*
            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;   p = 0;   total = total0;      // prv_pos = 0;            // <- remettre si | est remis

//  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);
  double vScale=(WindowPriceMax()-WindowPriceMin())/(1.154-1.061);   int pX=80, pY=45, pos_bar_cl;    bool tst1, tst2;
  for (pos=0; pos<obj_total; pos++) if (obj_liqTypes[pos] == "Error") { exp_1 ++;      p ++;
         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 ++;        p ++;
         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;     if (! first_bar) first_bar = Bars-obj_bars[pos];
      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 (Period()<=5 && iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) Print("*** Error High - Low ! "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");
         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);
            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 *
         if (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 (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 (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);*/     nb_pos ++; }
      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 (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 (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 prochaines 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 (show && Op_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 (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
            if (Period()<=5 && iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) Print("*** Error High - Low ! "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");
            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);
               t_clo = f_mqh_code_EA(1,pos,prv_pos,i,obj_liqTypes[pos],0,reOpn_prs[k],0,params,HighVal,MrktVal,HiLoVal,DDwnVal); } } // boucle des reOps Label_Arrow_Test(Type= 1,  // * MQH *
          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 (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;
               if (Period()<=5 && iHigh(NULL,0,Bars-i)==iLow(NULL,0,Bars-i)) Print("*** Error High - Low ! "+TimeToStr(iTime(NULL,0,Bars-i),TIME_DATE|TIME_MINUTES)+" ***");
               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);
                  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 (HighVal < MrktVal) HighVal = MrktVal;    if (DDwnVal > MrktVal - HighVal) DDwnVal = MrktVal - HighVal; } }    HighVal = 0;    DDwnVal = 0;
            if (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 (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 ---------------------------------------------------------------------------------------------------------------- */
   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;    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)))," ***"); */
      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);
         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 *
      if (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, 0, 1);         DrawArrow_pf(obj_prClots[pos], Bars-i, 5, 0, 1); }       // 1er niveau de sortie en bleu
      if (t_clo && i == Bars && Seconds() > 58) Print("** -> DrawArrow_OS *1 ",bull," ",t_clo," ",Bid," ",Ask," ",i," ",j," ",Bars," ",(Bars-i)," ",
               TimeToStr(Time[Bars-i],TIME_MINUTES)," | ",pos," ",obj_prClots[pos]," ",vScale," **");
      if (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; }
   total += (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);
//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 (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]]) {
         total += (obj_liqTypes[prv_pos] == "Buy" ? -1 : (obj_liqTypes[prv_pos] == "Sell" ? 1 : 0)) * (obj_Prices[pos] - obj_prClots[pos]) / Point - comm;
         if (obj_bars[obj_pos[p-1]] >= Bars-1 && Seconds() > 58)
            Print("** -> DrawArrow_OS *2 ",bull," ",Bid," ",Ask," ",p," ",obj_pos[p-1]," ",obj_bars[obj_pos[p-1]]," | ",pos," ",obj_Prices[pos]," ",vScale," **"); }
      if (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; }
   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)*
      if (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);
         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);
         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); }    // boucle des reOps Label_Arrow_Test(Type= 1,     // * MQH *
       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 (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 && Seconds() > 58) Print("** -> 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," **");
         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(1, iOpen(NULL,0,Bars-i), iClose(NULL,0,Bars-i), iHigh(NULL,0,Bars-i), iLow(NULL,0,Bars-i), Bars-i, NULL);
            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 *
            if (HighVal < MrktVal) HighVal = MrktVal;    if (DDwnVal > MrktVal - HighVal) DDwnVal = MrktVal - HighVal; }      HighVal = 0;    DDwnVal = 0;
         if (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 && Seconds() > 58) Print("** -> 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," **");
         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;       if (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 (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, " *");
/* -------------------------------------------------------------------------------------------------------------------------------- */

//  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 (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," (i) total ("+obj_liqTypes[prv_pos]+"): "+DoubleToStr(total,0)+" (end)",0);
     tmp3 = " (-) total ("+obj_liqTypes[prv_pos]+"): "+DoubleToStr(total,0)+" (end)"; }
  if (exp_1 || exp_2) { CreateLabel_end(0,0,0,NULL,"* Heiken Ashi: "+(ha_Opt? "YES": "NO")+" * ",2);
      CreateLabel_end(0,0,exp_1+exp_2,NULL,"* exp_1: "+IntegerToString(exp_1)+" - exp_2: "+IntegerToString(exp_2)+" * ",1); }
  else   CreateLabel_end(0,0,0,NULL,"* Heiken Ashi: "+(ha_Opt? "YES": "NO")+" * ",3);
  if (obj_bars[prv_pos] >= Bars-1 && Seconds() > 58) Print("** -> 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," **");
  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, " *");

  int tmpMktv,tmpHigh=0,tmpHgh2=0,tmpDDwn=0,tmpDDw2=0,tmpHiLo,NbDDw=0;    double tmpPr;
  for (i = 0; i < Bars; i ++) {        //bool tst;
      tmpHiLo = ((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;
      if (bar_OPrs[Bars-i]) tmpPr = bar_OPrs[Bars-i];      //if (bar_OPts[Bars-i]) tmpPt = bar_OPts[Bars-i];
      if ((tst=(bar_Dirs[Bars-i] != NULL && bar_Dirs[Bars-i] != "Close"))) bar_Dir = bar_Dirs[Bars-i];
      tmpMktv = (tmpPr? (bar_Dir=="Buy"? 1: bar_Dir=="Sell"? -1: 0) * ((bar_Dir=="Buy"? tst? iHigh(NULL,0,Bars-i): 
                  iLow(NULL,0,Bars-i): tst? iLow(NULL,0,Bars-i): iHigh(NULL,0,Bars-i)) - tmpPr) / Point: 0);
      if (tmpHigh-tmpMktv > tmpHiLo * 2 && tmpHigh && tmpMktv-tmpHigh < tmpDDwn / 4*3) NbDDw ++;
      if (tmpHigh < tmpMktv) tmpHigh = tmpMktv;    if (tmpDDwn > tmpMktv - tmpHigh) tmpDDwn = tmpMktv - tmpHigh;
      if (tmpHgh2 < tmpHigh) tmpHgh2 = tmpHigh;    if (tmpDDw2 > tmpDDwn) tmpDDw2 = tmpDDwn;
      if (bar_Dirs[Bars-i] != NULL) bar_Dir = bar_Dirs[Bars-i];
      if (bar_Dir == "Close") { tmpHigh = 0;    tmpDDwn = 0; }
  }   }   // fin du script "Liste dObjets (5b).mq4"

  if (show || ! script) { CurrSize += 1;      temp = "N/A"; }
  else { total -= nb_pos * 20;      tmfr = Period();   ind_total = ChartIndicatorsTotal(0,0);      j = -1;
      for (ind = 0; ind < ind_total; ind ++) if (StringFind(ChartIndicatorName(0,0,ind), "Liste") > 0) j ++;
      if (j) show = true;     temp = NULL;   for (ind = 0; ind < ind_total && temp==NULL; ind ++)
         if (StringFind((name=ChartIndicatorName(0,0,ind)), "ATS") > 0) temp = StringSubstr(name, StringFind(name, "(")+1,3);
      temp = temp!=NULL? StringSubstr(name, StringFind(name, "(")+2,1)=="5"? "3500": StringSubstr(name, StringFind(name, "(")+1,1)=="3"? "300": 
         StringSubstr(name, StringFind(name, "(")+1,1)=="5"? "5000": "Error": "N/A";
      copy_file (0, "** -> "+Symbol()+", "+(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")+", Obj.: "+obj_total+", Tot.: "+IntegerToString(total)+" - $"+DoubleToStr(total/100.0,2)+", Hi.: "+
         IntegerToString(hightotal)+" - $"+DoubleToStr(hightotal/100.0,2)+", Drd.: "+IntegerToString(drawdown)+" - $"+DoubleToStr(drawdown/100.0,2)+" ("+(hightotal?
         DoubleToStr((drawdown*1.0/hightotal*1.0)*100.0,1):"-.-")+" % "+(drawdwnp?DoubleToStr(drawdwnp,1):"-.-")+" % "+(tmpHgh2?DoubleToStr((tmpDDw2*1.0/tmpHgh2*1.0)*100.0,1):
         "-.-")+" %) -> "+DoubleToStr((total/10.0/first_bar)*1440/Period(),1)+" pips/d., "+DoubleToStr((total/10.0/first_bar)*21*1440/Period(),1)+" pips/m. (nDdw:"+
         IntegerToString(NbDDw)+"-Bars:"+Bars+"-Mbars:"+temp+") *");                GlobalVariableSet("indall_total", total);
         int opt_num=GlobalVariableGet("Options"), opt_num2=GlobalVariableGet("Options_2");
      if (! FileIsExist("EA-write-file_Liste-Objets.csv"))
         copy_file (1, ";Time;Symbole;Période;Nb. Objets;Total;$;Highest;$;Drawdown;$;% 1;% 2;% 3;pips/d.;pips/m.;NbDDw;Bars;MaxBars;Options");
      tmp2 = (total>0? "*;": ";")+TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)+";"+Symbol()+";"+(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")+";"+obj_total+";"+IntegerToString(total)+";"+
         DoubleToStr(total/100.0,2)+";"+IntegerToString(hightotal)+";"+DoubleToStr(hightotal/100.0,2)+";"+IntegerToString(drawdown)+";"+DoubleToStr(drawdown/100.0,2)+";"+
         (hightotal?DoubleToStr((drawdown*1.0/hightotal*1.0)*100.0,1):"-.-")+";"+(drawdwnp?DoubleToStr(drawdwnp,1):"-.-")+";"+(tmpHgh2?DoubleToStr((tmpDDw2*1.0/tmpHgh2*1.0)*100.0,1):"-.-")+
         ";"+DoubleToStr((total/10.0/first_bar)*1440/Period(),1)+";"+DoubleToStr((total/10.0/first_bar)*21*1440/Period(),1)+";"+IntegerToString(NbDDw)+";"+Bars+";"+temp+";"+
         opt_num3t[opt_num]+(StringFind(opt_num3t[opt_num],";")>0? "": ";_"+IntegerToString(opt_num2));
      StringReplace(tmp2, ".", ",");         copy_file (1, tmp2);

/* -> EURUSD, M1, Objets : 394, Total : 839 - $8.39, Highest : 913 - $9.13, Drawdown : -163 - $-1.63  (-17.9 % -19.9 % -138.4 %) - 1.8 pips/d., 39.4 pips/m. (NbDDw: 639 - Bars: 67516 - MaxBars: N/A) *
      " % "+(tmpHgh2? DoubleToStr((tmpDDw2*1.0/tmpHgh2*1.0)*100.0,1): "-.-")+" %) ; ", DoubleToStr(((total-nb_pos*20)/10.0/first_bar)*1440/Period(),1)," pips/d. ; ",
      DoubleToStr(((total-nb_pos*20)/10.0/first_bar)*21*1440/Period(),1)," pips/m. *"); //*/

      handle = FileOpen (m_log_file_name,FILE_TXT);
      CurrSize = FileSize(handle);   FileClose(handle);
      if (CurrSize == LastSize) { Sleep(100);
         copy_file (0, "* -> "+Symbol()+", "+(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")+", Objets : "+obj_total+", Total : ??? - $ ???, Highest :"+
            " ??? - $ ???, Drawdown : ??? - $ ???  (-.- % -.- %) - ??? pips/d., ??? pips/m. (NbDDw: ??? - MaxBars: ???) *"); } }
  }  // fin de while (CurrSize == LastSize)

/* si uniquement dans le cadre du script "Liste dObjets (all).mq4"+templates -> if (script) */
  if (script) Print ("Obj.: ", obj_total, ", Tot.: ", total, " - $", total/100.0, ", Hi.: ", hightotal, " - $", hightotal/100.0, ", Drd.: ", 
      drawdown, " - $", drawdown/100.0, " (", hightotal? DoubleToStr((drawdown*1.0/hightotal*1.0)*100.0, 1): "-.-", " % ", drawdwnp?DoubleToStr(drawdwnp,1):"-.-", 
//      "$"+DoubleToStr((total/10.0/Bars)*1440/Period(),2)," / day (0.1 lot) *");
      " % "+(tmpHgh2? DoubleToStr((tmpDDw2*1.0/tmpHgh2*1.0)*100.0,1): "-.-")+" %) -> ", DoubleToStr(((total-nb_pos*20)/10.0/first_bar)*1440/Period(),1)," pips/d., ",
      DoubleToStr(((total-nb_pos*20)/10.0/first_bar)*21*1440/Period(),1)," pips/m. *"); //*/

  if (script && temp == "Error") { Print("*** Erreur sur le nom d'indicateur ! ***");
      copy_file (1, "*** Erreur sur le nom d'indicateur ! ***"); }

  if (temp == "N/A" || show || ! script) {
      if (GlobalVariableCheck("frameX")) frameX = GlobalVariableGet("frameX");
      CreateButton(0,0,"<>",0,frameX-18,frameY+1,0);
      CreateButton(0,0,"Show", 0,frameX,frameY,0);
      CreateButton(0,0,"OShow",1,frameX,frameY+15,1);
      CreateButton(0,0,"Script",1,frameX,frameY+30,2);
      CreateButton(0,0,"rate1c",1,frameX,frameY+45,3);
      CreateButton(0,0,"rate2c",1,frameX,frameY+60,4);
      CreateButton(0,0,"rate3c",1,frameX,frameY+75,5);
      CreateButton(0,0,"rate4c",1,frameX,frameY+90,6);
      CreateButton(0,0,"Op_HA", 1,frameX,frameY+105,7);
      CreateButton(0,0,"exp-Err",1,frameX,frameY+120,8);
      CreateButton(0,0,"expSo1",1,frameX,frameY+135,9);
      CreateButton(0,0,"expSo2",1,frameX,frameY+150,10);
/*      CreateButton(0,0,"rate1h",1,frameX,frameY+90,6);
      CreateButton(0,0,"rate2h",1,frameX,frameY+105,7);
      CreateButton(0,0,"rate3h",1,frameX,frameY+120,8);
      CreateButton(0,0,"rate4h",1,frameX,frameY+135,9);*/ }

/* -> uniquement dans le cadre du script "Liste dObjets (all).mq4"+templates
    ou si l'indicateur est relancé plusieurs fois manuellement */
  if (script || show) { Sleep(100);    if (temp != "N/A")   // || show
      if (ChartIndicatorDelete(0,0,"Ind Liste dObjets (all)") && show)
         Alert("\"Ind Liste dObjets (all)\" a été fermé car ShowAll = true !"); }
//  ChartIndicatorDelete(0,0,"Ind Liste dObjets (all)_");     Sleep(1000);
//  IndicatorSetString(INDICATOR_SHORTNAME,"Ind Liste dObjets (all)_");


  return(rates_total); }
//+------------------------------------------------------------------+

void OnDeinit(const int reason) {
  while (ObjectDelete(LabelNameEnd)) {}
  CreateLabel_end(0, 0, 0, 0, tmp3, 0);
  return; }

void copy_file(bool mode, string tmp) { int handle;
   string filename="EA-write-file_Liste-Objets."+(mode? "csv": "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); }

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 (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); }
   bar_Dirs[BarNum] = (Clot? "Close": Bullish? "Buy": "Sell");
   bar_OPrs[BarNum] = (Clot? 0.0: LinePrice);
   bar_Dir = (Clot? "Close": Bullish? "Buy": "Sell");
}
// DrawArrowUp("Arr_up",Low[barre]-50*Point,DeepSkyBlue);
// DrawArrowDn("Arr_dn",High[barre]+150*Point,DeepPink);

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, 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(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?"-Up_":"-Down_")+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);
   bar_Dirs[BarNum] = (Bullish? bar_Dir: "Close");
   bar_OPrs[BarNum] = (Bullish? LinePrice: 0.0);
}

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? 9: 10);
   ObjectSet(LabelName,OBJPROP_COLOR, Color? Color==1 && Op_Show? clrDeepSkyBlue: Color==2 && script? clrAqua: 
      Color==3 && rate1c? clrSkyBlue: Color==4 && rate2c? clrSkyBlue: Color==5 && rate3c? clrSkyBlue: 
      Color==6 && rate4c? clrSkyBlue: Color==7 && ha_Opt? clrDeepSkyBlue: Color==8 && !Op_Liqu? clrDeepSkyBlue: 
      Color==9 && Op_Liqu==1? clrDeepSkyBlue: Color==10 && Op_Liqu==2? clrDeepSkyBlue: 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) {
   string LabelName = PREFIX+"_end_Label_"+IntegerToString(Bullish?241:242)+"-"+IntegerToString(Pos)+"-"+IntegerToString(BarNum)+"-0-0";
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);              if (LabelNameEnd == NULL) LabelNameEnd = LabelName;
   ObjectSet(LabelName,OBJPROP_XDISTANCE,Item? 200*(Item<3?Item:Item-2): 15);
   ObjectSet(LabelName,OBJPROP_YDISTANCE,15);
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_RIGHT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_RIGHT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE,Item? 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);
     if (pos && (StringSubstr(name,0,8) == "EA_Test_" || StringSubstr(name,0,9) == "H-A_Test_")) {
         j ++;   if (ObjectDelete(name)) { i ++;  pos --; } } }
   if (P) Print (pos, " objects, DELETED: ", i, " / ", j, " / ", obj_total);
   return; }
/* - partie finale ---------------------------------------------------------------------------------------------------------------- */

void DrawArrow_pf(double LinePrice,int BarNum,int Code,bool Bullish,bool Clot) {
   string ArrowName = PREFIX+"_pf_Arr"+(Bullish?"-Up_":"-Down_")+IntegerToString(Code?Code:Bullish?241:242)+"-"+IntegerToString(BarNum)+"-"+IntegerToString(Clot);
   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);
   bar_Dirs[BarNum] = (Clot? "Close": Bullish? "Buy": "Sell");
   bar_OPrs[BarNum] = (Clot? 0.0: LinePrice);
   bar_Dir = (Clot? "Close": Bullish? "Buy": "Sell");
}

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 = PREFIX+"_pf_Arr"+(Bullish?"-Up_":"-Down_")+IntegerToString(Code?Code:Bullish?241:242)+"-"+IntegerToString(BarNum);
   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);
   bar_Dirs[BarNum] = (Bullish? bar_Dir: "Close");
   bar_OPrs[BarNum] = (Bullish? LinePrice: 0.0);
}

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