Download MetaTrader 5

How to refernce a chart object

To add comments, please log in or register
Have you just installed MetaTrader 5? Learn it in details!
Peter Williams
344
Peter Williams 2014.05.22 12:25 

Thought this would be easy but can't find a solution


If - for example I have some objects on a chart then I want my EA to check for there existence then interrogate the details of the object.

If I draw - say 3 lines on a chart - Insert Hline - then I will have 3 lines withe names like Horizontal Line 12345.

I want to check and find say 5 x Horizontal Lines (Resistance Levels)  and then find the value of each and then write the information to file for that symbol.

The name of the object does not matter

Any help appreciated

Drazen Penic
2543
Drazen Penic 2014.05.22 13:29  

You need the name of an object to get the information.

If you don't know names then check ObjectsTotal() and Objectname() functions.

This is sample code that lists objects on a chart:

   int obj_total=ObjectsTotal();
   PrintFormat("Total %d objects",obj_total);
   string name;
   for(int i=0;i<obj_total;i++)
     {
      name=ObjectName(i);
      PrintFormat("%d object: Object name - %s",i,name);
     }

 

If you have a name of an object(s) then check if object exists on a chart with ObjectFind() and if object exists you can obtain data via ObjectGet()ObjectGetDouble(), ObjectGetInteger() and ObjectGetString() functions.

Peter Williams
344
Peter Williams 2014.05.23 08:08  

Just what I thought I should be able to do but hadn't found / understood the parts.


Many thanks

To add comments, please log in or register