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.
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:
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 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:
{
|
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:
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:
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>
|
A file with ticks should have the following format: Date Time Bid Ask Last Volume. For example:
<DATE> <TIME> <BID> <ASK> <LAST> <VOLUME>
|
Do not pass tick flags, as the terminal calculates them during import.
You can use data from any existing instrument for your custom symbol. Export data, modify it if necessary, and import the data back.
|
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 |
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.
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:
|
To save the changes, click "Apply Changes" at the bottom of the window.
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.
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:
For financial instruments with other margin calculation types (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 trading platform allows creating synthetic financial instruments, i.e. symbols based on one or more existing instruments. The user should set the formula for calculating quotes, after which the platform will generate ticks of the synthetic instrument in real time, and also will create its minute history.
For example, you can create an instrument showing the dollar index (USDX). It uses the below formula:
50.14348112*pow(ask(EURUSD),-0.576)*pow(USDJPY,0.136)*pow(ask(GBPUSD),-0.119)*pow(USDCAD,0.091)*pow(USDSEK,0.042)*pow(USDCHF,0.036) |
---|
The platform will calculate in real time the price of the new instrument based on the quotes of the other six symbols provided by your broker. The price changes will be visualized in the Market Watch window and on the chart:
Create a new custom symbol, open its specification and specify the formula:
Calculation of ticks and 1-minute bars of a synthetic instrument starts when this instrument is added to the Market Watch. Also, all symbols required for the synthetic price calculation are automatically added to the Market Watch. An entry about the calculation start will be added to the platform log: Synthetic Symbol USDX: processing started.
|
Every 100 ms (i.e. ten times per second) the prices of the symbols used in calculation are checked. If at least one of them has changed, the price of the synthetic symbol is calculated and a new tick is generated. Calculation is performed in parallel in three threads for Bid, Ask and Last prices. For example, if the calculation formula is EURUSD*GBPUSD, the price of the synthetic symbol will be calculated as follows:
The availability of changes is checked separately for each price. For example, if only the Bid price of a source instrument has changed, only the appropriate price of a synthetic instrument will be calculated.
In addition to collecting ticks in real time, the platform creates a minute history of the synthetic instrument. It enables traders to view synthetic symbol charts similar to normal ones, as well as to conduct technical analysis using objects and indicators.
When a trader adds a synthetic instrument to the Market Watch, the platform checks whether its calculated minute history exists. If it does not exist, the history for the last 60 days will be created, which includes about 50,000 bars. If a lower value is specified in the Max. bars in chart parameter in platform settings, the appropriate limitation will apply. If some of bars within this period were created earlier, the platform will additionally generate new bars.
After creating bars for the last 60 days, the platform will continue to create a deeper history in the background mode. The price history of each symbol used in the synthetic formula can be of different depth. Therefore the calculation is performed for the shortest available period. For example, the formula uses three financial instruments:
In this case, the history of the synthetic symbol will be calculated for a period from 2014.06.01 to the present. 100 minutes will be additionally discarded from this date, to ensure the calculation integrity (if any minute bar is not available in history, a previous minute bar is used in the calculation).
The history of one-minute bars of a synthetic instrument is calculated based one one-minute bars (not ticks) of instruments used in its formula. For example, to calculate the Open price of a 1-minute bar of a synthetic symbol, the platform uses the Open prices of symbols used in its formula. High, Low and Close prices are calculated in a similar way.
If the required bar is not available for any of the instruments, the platform will use the Close price of the previous bar. For example, three instruments are used: EURUSD, USDJPY and GBPUSD. If in the calculation of a bar corresponding to 12:00 the required bar of USDJPY is not available, the following prices will be used for calculation:
If the minute bar is not available for all instruments used in the formula, the appropriate minute bar of the synthetic instrument will not be calculated.
All new bars (current and subsequent ones) of the synthetic instrument are created based on the generated ticks. The price used for building the bars depends on the "Chart mode" parameter in the specification:
Price data and some properties of existing symbols provided by the broker can be used for calculating synthetic prices. Specify the following:
If a symbol has a complex name (contains hyphens, dots, etc.), it must be written in quotation marks. Example: "RTS-6.17". |
The following arithmetic operations can be used in the formula: addition (+), subtraction (-), multiplication (*), division (/) and remainder of division (%). For example, EURUSD+GBPUSD means that the price is calculated as the sum of EURUSD and GBPUSD prices. Also you can use the unary minus to change the sign, for example: -10*EURUSD.
Mind the calculation priority of arithmetic operations:
You can use constants in the formula:
You can also use in the formula all mathematical functions supported in MQL5, except for MathSrand, MathRand and MathIsValidNuber:
Function |
Description |
---|---|
fabs(number) |
Returns an absolute value (modulo value) of the number passed to the function. |
acos(number) |
Returns the arc cosine of the number in radians |
asin(number) |
Returns the arcsine of the number in radians |
atan(number) |
Returns the arc tangent of the number in radians |
ceil(number) |
Returns the nearest upper integer |
cos(number) |
Returns the cosine of the number |
exp(number) |
Returns the exponent of the number |
floor(number) |
Returns the nearest lower integer |
log(number) |
Returns the natural logarithm |
log10(number) |
Returns the logarithm of a number by base 10 |
fmax(number1, number2) |
Returns the highest of two numeric values |
fmin(number1, number2) |
Returns the lowest of two numeric values |
fmod(dividend, divisor) |
Returns the real remainder of the division of two numbers |
pow(base, power) |
Raises the base to the specified power |
round(number) |
Rounds the number to the nearest integer |
sin(number) |
Returns the sine of the number |
sqrt(number) |
Returns the square root |
tan(number) |
Returns the tangent of the number |
expm1(number) |
Returns the value of the expression exp(number)-1 |
log1p(number) |
Returns the value of the expression log(1+number) |
acosh(number) |
Returns the value of the hyperbolic arc cosine |
asinh(number) |
Returns the value of the hyperbolic arcsine |
atanh(number) |
Returns the value of the hyperbolic arc tangent |
cosh(number) |
Returns the value of the hyperbolic cosine |
sinh(number) |
Returns the value of the hyperbolic sine |
tanh(number) |
Returns the value of the hyperbolic tangent |