MQL4 Reference Object Functions ObjectsDeleteAll

ObjectsDeleteAll

Removes all objects from the specified chart, specified chart subwindow, of the specified type.

int  ObjectsDeleteAll(
   long   chart_id,           // chart ID
   int    sub_window=EMPTY,   // window index
   int    object_type=EMPTY   // object type
   );

Removes all objects of the specified type from the specified chart subwindow.

int  ObjectsDeleteAll(
   int    sub_window=EMPTY,   // window index
   int    object_type=EMPTY   // object type
   );

Removes all objects of the specified type using prefix in object names.

int  ObjectsDeleteAll(
   long           chart_id,   // chart ID
   const string     prefix,   // prefix in object name
   int    sub_window=EMPTY,   // window index
   int    object_type=EMPTY   // object type
   );

Parameters

chart_id

[in]  Chart identifier.

prefix

[in]  Prefix in object names. All objects whose names start with this set of characters will be removed from chart. You can specify prefix as 'name' or 'name*' — both variants will work the same. If an empty string is specified as the prefix, objects with all possible names will be removed.

sub_window=EMPTY

[in] Number of the chart window. Must be greater or equal to -1 (-1 mean all subwindows, 0 means the main chart window) and less than WindowsTotal().

object_type=EMPTY

[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

Returns the number of deleted objects. To read more about the error call GetLastError().

Note

Indexing of chart subwindows (if a chart has subwindows with indicators) starts with 1. The index of the main chart window is always equal to 0. If a window has no index, or its index is -1, objects will be deleted from the entire chart. If the value of the type parameter is -1 or this parameter is not available, all objects from the specified subwindow will be deleted.

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. In this case, the return value means the function execution result.

If the ID of a chart other than the current one is specified, the return value only informs whether the command has been added to the queue of that chart. In this case an asynchronous call is used, which means that the function does not wait for the execution of the command that has been added to the queue of another chart. Instead, it immediately returns control.

To check the result of command execution on a chart other than the current one, you can use a function that checks the specified object property. However, you should keep in mind that such functions are added to the end of the queue of that chart and wait for the execution result, and can therefore be time consuming. This feature should be taken into account when working with a large number of objects on a chart.

Example:

  ObjectsDeleteAll(2, OBJ_HLINE); // delete all horizontal lines from the 2nd subwindow
  ObjectsDeleteAll(2);            // delete all objects from the 2nd subwindow
  ObjectsDeleteAll();             // delete all objects from chart.