- Functions for getting the basic properties of the current chart
- Chart identification
- Getting the list of charts
- Getting the symbol and timeframe of an arbitrary chart
- Overview of functions for working with the complete set of properties
- Descriptive chart properties
- Checking the status of the main window
- Getting the number and visibility of windows/subwindows
- Chart display modes
- Managing the visibility of chart elements
- Horizontal shifts
- Horizontal scale (by time)
- Vertical scale (by price and indicator readings)
- Colors
- Mouse and keyboard control
- Undocking chart window
- Getting MQL program drop coordinates on a chart
- Translation of screen coordinates to time/price and vice versa
- Scrolling charts along the time axis
- Chart redraw request
- Switching symbol and timeframe
- Managing indicators on the chart
- Opening and closing charts
- Working with tpl chart templates
- Saving a chart image
Getting the list of charts
An MQL program can get a list of charts opened in the terminal (both windows and graph objects) using the functions ChartFirst and ChartNext.
long ChartFirst()
long ChartNext(long chartId)
The ChartFirst function returns the identifier of the first chart in the client terminal. MetaTrader 5 maintains an internal list of all charts, the order in which may differ from what we see on the screen, for example, in window tabs when they are maximized. In particular, the order in the list can change as a result of dragging tabs, undocking, and docking windows. After loading the terminal, the visible order of the bookmarks is the same as the internal list view.
The ChartNext function returns the ID of the chart following the chart with the specified chartId.
Unlike other functions for working with graphs, the value 0 in the ChartId parameter means not the current chart, but the beginning of the list. In other words, ChartNext(0) call is equivalent to ChartFirst.
If the end of the list is reached, the function returns -1.
The script ChartList1.mq5 outputs the list of charts into the log. The main work is performed by the ChartList function which is called from OnStart. At the very beginning of the function, we get the identifier of the current chart using ChartID and then we mark it with an asterisk in the list. At the end, the total number of charts is output.
void OnStart()
|
An example result is shown below.
Chart List
|