Delete Objects from EA

 

Hi everyone,

I am using below codes to delete all the objects created by EA.

However, when I remove the EA, there are still some objects remain on the chart

All my object names are created with something like

string name="EA" + XKDLJFLSIJ;

int init()
{
  RemoveEADrawings();
}


int deinit()
{
  RemoveEADrawings();
}

void RemoveEADrawings()
{
        for (int i=0; i<=ObjectsTotal(); i++)
        {       
                string name=ObjectName(i);
                
                if (StringFind(name,"EA")!=-1)  //also tried 
//if (StringFind(name,"EA")>-1)
                        ObjectDelete(name);                 else                         continue;         }               }
 

I have so many objects with different name so I can not use

StringFind ()

and in my case the object sometime were added or deleted by other CI.

You should re - check the return of

ObjectsTotal ()

in each iteration. I said re - check, then re adjust the i value less or more.

 
onewithzachy:

I have so many object with different name so I can not use

and in my case the object sometime were added or deleted by other CI.

You should re - check the return of

in each iteration. I said re - check, then re adjust the i value less or more.


get your point

now I need help with your point 2

am I asking too much

 
holdenmcgorin:


get your point

now I need help with your point 2

am I asking too much

Yes you are asking too much.

Read careful. On object list on MT4 (Ctrl + B) say you have 5 objects named obj_1, obj_2 .... obj_5, the iteration start at i = 0, and delete the top object which obj_1.

Now obj_2 moves on top of the list but now the value of i is 1 and pointed at second on the list which is obj_3. it delete obj_3 but not delete obj_2.

Just open object list and play around, pretend that you are a for loop :).

In your case after deleting object, set i back to -1.

 

Thank you

works wonderfully.

 
holdenmcgorin:

Hi everyone,

I am using below codes to delete all the objects created by EA.

However, when I remove the EA, there are still some objects remain on the chart

All my object names are created with something like

string name="EA" + XKDLJFLSIJ;

Adjust your loop so it counts down not up . . .
Reason: