How to obtain the properties of an object

 
How can I get the properties of an object, say the date value of a vertical line which I have placed manually?
 
Right click → properties.
 
William Roeder:
Right click → properties.
Lols...
Sorry, I mean properties of a Manually Placed OBJECT (e.g. the date of a vertical line). How can an EA identify a highlighted one?
 
macpee:
Lols...
Sorry, I mean by an expert advisor and not using the property window.

So, you want to develop something but you are not able to use MQL4 help file? Or the online MQL4 documentation?

Since you are obviously not familiar with the concept of documentation, first thing first  ==>

  1. Press F1 in Metaeditor 
  2. When the new window pops up, search for the section called "Object functions" .
  3. Read (not complicated, short reading)

Object Functions - MQL4 Reference
Object Functions - MQL4 Reference
  • docs.mql4.com
This is the group of functions intended for working with graphic objects relating to any specified chart. When working with objects on the current chart, a direct access is used, i.e. the existence of the specified object is pre-checked during the function call, and the error code is immediately returned in case of failure. When a function is...
 
Drazen Penic:

So, you want to develop something but you are not able to use MQL4 help file? Or the online MQL4 documentation?

Since you are obviously not familiar with the concept of documentation, first thing first  ==>

  1. Press F1 in Metaeditor 
  2. When the new window pops up, search for the section called "Object functions" .
  3. Read (not complicated, short reading)

Thanks a lot. But which function can I use to locate the object that my mouse is pointing to?

Note that when you place an object on the chart, you do not know the name or care to know the date or price.

But the ObjectFind() function uses the name of the object, which in this case, you are not ready to use for the programming.

The idea is to locate an object that the mouse has select for dragging... and obtain its properties for further use.




 
macpee:
Thanks a lot. But which function can I use to locate the object that my mouse is pointing to?

It would be very nice if you describe your use case so that people trying to help you know what you want.

Getting properties of the object and checking where the mouse is are two different problems.

Search for OnChartEvent in the documentation, this forum and codebase. You will find thousands of examples.

 
Drazen Penic:

It would be very nice if you describe your use case so that people trying to help you know what you want.

Getting properties of the object and checking where the mouse is are two different problems.

Search for OnChartEvent in the documentation, this forum and codebase. You will find thousands of examples.

Ok thanks. First, I need to locate the mouse position then.
 
macpee:
Thanks a lot. But which function can I use to locate the object that my mouse is pointing to?

Note that when you place an object on the chart, you do not know the name or care to know the date or price.

But the ObjectFind() function uses the name of the object, which in this case, you are not ready to use for the programming.

The idea is to locate an object that the mouse has select for dragging... and obtain its properties for further use.




You can search it by name or color

even you can search it by date

 
amando:

You can search it by name or color

even you can search it by date

We are not searching by name or date or color .... We are searching by mouse dragging or by clicking. 

Maybe the CHARTEVENT_OBJECT_CLICK will do in OnChartEvent() function.


I have the following. Is it good for a start?


void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
   if ((id == CHARTEVENT_OBJECT_DRAG) && (ObjectType() == OBJ_VLINE))
      {"do something"}
   
  }
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
There are 11 types of events that can be processed using the predefined function OnChartEvent(). For custom events 65535 identifiers are provided in the range of CHARTEVENT_CUSTOM to CHARTEVENT_CUSTOM_LAST inclusive. To generate a custom event, the EventChartCustom() function should be used. For each type of event, the input parameters of the...
 
macpee:
We are not searching by name or date or color .... We are searching by mouse dragging or by clicking. 

Maybe the CHARTEVENT_OBJECT_CLICK will do in OnChartEvent() function.


I have the following. Is it good for a start?


Wow! The documentation though, will prove helpful. Thanks to sender.
 
macpee:
Wow! The documentation though, will prove helpful. Thanks to sender.

I think I got it now. I did not know that the sparam stands for the name of the object.

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
   if ((id == CHARTEVENT_OBJECT_DRAG) && (ObjectType(sparam) == OBJ_VLINE))
      Print("do something");
   
  }

Thank you all

This is the result of running the followng code. Why are lparam and dparam giving zero values?

Result:      

(id = 2)(lparam = 0)(dparam = 0)(sparam = Vertical Line 33317)

Code:

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
   if ((id == CHARTEVENT_OBJECT_DRAG) && (ObjectType(sparam) == OBJ_VLINE))
      Print("(id = ",id,")", "(lparam = ",lparam,")", "(dparam = ",dparam,")", "(sparam = ",sparam,")");
   
  }
Reason: