Delete object by "description"

Back to topics list To post a new topic, please log in or register
avatar
16
gviali 2015.02.11 20:06
 

Hi guys, I couldn't find here in the forum or documentation if is it possible to delete an object by getting his description only instead of the the name.

 The application is to delete that Arrow object created by any EA when a position is opened as soon as it is created.  I tought about insert this ObjectDelete function right above the OrderSend, so, as soon as the order is triggered, the delete function is triggered with, and instantly delete the object.

 So, is it possible? 

 Thanks in advance. 

avatar
207
Rasoul 2015.02.11 20:18 #
 
int total=ObjectsTotal();

for(int i=0;i<total;i++)
{
  if(StringCompare(ObjectDescription(ObjectName(i)),the_description)==0)
  {
     ObjectDelete(ChartID(),ObjectName(i));
     break;   
  }
}

avatar
736
honest_knave 2015.02.11 20:40 #
 
If you're going to be deleting things from within a loop, you'll need to count down (not up).
avatar
13009
WHRoeder 2015.02.11 21:30 #
 
You must count down when closing/deleting in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum  (Also applies to deleting multiple objects)
avatar
16
gviali 2015.02.12 00:23 #
 

So, would it be like this?

int i;
int totalobjects = ObjectsTotal();

for(i=totalobjects-1;i>=0;i--)
  {
    if(StringCompare(ObjectDescription(ObjectName(i)),"delete-me")==0)
    {
     ObjectDelete(ChartID(),ObjectName(i));
     break;
     }
   }

 

avatar
21
hji 2015.02.13 08:17 #
 
gviali:

So, would it be like this?

 

Yes,when counting down it would be like that.
Back to topics list  

To add comments, please log in or register