- 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 symbol and timeframe of an arbitrary chart
Two fundamental properties of any chart are its working symbol and timeframe. As we saw earlier, these properties for the current chart are available as built-in variables _Symbol and _Period, as well as through the relevant functions Symbol and Period. The following functions can be used to determine the same properties for other charts: ChartSymbol and ChartPeriod.
string ChartSymbol(long chartId = 0)
The function returns the name of the symbol of the chart with the specified identifier. If the parameter is 0, the current chart is assumed.
If the chart does not exist, an empty string ("") is returned and _LastError sets error code ERR_CHART_WRONG_ID (4101).
ENUM_TIMEFRAMES ChartPeriod(long chartId = 0)
The function returns the period value for the chart with the specified identifier.
If the chart does not exist, 0 is returned.
The script ChartList2.mq5, similar to ChartList1.mq5, generates a list of charts indicating the symbol and timeframe.
#include <MQL5Book/Periods.mqh>
|
Here is an example of the log content after running the script on the EURUSD, H1 chart (on the second line).
Chart List
|
MQL5 allows not only to identify but also to switch the symbol and timeframe of any chart.