Download MetaTrader 5
To add comments, please log in or register
Do you want to order an application? Find out how to obtain the desired result
Gabriel Viali
201
Gabriel Viali 2015.02.11 19: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. 

Rasoul Mojtahedzadeh
25173
Rasoul Mojtahedzadeh 2015.02.11 19:18  
int total=ObjectsTotal();

for(int i=0;i<total;i++)
{
  if(StringCompare(ObjectDescription(ObjectName(i)),the_description)==0)
  {
     ObjectDelete(ChartID(),ObjectName(i));
     break;   
  }
}
honest_knave
951
honest_knave 2015.02.11 19:40  
If you're going to be deleting things from within a loop, you'll need to count down (not up).
whroeder1
13597
whroeder1 2015.02.11 20: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)
Gabriel Viali
201
Gabriel Viali 2015.02.11 23: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;
     }
   }
hji
26
hji 2015.02.13 07:17  
gviali:

So, would it be like this?

 

Yes,when counting down it would be like that.
/
To add comments, please log in or register