- Getting available symbols and Market Watch lists
- Editing the Market Watch list
- Checking if a symbol exists
- Checking the symbol data relevance
- Getting the last tick of a symbol
- Schedules of trading and quoting sessions
- Symbol margin rates
- Overview of functions for getting symbol properties
- Checking symbol status
- Price type for building symbol charts
- Base, quote, and margin currencies of the instrument
- Price representation accuracy and change steps
- Permitted volumes of trading operations
- Trading permission
- Symbol trading conditions and order execution modes
- Margin requirements
- Pending order expiration rules
- Spreads and order distance from the current price
- Getting swap sizes
- Current market information (tick)
- Descriptive symbol properties
- Depth of Market
- Custom symbol properties
- Specific properties (stock exchange, derivatives, bonds)
Getting swap sizes
For the implementation of medium-term and long-term strategies, the swap sizes become important, since they can have a significant, usually negative, impact on the financial result. However, some readers are probably fans of the "Carry Trade" strategy, which was originally built on profiting from positive swaps. MQL5 has several symbol properties that provide access to specification strings that are associated with swaps.
Identifier |
Description |
---|---|
SYMBOL_SWAP_MODE |
Swap calculation model ENUM_SYMBOL_SWAP_MODE |
SYMBOL_SWAP_ROLLOVER3DAYS |
Day of the week for triple swap credit ENUM_DAY_OF_WEEK |
SYMBOL_SWAP_LONG |
Swap size for a long position |
SYMBOL_SWAP_SHORT |
Swap size for a short position |
The ENUM_SYMBOL_SWAP_MODE enumeration contains elements that specify options for units of measure and principles for calculating swaps. As well as SYMBOL_SWAP_ROLLOVER3DAYS, they refer to the integer properties of ENUM_SYMBOL_INFO_INTEGER.
The swap sizes are directly specified in the SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT properties as part of ENUM_SYMBOL_INFO_DOUBLE, that is, of type double.
Following are the elements of ENUM_SYMBOL_SWAP_MODE.
Identifier |
Description |
---|---|
SYMBOL_SWAP_MODE_DISABLED |
no swaps |
SYMBOL_SWAP_MODE_POINTS |
points |
SYMBOL_SWAP_MODE_CURRENCY_SYMBOL |
the base currency of the symbol |
SYMBOL_SWAP_MODE_CURRENCY_MARGIN |
symbol margin currency |
SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT |
deposit currency |
SYMBOL_SWAP_MODE_INTEREST_CURRENT |
annual percentage of the price of the instrument at the time of swap calculation |
SYMBOL_SWAP_MODE_INTEREST_OPEN |
annual percentage of the symbol position opening price |
SYMBOL_SWAP_MODE_REOPEN_CURRENT |
points (with re-opening of the position at the closing price) |
SYMBOL_SWAP_MODE_REOPEN_BID |
points (with re-opening of the position at the Bid price of the new day). (in SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT parameters) |
For the SYMBOL_SWAP_MODE_INTEREST_CURRENT and SYMBOL_SWAP_MODE_INTEREST_OPEN options, there is assumed to be 360 banking days in a year.
For the SYMBOL_SWAP_MODE_REOPEN_CURRENT and SYMBOL_SWAP_MODE_REOPEN_BID options, the position is forcibly closed at the end of the trading day, and then their behavior is different.
With SYMBOL_SWAP_MODE_REOPEN_CURRENT, the position is reopened the next day at yesterday's closing price +/- the specified number of points. With SYMBOL_SWAP_MODE_REOPEN_BID, the position is reopened the next day at the current Bid price +/- the specified number of points. In both cases, the number of points is in the SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT parameters.
Let's check the operation of the properties using the script SymbolFilterSwap.mq5. In the input parameters, we provide the choice of the analysis context: Market Watch or all symbols depending on UseMarketWatch. When the ShowPerSymbolDetails parameter is false, we will calculate statistics, how many times one or another mode from ENUM_SYMBOL_SWAP_MODE is used in symbols. When the ShowPerSymbolDetails parameter is true, we will output an array of all symbols with the mode specified in mode, and sort the array in descending order of values in the fields SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT.
input bool UseMarketWatch = true;
|
For the elements of the combined array of swaps, we describe the SymbolSwap structure with the symbol name and swap value. The direction of the swap will be denoted by a prefix in the name field: "+" for swaps of long positions, "-" for swaps of short positions.
struct SymbolSwap
|
By tradition, we describe the filter object at the beginning of OnStart. However, the following code differs significantly depending on the value of the ShowPerSymbolDetails variable.
void OnStart()
|
Let's introduce the second branch first. Here we fill arrays with symbol names using the filter (symbols) and swap modes (values) that are taken from the SYMBOL_SWAP_MODE property. The resulting values are accumulated in an array map MapArray<ENUM_SYMBOL_SWAP_MODE,int> stats.
// calculation of mode statistics
|
Next, we display the collected statistics.
PrintFormat("Total symbols: %d", n);
|
For the case of constructing a table with swap values, the algorithm is as follows. Swaps for long and short positions are requested separately, so we define paired arrays for names and values. Together they will be brought together in the swaps array of structures.
// summary table of swaps of the selected Mode
|
Set the condition for the selected swap mode in the filter. This is necessary to be able to compare and sort array elements.
f.let(SYMBOL_SWAP_MODE, Mode); |
Then we apply the filter twice for different properties (SYMBOL_SWAP_LONG, SYMBOL_SWAP_SHORT) and fill different arrays with their values (longs, shorts). Within each call, the arrays are sorted in ascending order.
f.select(UseMarketWatch, SYMBOL_SWAP_LONG, buyers, longs, true);
|
In theory, the sizes of the arrays should be the same, since the filter condition is the same, but for clarity, let's allocate a variable for each size. Since each symbol will appear in the resulting table twice, for the long and short sides, we provide a double size for the swaps array.
const int l = ArraySize(longs);
|
Next, we join the two arrays longs and shorts, processing them in reverse order, since we need to sort from positive to negative values.
if(n > 0)
|
It is interesting to run the script several times with different settings. For example, by default, we can get the following results.
===== Swap modes for Market Watch symbols =====
|
These statistics show that 10 symbols have the swap mode SYMBOL_SWAP_MODE_POINTS, for two the swaps are disabled, SYMBOL_SWAP_MODE_DISABLED, and for one it is in the base currency SYMBOL_SWAP_MODE_CURRENCY_SYMBOL.
Let's find out what kind of symbols have SYMBOL_SWAP_MODE_POINTS and find out their swaps. For this, we will set ShowPerSymbolDetails to true (parameter mode already set to SYMBOL_SWAP_MODE_POINTS).
===== Swap modes for Market Watch symbols =====
|
You can compare the values with symbol specifications.
Finally, we change the Mode to SYMBOL_SWAP_MODE_CURRENCY_SYMBOL. In our case, we should get one symbol, but spaced into two lines: with a plus and a minus in the name.
===== Swap modes for Market Watch symbols =====
|
From the table, both swaps are negative.