ObjectDelete(0,label_name); can delete all object with the same name pluss index add?

 

i draw OBJ_VLINE by :

int OnCalculate(...)
{
.
.
.
 ObjectCreate(0,"label_name"+IntegerToString(j-1),OBJ_VLINE,0,Time[rates_total-j],CLOSE[rates_total-j]);
 .
.
,
}

and then :

void OnDeinit(const int reason)
  {
   for(int j=0;j<rates_total;j++)
     {  
      if(ObjectFind(0,"label_name"+IntegerToString(j))>=0) ObjectDelete(0,"label_name"+IntegerToString(j));
     }
  }

to delete it,

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

my question is :

if i used below code , Instead of above : is this have problem ?

void OnDeinit(const int reason)
  {
   ObjectDelete(0,label_name);
  }

i check it & there is seems no problem, but Can I be sure this is correct and no error in future with growing the indicator? ( may be i used 2 index , i & j )

thank you.

 
TIMisthebest:

i draw OBJ_VLINE by :

and then :

to delete it,

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

my question is :

if i used below code , Instead of above : is this have problem ?

i check it & there is seems no problem, but Can I be sure this is correct and no error in future with growing the indicator? ( may be i used 2 index , i & j )

thank you.

What is held in the string variable  label_name ?
 
RaptorUK:
What is held in the string variable  label_name ?

for example :

string  label_name="AO_Price_Divergence";

thank to reply.

 

label_name: is just for that type of OBJ_VLINE i use it in my indicator. ( for one case )



 
TIMisthebest:

for example :

string  label_name="AO_Price_Divergence";

thank to reply.

So that is the only Object that will be deleted OnDeinit
 
RaptorUK:
So that is the only Object that will be deleted OnDeinit

yes;

and then :

void OnDeinit(const int reason)
  {
   for(int j=0;j<rates_total;j++)
     {  
      if(ObjectFind(0,"label_name"+IntegerToString(j))>=0) ObjectDelete(0,"label_name"+IntegerToString(j));
     }
  }
can use below  Instead of above ?
void OnDeinit(const int reason)
  {
   ObjectDelete(0,label_name);
  }

i check it & there is seems no problem, but Can I be sure this is correct and no error in future with growing the indicator? ( may be i used 2 index , i & j )

thank you.

 
TIMisthebest:

yes;

and then :

can use below  Instead of above ?

i check it & there is seems no problem, but Can I be sure this is correct and no error in future with growing the indicator? ( may be i used 2 index , i & j )

thank you.

Of course not. Why are you thinking that 1 call to ObjectDelete will do the same that rates_total calls to it ?

What problem are you trying to solve by doing that ?

 
angevoyageur:

Of course not. Why are you thinking that 1 call to ObjectDelete will do the same that rates_total calls to it ?

What problem are you trying to solve by doing that ?

just for simple that . if any object has same equal part in name,  then delete it .( is it possible ? )      

thank you.

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

i used :

.
.
TOTAL_BAR=rates_total;
.
.
//+------------------------------------------------------------------+
//| Function for drawing a trend line in the indicator window        |
//+------------------------------------------------------------------+
void DrawIndicatorTrendLine(int bar,datetime x1,datetime x2,double y1,double y2,color lineColor,int style)         
  {
   int indicatorWindow=ChartWindowFind(0,short_name);  // short_name  indicatorName
   if(indicatorWindow<0) return;
   string label="AO_Indicator_Divergence"+IntegerToString(bar)+TimeToString(x2);
   if(ObjectFind(0,label)==-1)
     {
      ObjectCreate(0,label,OBJ_TREND,indicatorWindow,x1,y1,x2,y2);
      ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
      ObjectSetInteger(0,label,OBJPROP_STYLE,style);
      ObjectSetInteger(0,label,OBJPROP_WIDTH,0);
      ObjectSetInteger(0,label,OBJPROP_RAY,0);
      ObjectSetInteger(0,label,OBJPROP_BACK,false);
     }
   else
     {
      ObjectMove(0,label,0,x1,y1);
      ObjectMove(0,label,1,x2,y2);
     }
  }
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Function for drawing a trend line in a price chart window        |
//+------------------------------------------------------------------+
void DrawPriceTrendLine(int bar,datetime x1,datetime x2,double y1,double y2,color lineColor,int style)
  {
   string label="AO_Price_Divergence"+IntegerToString(bar)+TimeToString(x2);
   if(ObjectFind(0,label)==-1)
     {
      ObjectCreate(0,label,OBJ_TREND,0,x1,y1,x2,y2);
      ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
      ObjectSetInteger(0,label,OBJPROP_STYLE,style);
      ObjectSetInteger(0,label,OBJPROP_WIDTH,0);
      ObjectSetInteger(0,label,OBJPROP_RAY,0);
      ObjectSetInteger(0,label,OBJPROP_BACK,false);
     }
   else
     {
      ObjectMove(0,label,0,x1,y1);
      ObjectMove(0,label,1,x2,y2);
     }
  }
//----------------------------------------------------------------------------------------------------------//

&

void OnDeinit(const int reason)
  {
   Comment("");
   //ObjectsDeleteAll(0,0,OBJ_ARROW);
   //ObjectsDeleteAll(0,-1,OBJ_ARROW);
   //ObjectsDeleteAll(0,0,OBJ_TREND);
   //ObjectsDeleteAll(0,-1,OBJ_TREND);
   //ObjectsDeleteAll(0);
   //ObjectsDeleteAll(0,0,OBJ_VLINE);
   //ObjectsDeleteAll(0,0,OBJ_RECTANGLE);
   
   for(int j=1;j<=TOTAL_BAR;j++)
      {  
       for(int jj=1;jj<TOTAL_BAR;jj++)
          {  
           if(ObjectFind(0,"AO_Indicator_Divergence"+IntegerToString(j)+TimeToString(jj))>=0) 
              ObjectDelete(0,"AO_Indicator_Divergence"+IntegerToString(j)+TimeToString(jj));
           if(ObjectFind(0,"AO_Price_Divergence"+IntegerToString(j)+TimeToString(jj))>=0) 
              ObjectDelete(0,"AO_Price_Divergence"+IntegerToString(j)+TimeToString(jj));    
          }
      }

   ChartRedraw();
   ChartSetInteger(0,CHART_FOREGROUND,foreground);
  }

there is no error or warning but on chart there is problem.

what is wrong ?

thank you.

 
TIMisthebest:

just for simple that . if any object has same equal part in name,  then delete it .( is it possible ? )      


You can implement this by yourself:

1. Call ObjectsTotal to get the number of total objects on the chart.

2. Enumerate the objects and call ObjectName function to get the name of each object.

3. Compare the name of object and call ObjectDelete if its name meets your criteria.

 

How ever, the "equal part in name" should be more specific, otherwise you may delete objects that were created by the terminal or other programs. 

Documentation on MQL5: Object Functions / ObjectName
Documentation on MQL5: Object Functions / ObjectName
  • www.mql5.com
Object Functions / ObjectName - Documentation on MQL5
 
forex2start:

You can implement this by yourself:

1. Call ObjectsTotal to get the number of total objects on the chart.

2. Enumerate the objects and call ObjectName function to get the name of each object.

3. Compare the name of object and call ObjectDelete if its name meets your criteria.

 

How ever, the "equal part in name" should be more specific, otherwise you may delete objects that were created by the terminal or other programs. 

thank you.
 
angevoyageur:

What problem are you trying to solve by doing that ?

i used :

.
.
TOTAL_BAR=rates_total;
.
.
//+------------------------------------------------------------------+
//| Function for drawing a trend line in the indicator window        |
//+------------------------------------------------------------------+
void DrawIndicatorTrendLine(int bar,datetime x1,datetime x2,double y1,double y2,color lineColor,int style)         
  {
   int indicatorWindow=ChartWindowFind(0,short_name);  // short_name  indicatorName
   if(indicatorWindow<0) return;
   string label="AO_Indicator_Divergence"+IntegerToString(bar)+TimeToString(x2);
   if(ObjectFind(0,label)==-1)
     {
      ObjectCreate(0,label,OBJ_TREND,indicatorWindow,x1,y1,x2,y2);
      ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
      ObjectSetInteger(0,label,OBJPROP_STYLE,style);
      ObjectSetInteger(0,label,OBJPROP_WIDTH,0);
      ObjectSetInteger(0,label,OBJPROP_RAY,0);
      ObjectSetInteger(0,label,OBJPROP_BACK,false);
     }
   else
     {
      ObjectMove(0,label,0,x1,y1);
      ObjectMove(0,label,1,x2,y2);
     }
  }
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Function for drawing a trend line in a price chart window        |
//+------------------------------------------------------------------+
void DrawPriceTrendLine(int bar,datetime x1,datetime x2,double y1,double y2,color lineColor,int style)
  {
   string label="AO_Price_Divergence"+IntegerToString(bar)+TimeToString(x2);
   if(ObjectFind(0,label)==-1)
     {
      ObjectCreate(0,label,OBJ_TREND,0,x1,y1,x2,y2);
      ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
      ObjectSetInteger(0,label,OBJPROP_STYLE,style);
      ObjectSetInteger(0,label,OBJPROP_WIDTH,0);
      ObjectSetInteger(0,label,OBJPROP_RAY,0);
      ObjectSetInteger(0,label,OBJPROP_BACK,false);
     }
   else
     {
      ObjectMove(0,label,0,x1,y1);
      ObjectMove(0,label,1,x2,y2);
     }
  }
//----------------------------------------------------------------------------------------------------------//

&

void OnDeinit(const int reason)
  {
   Comment("");
   //ObjectsDeleteAll(0,0,OBJ_ARROW);
   //ObjectsDeleteAll(0,-1,OBJ_ARROW);
   //ObjectsDeleteAll(0,0,OBJ_TREND);
   //ObjectsDeleteAll(0,-1,OBJ_TREND);
   //ObjectsDeleteAll(0);
   //ObjectsDeleteAll(0,0,OBJ_VLINE);
   //ObjectsDeleteAll(0,0,OBJ_RECTANGLE);
   
   for(int j=1;j<=TOTAL_BAR;j++)
      {  
       for(int jj=1;jj<TOTAL_BAR;jj++)
          {  
           if(ObjectFind(0,"AO_Indicator_Divergence"+IntegerToString(j)+TimeToString(jj))>=0) 
              ObjectDelete(0,"AO_Indicator_Divergence"+IntegerToString(j)+TimeToString(jj));
           if(ObjectFind(0,"AO_Price_Divergence"+IntegerToString(j)+TimeToString(jj))>=0) 
              ObjectDelete(0,"AO_Price_Divergence"+IntegerToString(j)+TimeToString(jj));    
          }
      }

   ChartRedraw();
   ChartSetInteger(0,CHART_FOREGROUND,foreground);
  }

there is no error or warning but on chart there is problem.

what is wrong ?

thank you.
Reason: