- 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
Switching symbol and timeframe
Sometimes an MQL program needs to switch the current symbol or timeframe of a chart. In particular, this is a familiar functionality for many multicurrency, multitimeframe trading panels or trading history analyzing utilities. For this purpose, the MQL5 API provides the ChartSetSymbolPeriod function.
You can also use this function to initiate the recalculation of the entire chart, including the indicators located on it. You can simply specify the current symbol and timeframe as parameters. This technique can be useful for indicators that could not be fully calculated on the first call of OnCalculate, and wait for the loading of third-party data (other symbols, ticks, or indicators). Also, changing the symbol/timeframe leads to the reinitialization of the Expert Advisors attached to the chart. The script (if it is executed periodically in a cycle) will completely disappear from the chart during this procedure (it will be unloaded from the old symbol/timeframe combination but will not be loaded automatically for the new combination).
bool ChartSetSymbolPeriod(long chartId, string symbol, ENUM_TIMEFRAMES timeframe)
The function changes the symbol and timeframe of the specified chart with the chartId identifier to the values of the corresponding parameters: symbol and timeframe. 0 in the chartId parameter means the current chart, NULL in the symbol parameter is the current character, and 0 in the timeframe parameter is the current timeframe.
Changes take effect asynchronously, that is, the function only sends a command to the terminal and does not wait for its execution. The command is added to the chart's message queue and is executed only after all previous commands have been processed.
The function returns true in case of successful placement of the command in the chart queue or false in case of problems. Information about the error can be found in _LastError.
We have seen examples of using the function to update several indicators, in particular:
- IndDeltaVolume.mq5 (see Waiting for data and managing visibility)
- IndUnityPercent.mq5 (see Multicurrency and multitimeframe indicators)
- UseWPRMTF.mq5 (see Support for multiple symbols and timeframes)
- UseM1MA.mq5 (see Using built-in indicators)
- UseDemoAllLoop.mq5 (see Deleting indicator instances)
- IndSubChart.mq5 (see Chart display modes)