for loop issue

 

Hi everyone.

in this simple loop, several support lines are drawn.. the problem is: multiple lines are at the same value.

how to make sure that the lines are at different values and they are not repeating the same ones?

see example code below.

thanks and good day:)


void HLcalculation()
  {
   for(int A=1; A<=30; A++)
   {
    if(Close[A+1]>=Open[A+1])
    if(Close[A]<=Open[A])
    if(Close[A]<=Close[A+1])
    {  
     H1_name="H1_name"+(string(A));
     
     H1_S1_price=Close[A+1];
     H1_S1_time=Time[A+1];
     
     ObjectDelete(NULL,H1_name);
     ObjectCreate(NULL,H1_name,OBJ_TREND,0,H1_S1_time,H1_S1_price,Time[0],H1_S1_price);
     ObjectSet(H1_name,OBJPROP_COLOR,clrLightBlue);
     ObjectSet(H1_name,OBJPROP_WIDTH,1);
     ObjectSet(H1_name,OBJPROP_BACK,1);
     ObjectSet(H1_name,OBJPROP_RAY,1);
    }
   }
   
  }
//+------------------------------------------------------------------+
 
H1_name="H1_name"+(string(A));

Do not use series index in object names, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

Use time (as int) or a non-series index:

#define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
 
William Roeder #:

Do not use series index in object names, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

Use time (as int) or a non-series index:

thanks a lot :)

Reason: