How to iterate through all objects in another chart ?

 

Hi, I have an expert attach to a chart. It need to iterate through all other opened charts, and iterate through objects in all of this charts.

I iterate through charts without problems, but I don't know how to iterate through objects in another chart than the one where the expert is attached.

Because, to get information of an object in a different chart, the only solution is to use ObjectGetString, ObjectGetInteger,... functions, but all of these functions take in parameter only an object name, and not an index.

But of course, I don't have objects names of another chart.

So is it possible and how to get all objects of a another chart ?

Thanks in advance

 

Function

Action

ObjectName

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

ObjectsTotal

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

 
dv3lut: but I don't know how to iterate through objects in another chart than the one where the expert is attached.

Perhaps you should read the manual. ObjectsTotal - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

 
William Roeder #:

Perhaps you should read the manual. ObjectsTotal - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Sorry I forgot to mention that I'm in MQL4 , and in MQL4, ObjectName function works in current chart only.
 

Ok I find the solution on another topic.

The function ObjectName of the MQL5 documentation work in MQL4... But it's not documented on the MQL4 doc..

 
dv3lut #: Sorry I forgot to mention that I'm in MQL4 , and in MQL4, ObjectName function works in current chart only.

That is incorrect! On MQL4+ It works just like in MQL5. Just make sure to use the MQL4+ version of ObjectsTotal.

int  ObjectsTotal(
   long  chart_id,          // chart identifier
   int   sub_window=-1,     // window index
   int   type=-1            // object type
   );

Also, next time, please post in the correct MQL4 section at the end of the forum.

 
dv3lut #: Ok I find the solution on another topic. The function ObjectName of the MQL5 documentation work in MQL4... But it's not documented on the MQL4 doc..

It is documented in the MQL4 documentation (see the following MQL4 links). You just did not update your reading. It's also in MetaEditor when you hit F1..

Function

Action

ObjectName

Returns the name of an object by its index in the objects list

ObjectsTotal

Returns the number of objects of the specified type

 
Fernando Carreiro #:

It is documented in the MQL4 documentation (see the following MQL4 links). You just did not update your reading. It's also in MetaEditor when you hit F1..

Function

Action

ObjectName

Returns the name of an object by its index in the objects list

ObjectsTotal

Returns the number of objects of the specified type

Yes the function objectName work in mql4, but in this doc, it only take an index in parameter and not a chartId :

string  ObjectName(
   int   object_index   // object index
   );

So according to this, this function only works in the current chart, and not in another. (If my EA is attached to EURUSD, and I need to get the name of an object in the USDJPY chart, it's not possible).

Until I discovered that this works :

string  ObjectName(
   long  chart_id,           // chart identifier
   int   pos,                // number in the list of objects
   int   sub_window=-1,      // window index
   int   type=-1             // object type
   );

But this is the mql5 documentation.

Sorry if my explanation were not enough precise.

Yes next time I'll post in the good section.


 
dv3lut #: Yes the function objectName work in mql4, but in this doc, it only take an index in parameter and not a chartId
Yes, you are correct! I missed that. The MQL4 documentation is indeed incomplete. My apologies for the confusion.
 
Fernando Carreiro #: The MQL4 documentation is indeed incomplete.

To my knowledge, first reported seven (7) years ago. Object creation on different charts - MQL4 programming forum (2016)

 
dv3lut:

Because, to get information of an object in a different chart, the only solution is to use ObjectGetString, ObjectGetInteger,... functions, but all of these functions take in parameter only an object name, and not an index.

bool  ObjectGetString(
   long                            chart_id,          // chart identifier
   string                          name,              // object name
   ENUM_OBJECT_PROPERTY_STRING     prop_id,           // property identifier
   int                             prop_modifier,     // property modifier
   string&                         string_var         // here we accept the property value
   );

Not too long ago, this confused me too: click

Question about deleting objects
Question about deleting objects
  • 2023.01.02
  • www.mql5.com
I want to delete objects whose name contains the specified substring...
Reason: