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.
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:
- first, the search is performed for the symbols of AUDUSD.custom (for calculating the margin) and USDCAD.custom (for calculating the trade profit) forms
- 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.
- The presence of a trading symbol corresponding to GBPCHF (GBP vs CHF) is checked.
- 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.
Create a custom symbol with the specified name in the specified group
Delete a custom symbol with the specified name
Set the integer type property value for a custom symbol
Set the real type property value for a custom symbol
Set the string type property value for a custom symbol
Set the margin rates depending on the order type and direction for a custom symbol
Set the start and end time of the specified quotation session for the specified symbol and week day
Set the start and end time of the specified trading session for the specified symbol and week day
Delete all bars from the price history of the custom symbol in the specified time interval
Fully replace the price history of the custom symbol within the specified time interval with the data from the MqlRates type array
Add missing bars to the custom symbol history and replace existing data with the ones from the MqlRates type array
Delete all ticks from the price history of the custom symbol in the specified time interval
Fully replace the price history of the custom symbol within the specified time interval with the data from the MqlTick type array
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:
- 84 built-in technical analysis tools,
- multi-threaded strategy tester with 20 000 agents from MQL5 Cloud Network,
- asynchronous trading operations within one (!) millisecond for execution,
- 4000 free examples in source codes,
- MetaEditor with debugging and profiling.
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