Skip to content

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.

FunctionAction
ObjectCreateCreates an object of the specified type in a specified chart
ObjectNameReturns the name of an object by its index in the objects list
ObjectDeleteRemoves the object having the specified name
ObjectsDeleteAllRemoves all objects of the specified type from the specified chart subwindow
ObjectFindSearches for an object having the specified name
ObjectGetTimeByValueReturns the time value for the specified object price value
ObjectGetValueByTimeReturns the price value of an object for the specified time
ObjectMoveChanges the coordinates of the specified object anchor point
ObjectsTotalReturns the number of objects of the specified type
ObjectGetDoubleReturns the double value of the corresponding object property
ObjectGetIntegerReturns the integer value of the corresponding object property
ObjectGetStringReturns the string value of the corresponding object property
ObjectSetDoubleSets the value of the corresponding object property
ObjectSetIntegerSets the value of the corresponding object property
ObjectSetStringSets the value of the corresponding object property
TextSetFontSets the font for displaying the text using drawing methods (Arial 20 used by default)
TextOutTransfers the text to the custom array (buffer) designed for creation of a graphical resource
TextGetSizeReturns the string’s width and height at the current font settings
ObjectDescriptionReturns the object description
ObjectGetReturns the value of the specified object property
ObjectGetFiboDescriptionReturns the level description of a Fibonacci object
ObjectGetShiftByValueCalculates and returns bar index for the given price
ObjectGetValueByShiftCalculates and returns the price value for the specified bar
ObjectSetChanges the value of the specified object property
ObjectSetFiboDescriptionSets a new description to a level of a Fibonacci object
ObjectSetTextChanges the object description
ObjectTypeReturns 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

Last updated on