How to use ObjectGetValueByShift("Horizontal Line", 0);

Cromo
393
Cromo  

HI, I need your help.


I draw the horizontal Line on the chart by manual.

And I want the EA to read the value (price)

But when I draw it by manual, object name has some numbers. --> 38987

What is this number?

TO read the price of the line, I want to use

  double Price =ObjectGetValueByShift("Horizontal Line", 0);

But can I use wildcart of the object?

Instead of below?

  double dn=ObjectGetValueByShift("Horizontal Line 38987", 0);
Keith Watford
Moderator
29862
Keith Watford  
Cromo:

HI, I need your help.


I draw the horizontal Line on the chart by manual.

And I want the EA to read the value (price)

But when I draw it by manual, object name has some numbers. --> 38987

What is this number?

TO read the price of the line, I want to use

But can I use wildcart of the object?

Instead of below?

When you draw the line, open the properties box and rename it.

You don't use 

double dn=ObjectGetValueByShift("Horizontal Line 38987", 0);

for a horizontal line as it only has 1 price.

Use ObjectGetDouble()

Cromo
393
Cromo  

Thanks, Keith

is there any ways to pick up the price of the Horizontal line without rename it?

Like.... Find the pre-fix of Horizontal ****, then use ObjectGetDouble to read the price.

Drazen Penic
3267
Drazen Penic  
Cromo:

Thanks, Keith

is there any ways to pick up the price of the Horizontal line without rename it?

Like.... Find the pre-fix of Horizontal ****, then use ObjectGetDouble to read the price.

Loop through all objects on the chart and compare the name with pattern (using StringFind or StringSubstr).

See example from the ObjectsTotal help page

ObjectsTotal - Object Functions - MQL4 Reference
ObjectsTotal - Object Functions - MQL4 Reference
  • docs.mql4.com
When this function is used on the current chart, this chart is accessed directly, while in order to receive the properties of an object on a different chart, a synchronous call is used. The synchronous...
Keith Watford
Moderator
29862
Keith Watford  
Cromo:

Thanks, Keith

is there any ways to pick up the price of the Horizontal line without rename it?

Like.... Find the pre-fix of Horizontal ****, then use ObjectGetDouble to read the price.

Only if you know for sure that there will only be 1 horizontal line on the chart at any time.

Cromo
393
Cromo  
Keith Watford:

Only if you know for sure that there will only be 1 horizontal line on the chart at any time.

Thanks. I will try some other ways!
Cromo
393
Cromo  
Drazen Penic:

Loop through all objects on the chart and compare the name with pattern (using StringFind or StringSubstr).

See example from the ObjectsTotal help page

Good idea... Nice! StringFind or StringSubstr