The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow of the specified chart. There are two variants of the function:
The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow:
[in] Chart identifier.
[in] Name of the object. The name must be unique within a chart, including its subwindows.
[in] Object type. The value can be one of the values of the ENUM_OBJECT enumeration.
[in] Number of the chart subwindow. 0 means the main chart window. The specified subwindow must exist (window index must be greater or equal to 0 and less than WindowsTotal()), otherwise the function returns false.
[in] The time coordinate of the first anchor point.
[in] The price coordinate of the first anchor point.
[in] The time coordinate of the second anchor point.
[in] The price coordinate of the second anchor point.
[in] The time coordinate of the third anchor point.
[in] The price coordinate of the third anchor point.
[in] The time coordinate of the N-th anchor point.
[in] The price coordinate of the N-th anchor point.
When the function is used on the current chart, the chart is accessed directly (a usual behavior in MQL4), and the return of true means a successful creation of an object; otherwise false is returned. In this case, you should call GetLastError() for further information about the error.
To create objects on a different size, an asynchronous function call is used, and ObjectCreate() only returns the result of command adding to the chart queue. In this case true means that the object creation command has been successfully enqueued, while the command execution result is unknown. To check the command execution result, you can use the ObjectFind function or any other function that request object properties, such as ObjectGetXXX. However, you should keep in mind that such functions are added to the end of the queue of that chart, and they wait for the execution result (due to the synchronous call), and can therefore be time consuming.
An object name should not exceed 63 characters. Characters not belonging to the current code page are not allowed (characters that cannot be converted from Unicode to ANSI are replaced with '?'). If programs are to be distributed among users with different code pages, we strongly recommend using Latin characters in object names.
Objects of the OBJ_LABEL type ignore the coordinates. Use the ObjectSet() function to set up the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties. 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. Coordinates must be passed in pairs: time and price. For example, the OBJ_VLINE object needs only time, but price (any value) must be passed, as well.