Main object properties

All objects have some universal attributes. The main ones are listed in the following table. We will see other general special-purpose properties later (see the Object state management, Z-order, and Visibility of objects in timeframe context sections).

Identifier

Description

Type

OBJPROP_NAME

Object name

string

OBJPROP_TYPE

Object type (r/o)

ENUM_OBJECT

OBJPROP_CREATETIME

Object creation time (r/o)

datetime

OBJPROP_TEXT

Description of the object (text contained in the object)

string

OBJPROP_TOOLTIP

Mouseover tooltip text

string

The OBJPROP_NAME property is an object identifier. Editing it is equivalent to deleting the old object and creating a new one.

For some types of objects capable of displaying text (such as labels or buttons), the OBJPROP_TEXT property is always displayed directly on the chart, inside the object. For other objects (for example, lines), this property contains a description that is displayed on the chart next to the object and only if the "Show object descriptions option" is enabled in the chart settings. In either case, OBJPROP_TEXT is displayed in the tooltip.

The OBJPROP_CREATETIME property exists only until the end of the current session and is not written to chr files.

You can change the name of an object programmatically or manually (in the object's properties dialog), while its creation time will remain the same. Looking ahead, we note that programmatic renaming does not cause any events about objects on the chart. As we are about to learn in the next chapter, manual renaming triggers three events:

  • deleting an object under the old name (CHARTEVENT_OBJECT_DELETE),
  • creating an object under a new name (CHARTEVENT_OBJECT_CREATE) and
  • modification of a new object (CHARTEVENT_OBJECT_CHANGE).

If the OBJPROP_TOOLTIP property is not set, a tooltip is displayed for the object, automatically generated by the terminal. To disable the tooltip, set its value to "\n" (line feed).

Let's adapt the ObjectFinder.mq5 script from the Finding objects section to log all the above properties of objects on the current chart. Let's name the new script as ObjectListing.mq5.

At the very beginning of OnStart, we will create or modify a vertical straight line located on the last bar (at the moment the script is launched). If there is an option to show object descriptions in the chart settings, then we will see the "Latest Bar At The Moment" text along the right vertical line.

void OnStart()
{
   const string vline = ObjNamePrefix + "current";
   ObjectCreate(0vlineOBJ_VLINE0iTime(NULL00), 0);
   ObjectSetString(0vlineOBJPROP_TEXT"Latest Bar At The Moment");
   ...

Next, in a loop through the subwindows, we will query all objects up to ObjectsTotal and their main properties.

   int count = 0;
   const long id = ChartID();
   const int win = (int)ChartGetInteger(idCHART_WINDOWS_TOTAL);
   // loop through subwindows
   for(int k = 0k < win; ++k)
   {
      PrintFormat("  Window %d"k);
      const int n = ObjectsTotal(idk);
      //loop through objects
      for(int i = 0i < n; ++i)
      {
         const string name = ObjectName(idik);
         const ENUM_OBJECT type =
            (ENUM_OBJECT)ObjectGetInteger(idnameOBJPROP_TYPE);
         const datetime created =
            (datetime)ObjectGetInteger(idnameOBJPROP_CREATETIME);
         const string description = ObjectGetString(idnameOBJPROP_TEXT);
         const string hint = ObjectGetString(idnameOBJPROP_TOOLTIP);
         PrintFormat("    %s %s %s %s %s"EnumToString(type), name,
            TimeToString(created), descriptionhint);
         ++count;
      }
   }
   
   PrintFormat("%d objects found"count);
}

We get the following entries in the log.

  Window 0
    OBJ_VLINE ObjShow-current 2021.12.21 20:20 Latest Bar At The Moment 
    OBJ_VLINE abc 2021.12.21 19:25  
    OBJ_VLINE xyz 1970.01.01 00:00  
3 objects found

A zero OBJPROP_CREATETIME value (1970.01.01 00:00) means that the object was not created during the current session, but earlier.