MQL4 Reference Object Functions ObjectsTotal

MQL4 Help as One File:

ObjectsTotal

The function returns the number of objects of the specified type in the specified chart. There are two variants of the function:

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

The function returns the number of objects of the specified type:

int  ObjectsTotal(
   int    type=EMPTY        // object type
   );

Parameters

chart_id

[in]  Chart identifier.

sub_window=-1

[in]  Number of the chart subwindow. 0 means the main chart window, -1 means all the subwindows of the chart, including the main window.

type=-1

[in]  Type of the object. The value can be one of the values of the ENUM_OBJECT enumeration. EMPTY(-1) means all types.

Return Value

The number of objects.

Note

When this function is used on the current chart, this chart is accessed directly, while in order to receive the properties of an object on a different chart, a synchronous call is used. The synchronous call means that the function waits for the execution of the command added to the chart queue. If the queue already contains other commands, the result will only be obtained after their execution.

Example:

  int obj_total=ObjectsTotal();
  string name;
  for(int i=0;i<obj_total;i++)
    {
     name = ObjectName(i);
     Print(i," object - ",name);
    }