Applies a specific template from a specified file to the chart. The command is added to chart message queue and executed only after all previous commands have been processed.
[in] Chart ID. 0 means the current chart.
[in] The name of the file containing the template.
The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to.
Live Trading and DLL Imports
Users can allow or forbid the following actions for an mql4 program launched on a chart:
The terminal allows saving the configured chart as a template with all indicators and Expert Advisors launched on it. Thus, it is possible to quickly apply template settings to all other charts. When saving the template, permissions of the launched programs (live trading and DLL imports) are also saved. When applying the template to the chart, these permissions may be limited due to security reasons:
If the mql4 program calling ChartApplyTemplate() function has no permission to trade, the Expert Advisor launched via the template will also not be able to trade regardless of the template settings.
If the mql4 program calling ChartApplyTemplate() function has permission to trade, while there is no such permission in the template settings, the Expert Advisor launched via the template will not be able to trade.
The resources of the MQL4 language allow setting multiple chart properties, including colors using the ChartSetInteger() function:
Besides, there can be multiple graphical objects and indicators on a chart. You may set up a chart with all the necessary indicators once and then save it as a template. Such a template can be applied to any chart.
The ChartApplyTemplate() function is intended for using a previously saved template, and it can be used in any mql4 program. The path to the file that stores the template is passed as the second parameter to ChartApplyTemplate(). The template file is searched according to the following rules:
Here terminal_directory is the folder from which the MetaTrader 4 Client Terminal is running, and terminal_data_directory is the folder, in which editable files are stored, its location depends on the operating system, user name and computer's security settings. Normally they are different folders, but in some cases they may coincide.
The location of folders terminal_data_directory and terminal_directory can be obtained using the TerminalInfoString() function.
Templates are not resources, they cannot be included into an executable EX4 file.