Custom Financial Instruments
The trading platform allows creating custom financial symbols. You can view charts of such symbols and perform technical analysis, as well as use them for testing trading robots and indicators in the Strategy Tester.
If your broker does not provide the instrument, on which you want to test your strategy, or the provided history depth and the quality of price history is not enough, you can create a custom symbol and upload required data to it.
How to Create and Configure a Custom Symbol
Open the symbol management window using the context menu of the "Market Watch" window and click on "Create Custom Symbol":
For a custom symbol, you can configure some parameters from the specification of trading instruments, as well as some additional parameters:
- Basis — the name of the underlaying asset for the custom symbol. For example, gold is the underlying asset for futures contracts.
- Page — the web page containing symbol information. It will be displayed as a link when viewing symbol properties in the Market Watch window.
- Chart mode — the price used for creating the symbol chart, Bid or Last.
- Background — the background color for the symbol in the Market Watch window.
- Calculate hedged margin using larger leg — this mode is only used on hedging accounts, where opposite positions of the same symbol can exist simultaneously. Symbol margin can be calculated using the margin of a short side (all sell positions and pending orders) and of a long side (all buy positions and sending orders). The largest one of the calculated values is used as the final margin value.
- Time limits use — by setting "Yes", you can specify the first and the last day of the symbol trading period (circulation period).
In addition to the above parameters, you can configure trading and quoting sessions for the symbol. Sessions are configured separately for each day. Double-click on a day to edit it.
Set the desired sessions using sliders. Expert Advisors will not be able to trade in the Strategy Tester in non-session hours.
Trading sessions are not specified by default, and coincide with quoting sessions. If you need to configure the time of quoting and trading sessions separately, enable the option "Enable separate trading sessions". Each trading session must be within a quoting session.
- You can quickly configure your custom symbol by copying parameters of any similar instrument and modifying them. Select an existing symbol in the "Copy from" field.
- The name of the custom symbol must not match the names of symbols provided by the brokers. If you connect to the server, on which a symbol with the same name exists, the custom symbol will be deleted.
- The symbol name may only contain Latin letters without punctuation, spaces or special characters (may only contain ".", "_", "&" and "#"). It is not recommended to use characters <, >, :, ", /, |, ?, *.
Import and Export of Custom Symbols
You can easily share custom symbols or transfer symbols between your platforms. Parameters of a specific custom symbol can be exported or imported from its settings editing window shown above.
It is also possible to export and import entire groups of symbols:
Settings are exported to JSON text files:
"ConfigSymbols" : [
"Symbol" : "EURUSD_cust",
"Path" : "Custom\\Forex\\EURUSD_cust",
"ISIN" : "",
"Description" : "Euro vs US Dollar",
Managing Custom Symbols
All symbols are displayed in a separate Custom group. If you need to modify or delete a symbol, use the context menu of the list:
Importing the Price History
You can import price data to your custom symbol from any text file, as well as from MetaTrader history files (HST). Choose a symbol and go to the "Bars" or "Ticks" tab.
In the import dialog, specify the path to the file and set the required parameters:
- Separator — separator of items in a text file.
- Skip columns and rows — amount of columns (from left to right) and rows (from top to bottom) to be skipped during an import.
- Shift — time shift by hours. The option is used when importing data saved in a different time zone.
- Use selected only — import only rows highlighted in the row view area. You can highlight rows with your mouse while holding Ctrl or Shift.
A file with 1-minute bars should have the following format: Date Time Open High Low Close TickVolume Volume Spread. For example:
<DATE> <TIME> <OPEN> <HIGH> <LOW> <CLOSE> <TICKVOL><VOL> <SPREAD>
2016.06.27 00:01:00 1.10024 1.10136 1.10024 1.10070 18 54000000 44
2016.06.27 00:02:00 1.10070 1.10165 1.10070 1.10165 32 55575000 46
2016.06.27 00:03:00 1.10166 1.10166 1.10136 1.10163 13 13000000 46
2016.06.27 00:04:00 1.10163 1.10204 1.10155 1.10160 23 51000000 41
A file with ticks should have the following format: Date Time Bid Ask Last Volume. For example:
<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
You can use data from any existing instrument for your custom symbol. Export data, modify it if necessary, and import the data back.
- The price history is stored in the form of one-minute bars. All other timeframes are created based on these bars. You can also import data of higher timeframes, but charts on lower timeframes will have gaps in this case. For example, if you import one-hour data, one bar per hour will be shown on the M1 chart.
- During import, the time interval is completely replaced by data from the specified file. For example, if the file contains data from 2016.01.01 00:00:00 to 2016.06.01 00:00:00, and the custom symbol history already has some data in this interval, these data will be completely replaced with new ones (even if the amount of imported data is less than data in the history).
- When importing bars, the presence of duplicate entries in the imported file (bars with the same time) is considered to be an error. In the platform, only one bar can correspond to one minute. When importing ticks, several ticks can have fully identical parameters.
- Values set to less than or equal to zero are not imported.
- During import, the user must provide the correct order of ticks in the file, i.e. from earlier to ticks to more recent ones.
Price data of custom symbols are saved in a separate Custom directory (not in the directories where data of trade servers are stored):
C:\Users\[windows account]\AppData\Roaming\MetaQuotes\Terminal\[instance id]\bases\Custom
Editing the Price History
You can edit the history of bars and ticks of custom symbols manually. To do this, request the required data interval in the "Bars" or "Ticks" tab.
- Double-tap to change the value.
- Use the context menu to add or delete entries
- If you need to delete multiple bars/ticks at once, select them with the mouse, holding down Shift or Ctrl+Shift.
When editing bars, it is highly recommended to request data of the M1 timeframe. The price history is stored in the form of one-minute bars in the platform. All other timeframes are created based on these bars. Even if you initially request bars of another timeframe, all changes will be applied to the corresponding 1-minute bars. For example, if you request data of the M5 timeframe and edit a bar, five 1-minute bars will be replaced by one 1-minute bar (corresponding to the beginning of the M5 bar). It means that the edited interval will be completely replaced.
For convenience, modified entries are highlighted as follows:
- Red background means that the entry is incorrect (for example, the high price is less than the low price)
- Green background indicates a correct modified entry
- Gray background means a deleted entry
- Yellow background shows an added entry
- When adding a new bar, the first unoccupied date/time from the current data selection is automatically inserted in the "Date" column.
- The platform does not allow creating bars with the same date/time. Only one bar can correspond to one minute.
To save the changes, click "Apply Changes" at the bottom of the window.
Use of Custom Financial Instruments
Use of custom symbols is similar to the use of instruments provided by the broker. Custom symbols are displayed in the Market Watch window; you can open charts of such symbols and apply indicators and analytical objects on them.
Testing Using Custom Financial Instruments
Real trades cannot be executed on custom symbols, but they can be used for testing trading robots and indicators in the Strategy Tester. Select a custom symbol and launch testing:
When calculating the margin and profit of trades executed during testing, the Strategy Tester can automatically use cross rates available on the account. For example, if the profit currency is EUR and the account currency is USD, the tester will convert it according to the corresponding EURUSD rates.
Most often, custom symbol names include various suffixes, such as EURUSD.1 or EURUSD.f. Therefore, the strategy tester uses a special mechanism to search for suitable cross rates for recalculation.
For example, we have created a custom symbol AUDCAD.custom with the margin calculation type Forex, and the currency of our account is USD. Based on the name of the Forex instrument, the tester searches for the required symbols in the following order:
- First, the tester searches for symbols such as AUDUSD.custom (for margin calculation) and USDCAD.custom (for profit calculation).
- If any of these symbols is not found, the tester searches for the first symbol, whose name corresponds to the required currency pairs, i.e. AUDUSD and USDCAD. If it finds for example AUDUSD.b and USDCAD.b, the rates of these symbols will be used for margin and profit calculation.
For financial instruments with other margin calculation types (CFD, Futures, Stock Exchange), a currency pair is needed for converting the instrument currency into deposit currency. For example, we have created a custom symbol with the British pound (GBP) set for the profit and margin currency, and the Swiss franc (CHF) used as the deposit currency. In this case, symbols for testing are searched in the following order:
- The availability of a trading instrument corresponding to GBPCHF (GBP vs CHF) is checked.
- If this symbol is not available, the tester will search for the first trading instrument corresponding to the GBPCHF currency pair, such as GBPCHF.b or GBPCHF.def.
- When testing applications using custom instruments, make sure that the account has all the necessary currency pairs. Otherwise, the calculation of financial results and margin requirements during testing will not be possible.
- 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 can 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. Using local network agents and remote agents is allowed.