Why Chart Templates Matter
Every MetaTrader user has a preferred chart setup: a specific combination of indicators, timeframes, colors, grid settings, and object drawings. Without templates, you would manually recreate that setup on every new chart window. Chart templates let you save your entire visual configuration into a single .tpl file and apply it instantly to any symbol or timeframe. This is especially critical for traders who monitor multiple instruments or switch between strategies frequently.
This guide covers the complete workflow: saving templates, loading them, managing the template library, transferring templates between MT4 and MT5, and even applying templates programmatically from an MQL Expert Advisor or script. By the end, you'll have a professional-grade system for maintaining consistent chart setups across all your trading screens.
Prerequisites
- A running MetaTrader 4 or MetaTrader 5 platform (any build, though Windows is recommended for full file access)
- At least one chart window open with your preferred indicators and settings
- File Explorer access (to locate the
templatesfolder) - (Optional) MetaEditor for the MQL code section
Note: On macOS via Wine or virtual machines, the file paths may differ. Use the platform's File → Open Data Folder to locate the correct directory.
Step-by-Step: Saving a Chart Template
- Set up your chart exactly as you want it. Attach indicators (e.g., Moving Average, RSI, Bollinger Bands), adjust colors (background, candle bull/bear, grid), set grid and candle styles (e.g., bar, candlestick, line), add trendlines or horizontal lines, and configure any chart properties (e.g., show ask line, volume histogram).
- Right-click anywhere on the chart background (not on an indicator or object). If you click on an indicator, you'll open its properties instead of the chart context menu.
- Hover over Template in the context menu.
- Click Save Template.
- Enter a descriptive name (e.g.,
Forex_Daily_MA_RSI) and click Save. Avoid special characters like slashes or colons; stick to alphanumeric and underscores.
The template is now stored in the templates subfolder of your MetaTrader data directory. On Windows, the default path is:
%APPDATA%\MetaQuotes\Terminal\[INSTANCE_ID]\templates\
For MT4, it may be:
%APPDATA%\MetaQuotes\Terminal\[INSTANCE_ID]\MQL4\Profiles\Templates\
To find your exact data folder: open MetaTrader, go to File → Open Data Folder (both MT4 and MT5). The [INSTANCE_ID] is a long alphanumeric string unique to your installation. If you have multiple MetaTrader instances, each has its own folder.
Step-by-Step: Loading a Chart Template
- Open a new chart or select an existing chart window by clicking on it.
- Right-click on the chart background.
- Hover over Template.
- Select the desired template from the list. The chart will immediately update, applying all saved indicators, colors, and objects.
You can also load a template by dragging a .tpl file from Windows File Explorer directly onto a chart window. This is especially fast when you have many templates open in Explorer. If the template doesn't apply, check that the file is a valid .tpl and not corrupted (e.g., from a partial download).
Keyboard shortcut: There is no native hotkey, but you can assign one via the Tools → Options → Charts tab (MT5) or use a custom script with ChartApplyTemplate().
Managing Your Template Library
Over time, your template folder can grow cluttered. Use these practices to stay organized:
- Use descriptive filenames that include the strategy name, timeframe, or symbol, e.g.,
Scalping_M1_Bollinger.tpl,Breakout_H4_MA.tpl. - Delete unused templates directly in the
templatesfolder via File Explorer. MetaTrader will reflect the changes after restart or refresh (close and reopen the Template menu). - Back up your templates by copying the entire
templatesfolder. This is essential before reinstalling, upgrading to a new build, or migrating to a new PC. Store the backup on cloud storage (e.g., Google Drive, Dropbox) or an external drive. - Transfer between MT4 and MT5: While the
.tplfile format is similar, indicator references are platform-specific. A template saved in MT4 will not load correctly in MT5 if it uses MQL4-only indicators (e.g., custom indicators compiled as.ex4files). Strip platform-specific indicators first, or rebuild the template manually on the target platform. For standard indicators (e.g., Moving Average, Stochastic), they often work across platforms, but test thoroughly. - Version control: If you update indicators frequently, save templates with version numbers (e.g.,
MyStrategy_v2.tpl) to track changes.
Organizing Templates into Subfolders
MetaTrader does not natively support subfolders in the templates directory, but you can create them manually in Windows Explorer. For example:
templates\
├── Scalping\
│ ├── M1_Bollinger.tpl
│ └── M1_Renko.tpl
├── Swing\
│ ├── H4_MA_RSI.tpl
│ └── Daily_Trend.tpl
└── Base\
└── Clean_Setup.tpl
After creating subfolders, restart MetaTrader. The templates will appear in the context menu under their subfolder names (e.g., Template → Scalping → M1_Bollinger). This works in both MT4 and MT5.
Using Templates with MQL Code
You can apply a template programmatically from an Expert Advisor or script. This is useful when you want to switch chart setups automatically based on market conditions (e.g., volatility changes), time of day (e.g., session-based templates), or symbol-specific settings.
In MQL4 and MQL5, the function is:
bool ChartApplyTemplate(
long chart_id, // 0 = current chart
string filename // template name without path
);
The function returns true on success and false on failure. Use GetLastError() to diagnose errors (e.g., ERR_FILE_NOT_FOUND, ERR_INTERNAL_ERROR).
Example: Load a Template on the Current Chart
// MQL4 / MQL5
if (ChartApplyTemplate(0, "Evening_Scalp.tpl"))
{
Print("Template applied successfully.");
}
else
{
Print("Failed to apply template. Error: ", GetLastError());
}
Example: Cycle Through Templates Based on Time
// MQL4 / MQL5
void OnTick()
{
int hour = Hour();
if (hour >= 8 && hour < 16)
{
ChartApplyTemplate(0, "Day_Trading.tpl");
}
else if (hour >= 16 || hour < 8)
{
ChartApplyTemplate(0, "Evening_Scalp.tpl");
}
}
Applying Templates to Multiple Charts
To apply a template to all open charts, iterate through chart IDs using ChartFirst() and ChartNext():
// MQL5 only (MQL4 does not have ChartFirst/ChartNext)
long chartID = ChartFirst();
while (chartID != -1)
{
ChartApplyTemplate(chartID, "Standard_Setup.tpl");
chartID = ChartNext(chartID);
}
In MQL4, you can use WindowHandle() with symbol and timeframe, but it's more limited. For MT4, consider using a script that loops through symbols and timeframes.
Tips and Best Practices
- Save templates after any indicator change. If you tweak an indicator's parameters or add a new one, re-save the template to overwrite the old version. Otherwise, the template will retain outdated settings.
- Use a "clean" base template with only colors, grid, and candle style (no indicators). Apply this first, then add indicators manually. This prevents indicator conflicts when switching templates, especially if you use different indicator combinations.
- Template names are case-sensitive on some operating systems (e.g., Linux via Wine). Stick to alphanumeric characters and underscores, and avoid spaces (use underscores instead).
- Test templates in the Strategy Tester before live use. The Strategy Tester uses the same
ChartApplyTemplate()function, so you can verify indicator behavior in a controlled environment. Note that some indicators may not render in the tester if they rely on real-time data. - Share templates with team members by sending the
.tplfile. Ensure everyone uses the same indicator versions to avoid "indicator not found" errors. A good practice is to include the indicator.ex4/.ex5files in a shared folder. - Use templates for different chart types: Save separate templates for candlestick, bar, and line charts, as the visual settings differ.
Common Mistakes and Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Template not showing in list | File in wrong folder or corrupt | Verify file is in the correct templates folder. Restart MetaTrader. Check file extension is .tpl (not hidden). |
| "Indicator not found" error | Template references a missing custom indicator | Install the missing indicator in the Indicators folder. Or edit the template in a text editor to remove the missing indicator block (look for <indicator> sections). |
| Template applies but looks wrong | Incompatible indicator version or parameters | Re-save the template after manually adjusting indicators on the target platform. Check that the indicator version matches (e.g., same input parameters). |
| MT4 template won't load in MT5 | Different indicator file formats (.ex4 vs .ex5) | Rebuild the template manually in MT5. Do not attempt direct file transfer for custom indicators. Standard indicators may work. |
| Template loads but chart objects are missing | Objects (lines, text) are stored separately in chart profiles | Save the chart as a profile (File → Profiles → Save As) to include objects. Templates only store indicators and chart settings. |
Advanced: Editing .tpl Files Manually
If you're comfortable with XML-like structures, you can open .tpl files in a text editor (e.g., Notepad++, VS Code) to make bulk changes. The file contains sections for each indicator, chart properties, and color settings. For example, to change the period of a Moving Average across all templates, search for <indicator> blocks with the indicator name and modify the <param> values. Be cautious: one typo can corrupt the file, so always back up before editing.
Summary and Next Steps
Chart templates are one of the most productive features in MetaTrader. They eliminate repetitive manual setup, ensure consistency across your trading screens, and can even be automated via MQL code. Master saving, loading, and organizing your .tpl files, and you will save hours every week.
Next steps:
- Create a "base" template with your preferred color scheme and grid settings, then save variations for different strategies (e.g., trend-following, scalping, breakout).
- Write a simple M
Frequently Asked Questions
Can I use the same template file on MT4 and MT5?
Not directly. While the .tpl file structure is similar, MT4 stores references to .ex4 indicator files, while MT5 uses .ex5 files. You must manually rebuild the template on the target platform.
How do I delete a template I no longer need?
Right-click the chart → Template → Save Template (to see the list), then delete the .tpl file from the templates folder via File Explorer. Restart MetaTrader for the change to take effect.
What happens if I apply a template that references a missing indicator?
MetaTrader will apply the template but skip the missing indicator. You will see a warning in the Experts tab of the Terminal window. The chart will still load with all other settings intact.
Can I apply a template from within an Expert Advisor during backtesting?
Yes. The ChartApplyTemplate() function works in the Strategy Tester. However, the template must exist in the tester's virtual file system, which is the same as your local templates folder.






