Object name by value???

 

Is there any way to find an object's name if you only have it's price value?

Specifically, I want to be able to determine if a Horizontal Line exists at a given price, knowing only the price value; and get the name of such a line if one exists.

I've racked my brain trying to figure out how to do this, and can't come up with anything that works.

 
Michael Vallone:

Is there any way to find an object's name if you only have it's price value?

Specifically, I want to be able to determine if a Horizontal Line exists at a given price, knowing only the price value; and get the name of such a line if one exists.

I've racked my brain trying to figure out how to do this, and can't come up with anything that works.

This code will do that but remember the chances of a double value being equal is very slim...

#property strict

void OnStart()
{
   double   Target = 13217.00;
   double   Price = 0;
   string   Name = "";
   for(int Obj=0; Obj<ObjectsTotal(0,0,OBJ_HLINE); Obj++)
   {
      Name = ObjectName(0,Obj,0,-1);
      Price = ObjectGetDouble(0,Name,OBJPROP_PRICE);
      if(Price = Target)
      {
         Alert("HLine found: " + Name + "  " + Price);
         break;
      }
   }
}
 
  1.       if(Price = Target)
    That is an assignment, not a comparison.
  2. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

 
William Roeder:
  1. That is an assignment, not a comparison.
  2. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

just a typo I'm sure he'll get the gist....
#property strict

void OnStart()
{
   double   Target = 13180.00;
   double   Price = 0;
   string   Name = "";
   for(int Obj=0; Obj<ObjectsTotal(0,0); Obj++)
   {
      Name = ObjectName(0,Obj,0,OBJ_HLINE);
      Price = ObjectGetDouble(0,Name,OBJPROP_PRICE);
      if(Price == Target)
      {
         Alert("HLine found: " + Name + "  " + Price);
         break;
      }
   }
}
Reason: