Download MetaTrader 5

Creating and testing custom symbols in MetaTrader 5

21 September 2017, 12:52
MetaQuotes Software Corp.
0
9 442

Custom symbols in MetaTrader 5 offer new opportunities for developing trading systems and analyzing any financial markets. Now traders are able to plot charts and test trading strategies on an unlimited number of financial instruments. To do this, they only need to create their custom symbol based on a tick or minute history. Custom symbols can be used to test any trading robot from the Market or the free source code library.


Creating a custom symbol

Let's create a custom symbol based on the one already present in the Market Watch. Open the Symbols window by the right mouse button and select the one you would like to use to create a custom symbol.


After clicking "Create Custom Symbol", set its name and change the required parameters in the contract specification if necessary.


All custom symbols are placed to the separate <Custom> directory of the Symbols tree and are always located there regardless of a broker you are currently connected to. Price data of custom symbols are saved in a separate Custom directory outside of the directories where data of trade servers are stored:

C:\Users\[windows account]\AppData\Roaming\MetaQuotes\Terminal\[instance id]\bases\Custom

This is another advantage of creating a custom symbol — you can simply copy the necessary symbols from each broker to your custom group. Just like conventional symbols, you can delete a custom symbol only if there are no open charts with it and it is not present in the Market Watch.


Configuring a custom symbol

You are able to set the quotes accuracy, contract size, symbol currency, settlement method and all other parameters affecting test results of a trading strategy involving the custom symbol.



Importing history

After creating a custom symbol, we need to add a quote history for it. First, let's see how to create a history based on an already existing symbol. On the Symbols window, open the Bars or Ticks tab depending on how you want to prepare the history. Make a request for a desired period and perform export.  To receive bars, select the M1 timeframe, since the entire history in MetaTrader 5 is based on minute data.


The export is done in the form of a text CSV file with the name having the following look: EURUSD_M1_201701020000_201707251825.csv, which contains the symbol name, timeframe and the time boundaries of the exported history up to a minute. Below is how the format looks when exporting bars:

<DATE>	        <TIME>	        <OPEN>	<HIGH>	<LOW>	<CLOSE>	<TICKVOL><VOL>	     <SPREAD>
2017.01.02	00:03:00	1.05141	1.05141	1.05141	1.05141	6	15000000	118
2017.01.02	00:04:00	1.05141	1.05141	1.05141	1.05141	2	5000000	        112
2017.01.02	00:05:00	1.05158	1.05158	1.05148	1.05158	10	17000000	101
2017.01.02	00:06:00	1.05148	1.05158	1.05148	1.05158	7	13000000	101

When exporting a tick history, the CSV file becomes much larger, and its format receives data on each tick up to milliseconds. Using these data, the terminal forms a one-minute history all other timeframes are to be based on.

<DATE>          <TIME>          <BID>   <ASK>   <LAST>  <VOLUME>
2017.07.03      00:03:47.212    1.14175 1.14210 0.00000 0       
2017.07.03      00:03:47.212    1.14168 1.14206 0.00000 0       
2017.07.03      00:03:47.717    1.14175 1.14206 0.00000 0       
2017.07.03      00:03:54.241    1.14175 1.14205 0.00000 0       
2017.07.03      00:03:57.982    1.14165 1.14201 0.00000 0       
2017.07.03      00:04:07.795    1.14175 1.14201 0.00000 0       
2017.07.03      00:04:55.432    1.14164 1.14200 0.00000 0       
2017.07.03      00:14:33.743    1.14173 1.14203 0.00000 0       
2017.07.03      00:14:33.743    1.14173 1.14201 0.00000 0       
2017.07.03      00:16:44.901    1.14174 1.14195 0.00000 0       

Therefore, if you form a history for your custom symbol using any third-party sources, you need to prepare the data in accordance with the formats displayed above.

To import the history, perform the similar steps. Find your EURUSD_my custom symbol in the Custom\<Custom group> folder, go to the Ticks tab, select the necessary CSV file and click "Import Ticks" (do the same to import bars).


After importing the history, you can edit it by adding, deleting or changing any bars and ticks.

Created custom symbols become available in the Market Watch, and you can open charts for them. Thus, custom symbols allow you to apply the entire rich arsenal of the MetaTrader 5 technical analysis, including the launch of any custom indicators and analytical tools from the Market.


Testing trading strategies on a custom symbol

The multi-threaded MetaTrader 5 strategy tester allows you to test strategies trading on multiple financial instruments on real ticks. Use all its advantages to test strategies on custom symbols. To do this, import a high-quality minute (preferably tick) history and set the properties for each instrument necessary for a detailed reconstruction of the trading environment. After that, select the necessary EA and set the test settings. The entire process is similar to working with conventional trading symbols provided by your broker.


Provide the tester with all the necessary symbols you may need to calculate margin requirements and profit in your trading account currency. When calculating the margin and profit, the strategy tester automatically uses available cross rates. Suppose that we have created AUDCAD.custom symbol with the Forex type of margin calculation, and our account currency is USD. In this case, the tester searches for the necessary symbols in the following order based on the Forex symbol name:

  1. first, the search is performed for the symbols of AUDUSD.custom (for calculating the margin) and USDCAD.custom (for calculating the trade profit) forms
  2. if any of these symbols is not present, the search is performed for the first symbol corresponding to the necessary currency pairs by name (AUDUSD and USDCAD respectively). For example, AUDUSD.b and USDCAD.b symbols have been found. This means their rates are to be used to calculate the margin and profit.
Instruments with other types of margin calculation (CFD, Futures and Stock Exchange) require a currency pair to convert the instrument currency into a deposit one. Suppose that we have created a custom symbol with profit and margin currency expressed in GBP, while the deposit currency is CHF. In this case, the search for testing symbols is performed in the following order:
  1. The presence of a trading symbol corresponding to GBPCHF (GBP vs CHF) is checked.
  2. If no such symbol exists, the search is performed for the first trading symbol that corresponds to GBPCHF by its name, for example GBPCHF.b or GBPCHF.def.

When testing using custom symbols, make sure that the trading account has all the necessary currency pairs. Otherwise, the calculation of financial results and margin requirements during testing will not be possible.


Optimizing strategies on a custom symbol in a local network

Apart from your own agents, you are able to use agents from a local network and remote agents to optimize trading strategies on custom symbols. This is yet another advantage of the MetaTrader 5 strategy tester allowing you to shorten the time spent searching for optimal parameters of your trading system.

The use of MQL5 Cloud Network for optimization using custom symbols is not allowed. This is due to the fact that custom symbols with the same names, but different price histories may exist on computers of different traders. In addition to the discrepancy of test results between network agents, this may cause mass reloading and synchronization of history data, which leads to excessive internet usage.


Functions for working with custom symbols

You can also work with custom symbols using MQL5 language. The functions from the "Custom symbols" section are designed for that. An MQL5 application allows you to quickly create necessary financial instruments with specified properties based on data from third-party sources. Thus, you can automate collecting and preparing history data for any symbols, as well as create your custom indices and other derivatives and test them in the MetaTrader 5 strategy tester.

Function

Action

CustomSymbolCreate

Create a custom symbol with the specified name in the specified group

CustomSymbolDelete

Delete a custom symbol with the specified name

CustomSymbolSetInteger

Set the integer type property value for a custom symbol

CustomSymbolSetDouble

Set the real type property value for a custom symbol

CustomSymbolSetString

Set the string type property value for a custom symbol

CustomSymbolSetMarginRate

Set the margin rates depending on the order type and direction for a custom symbol

CustomSymbolSetSessionQuote

Set the start and end time of the specified quotation session for the specified symbol and week day

CustomSymbolSetSessionTrade

Set the start and end time of the specified trading session for the specified symbol and week day

CustomRatesDelete

Delete all bars from the price history of the custom symbol in the specified time interval

CustomRatesReplace

Fully replace the price history of the custom symbol within the specified time interval with the data from the MqlRates type array

CustomRatesUpdate

Add missing bars to the custom symbol history and replace existing data with the ones from the MqlRates type array

CustomTicksDelete

Delete all ticks from the price history of the custom symbol in the specified time interval

CustomTicksReplace

Fully replace the price history of the custom symbol within the specified time interval with the data from the MqlTick type array

These functions complement the capabilities of the "Getting Market Information" section. Now, you can not only obtain properties of any symbols but also set them for custom instruments.


Test your trading ideas on any symbols in MetaTrader 5!

The MetaTrader 5 platform offers the widest opportunities for algorithmic traders. Here are just a few of them:

Traders have access to all the advantages of the MetaTrader 5 platform even on the symbols their brokers do not have yet. Create your own symbols and test trading strategies in any financial market!

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/3540

Deep Neural Networks (Part II). Working out and selecting predictors Deep Neural Networks (Part II). Working out and selecting predictors

The second article of the series about deep neural networks will consider the transformation and choice of predictors during the process of preparing data for training a model.

The Flag Pattern The Flag Pattern

The article provides the analysis of the following patterns: Flag, Pennant, Wedge, Rectangle, Contracting Triangle, Expanding Triangle. In addition to analyzing their similarities and differences, we will create indicators for detecting these patterns on the chart, as well as a tester indicator for the fast evaluation of their effectiveness.

Graphical Interfaces XI: Text edit boxes and Combo boxes in table cells (build 15) Graphical Interfaces XI: Text edit boxes and Combo boxes in table cells (build 15)

In this update of the library, the Table control (the CTable class) will be supplemented with new options. The lineup of controls in the table cells is expanded, this time adding text edit boxes and combo boxes. As an addition, this update also introduces the ability to resize the window of an MQL application during its runtime.

Using cloud storage services for data exchange between terminals Using cloud storage services for data exchange between terminals

Cloud technologies are becoming more popular. Nowadays, we can choose between paid and free storage services. Is it possible to use them in trading? This article proposes a technology for exchanging data between terminals using cloud storage services.