Templates

Hi folks,

You have loaded your favorite indicators on the chart, set the favorite colors for the background and the bars, you have drawn your study lines and you've loaded your best expert advisor.
Tomorrow you don't want to repeat all these steps again and spend your valuable time arranging the chart from scratch for every work day.
Is there a solution to save the chart layout and apply it when you want? Yes! The solution is the Templates.

Note: Templates in MetaTrader terminal is something very different of templates in MQL4.  I've started with this note because you will find another article in the development section with the same name and maybe you think we are talking about the same thing.


What are the templates anyway?

The templates are files (.tpl) saved in MetaTrader 4\templates path which MetaTrader uses it to save the chart settings of the current chart which you can apply to other charts.


Which data you can store in the template file?

In the template file you can store all the chart properties except the currency pair and the period of the chart.

These are some of the properties you store in (and restore from) the template file:

The colors of the chart (Background, Foreground, Grid, Bars, Candles, Ask Line etc);
The chart scale;
The property of the OHLC (Open High Low Close) line;
The loaded expert advisor and its settings;
The loaded indicators and their settings;
The line studies;
The period separator.


A template file – Inside look:

If you navigate to MetaTrader 4\Templates path, you will find a set of templates files shipped with MetaTrader and installed in the first time you install the terminal.
We will open one of them in any text editor to give the content of it a look. Let’s look inside the ADX.tpl file.
This is the content of the ADX.tpl file:

 

<chart> symbol=GBPUSD period=30 leftpos=37  digits=4 scale=8 graph=1 fore=1 grid=1 volume=0 scroll=1 shift=1 ohlc=1 askline=0 days=1 descriptions=0 shift_size=20 fixed_pos=0 window_left=307 window_top=0 window_right=614 window_bottom=159 window_type=1 background_color=0 foreground_color=16777215 barup_color=65280 bardown_color=65280 bullcandle_color=0 bearcandle_color=16777215 chartline_color=65280 volumes_color=3329330 grid_color=10061943 askline_color=255  stops_color=255  <window> height=151 <indicator> name=main </indicator> <indicator> name=Moving Average period=21 shift=0 method=0 apply=0 color=65535 style=0 weight=1 period_flags=0 show_data=1 </indicator> </window>  <window> height=50 <indicator> name=Average Directional Movement Index period=14 apply=0 color=11119017  style=0 weight=1 color2=64636 style2=0 weight2=1 color3=255 style3=0 weight3=1 period_flags=0 show_data=1 </indicator> </window></chart>
The template file starts with tags very like the Html and XML tags.
There is a start tag and a closing tag. The closing tag uses a slash after the opening
bracket. For example <chart> is the start tag and </chart> is the closing tag.
The text between the brackets is called an element. For example:

symbol=GBPUSD
period=30
leftpos=37
digits=4

 Note: We can not explain in details the elements of the template files, and I think they are self- explicit.


These are the most used template tags:

<chart>..</chart>
Between those tags we set the properties of the chart. For example here we can set the background color of the chart, the foreground color, show/hide OHLC line, the number of digits for the currency used in the chart etc.

<window>..</window>
Between those tags you set the windows properties and the indicators, expert advisors or the objects that placed on the window.
There are two kinds of windows you can set in MetaTrader: The main window and the separate windows.

 Note: these tags are belonging to the <window>..</ window > tags:
<indicators>..</indicators>, <expert>..</ expert > and <object>..</object>.

Belonging to the <window> tags means you must write them inside the tag because they have to belong to a specified window.

<indicator>..</indicator>
Between those tags can set the indicators belong to a specified window and its parameters.

<expert>..</ expert >
Between those tags can set the expert advisors belong to a specified window, to set the inputs of these expert advisor you have to use the <inputs>..</inputs> tags.

<inputs>../<inputs>
These tags belonging to the <expert>..<expert> tags and between them you can set the inputs for the expert advisor like the TakeProfit and Lots etc.

<object>../<object>
Between those tags can set the properties of the objects belong to a specified window.


Loading the template:

When you load the template file on the current active chart you apply all the setting stored in the template file to the chart including the stored indicators with their settings, the expert advisors with their inputs and the objects with their properties.
To load a template click the right mouse button on the chart to bring the context menu (Figure 1) and click the Template menu and from the menu choose Load template command. That will bring the Open window to choose the template you want to load.
Or you will find the list of templates saved in the templates path showed in the context menu.



Figure 1 - Loading a template
Saving settings to a template file:

If you are interested of the setting of the chart and the loaded indicators or expert advisor, you can save these settings in a template file and restore them later.
To save to a template click the right mouse button on the chart to bring the context menu (Figure 2) and click the Template menu and from the menu choose Save template command. That will bring the Save As window to choose the template you want to overwrite or a new name for your new template file.



Figure 2 - Saving a template

Removing a template file:

You can remove any saved template by clicking the right mouse button on the chart to bring the context menu (Figure 3) and click the Template menu and from the menu click Remove template menu which bring a list of already saved templates to choose from them the template you want to remove.



Figure 3 - Removing a template

Note: the "DEFAULT.TPL" template cannot be removed.


Note: You can access all the commands of loading, saving and removing the templates files from the toolbar from the Templates icon (Figure 6).

 



Figure 4 - Templates icon in the toolbar
I hope you enjoyed the article.
Coders Guru