MQL4参考 物件函数 ObjectFind

ObjectFind

The function searches for an object having the specified name. There are two variants of the function:

int  ObjectFind(
   long     chart_id,     // chart ID
   string   object_name   // object name
   );

The function searches the object with the specified name:

int  ObjectFind(
   string   object_name   // object name
   );

Parameters

chart_id

[in]  Chart identifier.

object_name

[in]  The name of the object to find.

Return Value

If successful the function returns the number of the subwindow (0 means the main window of the chart), in which the object is found. If the object is not found, the function returns a negative number. To read more about the error call GetLastError().

Note

The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index.

When the function is used with no chart ID specified, the function is supposed to be working with the current chart to which it has a direct access.

If a chart ID is specified in the function call, a synchronous call will be used to search for an object on a chart different from the current one. The synchronous call means that the function waits for the execution of all commands that have been enqueued for this chart prior to its call, that is why this function can be time consuming. This feature should be taken into account when working with a large number of objects on a chart.

Example:

  if(ObjectFind(0,"line_object2")!=win_idx) return(0);