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; } } }
-
if(Price = Target)
That is an assignment, not a comparison. -
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum #2 2013.06.07
William Roeder:
- That is an assignment, not a comparison.
-
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; } } }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.