MQL4 Reference Object Functions

Object Functions

This is the group of functions intended for working with graphic objects relating to any specified chart. When working with objects on the current chart, a direct access is used, i.e. the existence of the specified object is pre-checked during the function call, and the error code is immediately returned in case of failure. When a function is used for the objects of a chart other than the current one, an asynchronous function call is used, during which no pre-checks are performed and the function is added to the queue of that chart as is.

Functions that set the properties of graphical objects, as well as the ObjectCreate() and ObjectMove() operations are actually used for sending commands to a chart. If these functions are executed successfully, the command is added to the queue of chart events. Visual changes in the properties of graphical objects are implemented upon handling of chart events from the queue.

That is why you should do not expect an immediate visual update of graphical objects after calling these functions. Generally, graphical objects on a chart are updated automatically by the terminal based on update events, such as a new quote arrival, chart window resizing, etc. Use the ChartRedraw() command to force the update of graphical objects.

Function

Action

ObjectCreate

Creates an object of the specified type in a specified chart

ObjectName

Returns the name of an object by its index in the objects list

ObjectDelete

Removes the object having the specified name

ObjectsDeleteAll

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

ObjectFind

Searches for an object having the specified name

ObjectGetTimeByValue

Returns the time value for the specified object price value

ObjectGetValueByTime

Returns the price value of an object for the specified time

ObjectMove

Changes the coordinates of the specified object anchor point

ObjectsTotal

Returns the number of objects of the specified type

ObjectGetDouble

Returns the double value of the corresponding object property

ObjectGetInteger

Returns the integer value of the corresponding object property

ObjectGetString

Returns the string value of the corresponding object property

ObjectSetDouble

Sets the value of the corresponding object property

ObjectSetInteger

Sets the value of the corresponding object property

ObjectSetString

Sets the value of the corresponding object property

TextSetFont

Sets the font for displaying the text using drawing methods (Arial 20 used by default)

TextOut

Transfers the text to the custom array (buffer) designed for creation of a graphical resource

TextGetSize

Returns the string's width and height at the current font settings

ObjectDescription

Returns the object description

ObjectGet

Returns the value of the specified object property

ObjectGetFiboDescription

Returns the level description of a Fibonacci object

ObjectGetShiftByValue

Calculates and returns bar index for the given price

ObjectGetValueByShift

Calculates and returns the price value for the specified bar

ObjectSet

Changes the value of the specified object property

ObjectSetFiboDescription

Sets a new description to a level of a Fibonacci object

ObjectSetText

Changes the object description

ObjectType

Returns the object type

Every graphical object should have a name unique within one chart, including its subwindows. Changing of a name of a graphic object generates two events: event of deletion of an object with the old name, and event of creation of an object with a new name.

After an object is created or an object property is modified it is recommended to call the ChartRedraw() function, which commands the client terminal to forcibly draw a chart (and all visible objects in it).

 

What's new in MQL5

MQL5 features more graphical objects, and the most unusual of them is OBJ_CHART(Chart) — you are able to insert such objects as symbol charts. If you complement OBJ_CHART with indicators and control panels handling custom events, a usual chart turns into a convenient analysis tool with the ability to quickly change symbols and timeframes in a single mouse click.

The properties of objects for managing program objects have been significantly expanded. Now you are able to set colors, move an object to the back or front, set the priority for intercepting keyboard and mouse events on a chart, as well as select an object or hide it from the list of visible ones. All this allows you to develop a graphical user interface of any complexity.

live_chart_panel