How to use ObjectGet on a different chart?

 

Hi all,

I am using MQL4 and I found out that ObjectGet doesn't support a chartId as you can see from the following screenshot:


and therefore I am not able to use it on charts different than the one the EA is running.

Is there a way to solve this problem?

Thanks in advance.

 
Luca De Marco:

Hi all,

I am using MQL4 and I found out that ObjectGet doesn't support a chartId as you can see from the following screenshot:


and therefore I am not able to use it on charts different than the one the EA is running.

Is there a way to solve this problem?

Thanks in advance.

https://docs.mql4.com/objects/objectgetdouble
 

It's for the current chart only.

But you can do it with the extended calls like,

ObjectGetInteger()
ObjectGetDouble()
 
I want to retrieve the OBJPROP_RAY of a trend line and that parameter is available to use only with ObjectGet. I will have the same problem with ObjectSet as I want then to set that value on another chart.
 

I don't understand why you insist with ObjectGetDouble...

As you can see it doesn't work!

 
Luca De Marco:

I don't understand why you insist with ObjectGetDouble...

As you can see it doesn't work!

You are simply calling the function, you are not assigning the value to anything

 
Keith Watford:

You are simply calling the function, you are not assigning the value to anything

Did you read the error underneath the code?

It doesn't work!

 

Fix your code.

Look at the documentation.

Function

Action

ObjectCreate

Creates an object of the specified type in a specified chart

ObjectName

Returns the name of an object of the corresponding type in the specified chart (specified chart subwindow)

ObjectDelete

Removes the object with the specified name from the specified chart (from the specified chart subwindow)

ObjectsDeleteAll

Removes all objects of the specified type from the specified chart (from the specified chart subwindow)

ObjectFind

Searches for an object with the specified ID by the name

ObjectGetTimeByValue

Returns the time value for the specified object price value

ObjectGetValueByTime

Returns the price value of an object for the specified time

ObjectMove

Changes the coordinates of the specified object anchor point

ObjectsTotal

Returns the number of objects of the specified type in the specified chart (specified chart subwindow)

ObjectGetDouble

Returns the double value of the corresponding object property

ObjectGetInteger

Returns the integer value of the corresponding object property

ObjectGetString

Returns the string value of the corresponding object property

ObjectSetDouble

Sets the value of the corresponding object property

ObjectSetInteger

Sets the value of the corresponding object property

ObjectSetString

Sets the value of the corresponding object property

TextSetFont

Sets the font for displaying the text using drawing methods (Arial 20 used by default)

TextOut

Transfers the text to the custom array (buffer) designed for creation of a graphical resource

TextGetSize

Returns the string's width and height at the current font settings


bool ray = ObjectGetInteger(ChartID(),"Trend",OBJPROP_RAY);
 
Luca De Marco:

Did you read the error underneath the code?

It doesn't work!

Oh, I see.

You should be using ObjectGetInteger() and you should be assigning its value to something or checking to see if it is true or not.

 
Keith Watford:

Oh, I see.

You should be using ObjectGetInteger() and you should be assigning its value to something or checking to see if it is true or not.

Yes I know how to use a result from a function, that code was simply to prove that it doesn't work.

However, I tried with ObjectGetInteger and it works. Thanks for the tip!

But I don't understand how you know it, because from the documentation it says tht OBJPROP_RAY must be used with ObjectGet:


 
Marco vd Heijden:

Fix your code.

Look at the documentation.

Function

Action

ObjectCreate

Creates an object of the specified type in a specified chart

ObjectName

Returns the name of an object of the corresponding type in the specified chart (specified chart subwindow)

ObjectDelete

Removes the object with the specified name from the specified chart (from the specified chart subwindow)

ObjectsDeleteAll

Removes all objects of the specified type from the specified chart (from the specified chart subwindow)

ObjectFind

Searches for an object with the specified ID by the name

ObjectGetTimeByValue

Returns the time value for the specified object price value

ObjectGetValueByTime

Returns the price value of an object for the specified time

ObjectMove

Changes the coordinates of the specified object anchor point

ObjectsTotal

Returns the number of objects of the specified type in the specified chart (specified chart subwindow)

ObjectGetDouble

Returns the double value of the corresponding object property

ObjectGetInteger

Returns the integer value of the corresponding object property

ObjectGetString

Returns the string value of the corresponding object property

ObjectSetDouble

Sets the value of the corresponding object property

ObjectSetInteger

Sets the value of the corresponding object property

ObjectSetString

Sets the value of the corresponding object property

TextSetFont

Sets the font for displaying the text using drawing methods (Arial 20 used by default)

TextOut

Transfers the text to the custom array (buffer) designed for creation of a graphical resource

TextGetSize

Returns the string's width and height at the current font settings


I looked at the documentation and as you can see from the screenshot, it says that OBJPROP_RAY must be used with ObjectGet. Can you tell me where it is written otherwise, so I won't commit the same error again with another property?

HOwever I tried with ObjectGetInteger and it worked! Thanks for the tip.

Reason: