All objects can't be deleted

 

Hello,

I have problem when I want to delete all objects from chart with names begining at "AT_".

Only several of them are deleted, always the same are leving on the chart. I cheked names, all are correct and all objects are finded but not deleted.

Any idea?

void DeleteAllObjects()
 {
  
  int obj_total=ObjectsTotal(); 
  string name; 
  
  for(int i=0;i<obj_total;i++) 
    { 
     name = ObjectName(i);

     if(StringFind(name,"AP_")>=0)
       {
         Print(name);
         ObjectDelete(
0,name);
       }
    }
    
  return; 
 }
 
GiovanniImperiale:

Hello,

I have problem when I want to delete all objects from chart with names begining at "AT_".

Only several of them are deleted, always the same are leving on the chart. I cheked names, all are correct and all objects are finded but not deleted.

Any idea?

ObjectDelete("AT_");

or

ObjectsDeleteAll();

This might work.....

 
GiovanniImperiale: Only several of them are deleted,
  1. Kenneth has already given you the simple method.
  2. The reason your code doesn't work is that you are counting up.
    you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
              Loops and Closing or Deleting Orders - MQL4 programming forum
 

Hello,

Yes, 

ObjectsDeleteAll(); 

can be use but I want to avoid deleting objects which are the part of second panel on chart. That's why I used:

if(StringFind(name,"AP_")>=0)

But with Roedger advaise it works.

Thank you!

 
GiovanniImperiale:

Hello,

Yes, 

ObjectsDeleteAll(); 

can be use but I want to avoid deleting objects which are the part of second panel on chart. That's why I used:

But with Roedger advaise it works.

Thank you!

ObjectsDeleteAll(0,"AT_);