Intermarket Arbitage is a deal consisting of buying and selling the same asset at the same time in two different markets with an aim to profit from the price difference. Respectively, arbitrage opportunity occures as asset's price difference on two markets is sufficient to cover transaction and logistic costs associated with such deal. In case arbitrager is able to deal in both direction (buying and selling asset) strictly in the same time he bears no risk of holding asset and is able to profit immediatly.
Statistical arbitrage is a deal comprising of buying and selling two (or more) assets which prices are statistically interdependent (cointegrated) on the same (or different) market(s) with the aim to profit from asstes' short term price deviation. Presumably, arbitrager believes the price deviation is going to dissappear in short term period and he will be able to profit closing out positions. In contrast to intermarket arbitrage, statistical arbitrage bears a risk of persistentcy in price deviation which will prevent arbitrager from closing a deal with a profit in resanoble time.
Triangular arbitrage when traded on interbank currency exchange market is an intermarket arbutrage per se. As an example, arbitrager might buy the EUR from Dealer A delivering him USD and at the same time buy GBP from Dealer B delivering him EUR he just bought and, finally, buying back USD from Dealer C delivering him GBP he bought from Dealer B. Occasionally, it might occure that final amount of USD arbitrager has got in hands at the end is bigger than amount he spent to buy EUR in first hand. Could arbitrager manage to deal with all three Dealers at (or almost at) the same time he is not bearing of any risk of loosing on abrupt exchange rate moves.
Unfortunately, such transaction is impossible on marginal account, since arbitrager is not able to deliver any currency to any dealer other then he trades with as total ammount of currency he bought is kept as a collateral in hands of his dealer. The only way arbitrager could profit from triangular exchange rate discreapancy while trading on marginal account is to trade whole "triangle" (e.g. buy EURUSD - sell EURGBP - sell GBPUSD) in one direction, first, after he found arbitrage opportunity and wait the price deviation to invert to trade the same "triangle" in opposite direction to finally profit.
Therefore, aiming to profit from triangular arbitrage on marginal account one have to bear in mind that he is dealing with statistical, not intermarket, arbitrage. Saying this, it make sence to figure out what statistically cointegrated assets are used in triangular arbitrage on marginal account.
Cross-rate and synthetic cross-rate
Starting from 1943 USD was the only currency used as payment mean in international trading. Due to this fact, all national currencies other then USD are conventionally quoted against USD either in direct (number of USD per unit of foreign currency) or indirect (number of foreign currency per unit of USD) quotation.
At te same time, if the price of one national currency (call it base currency) expressed in units of other national currency (call it quote currency) such rate is reffered as base currency's cross-rate. Cross-rate could be calculated as base currency rate expressed in USD devided by quote currency rate expressed in USD (in case of quote currency rate is listed in indirect quotation, cross-rate is calculated as base currency rate in USD multiplied by quote currency rate in USD). As an example, EURGBP cross-rate could be calculated as ratio of EURUSD to GBPUSD and EURJPY cross-rate could be calculated as EURUSD multyplied by USDJPY.
As volume of international trades transacted in national currencies (bypassing USD) increases cross-rate exchange transactions become more and more frequent and liquid so cross currency pairs now emerged as independently traded instruments in FOREX market.
Below, I will refer to traded cross-pair that one can find as independent symbol in MT5-terminal as cross-pair or traded cross-pair. Accordingly, I will refer to calculated cross rate that one can easily synthesize in MT5-terminal by holding two positions in two majors (either one long and one short in case of both majors in direct quotation or both long or both short in case of one major is in indirect quotation) as synthetic cross-pair or simply synthetic (e.g. long EURUSD plus short GBPUSD combination could be treated as synthetic EURGBP cross-pair position).
It is importante to note that traded cross pair rate is not necessary should be equal to synthetic or calculated cross rate since calculated cross rate (or sunthetic) depends presumably on demand and supply in two national currencies relative to USD (majors) as soon as traded cross pair depends mostly on demand and supply of both currencies relative to each other. As experience shows, traded cross rate could deviate from calculated synthetic rate by several points in both dirextion.
It make sense, therefore, trying to exploit such deviation to profit by arbitraging traded cross vs. synthetic cross rates.
TriArb Trader Algorithm
Over regular time intervals, specifyed by input variable "Arb. period (msec)", TriArb Trader EA calculates synthetic cross-rate and compares it to the rate of cross-pare from MT5-terminal. In case positive difference between cross-pair bid-rate and synthetic ask-rate occures larger than value specifyed by input variable "Min. deviation for IN-trade (points)" EA opens long-synthetic position (whuch consists of two positions in majors) and short position in traded cross-pair.
After that following message will appear in Expert's log file:
TriArbTrader_v7-2 (EURUSD,M1) 2016.10.03 17:00:00 TriArbBuy666 Direction = 0 deviation = 13.10 profit = 0.00
Here, "TriArbBuy" fuction name points to trade direction (buy-synthetic), "666" - is Expert's ID (magic code). First line shows triangle's currencies quotes at the moment when arb. oppurtunity is detected and second line shows synthetic/cross-pair price deviation (in points). Direction = 0 means that at the moment there was no open positions.
Accordingly, in case positive difference between synthetic bid-rate and traded cross-pair ask-rate occures larger than value specifyed by input variable "Min. deviation for IN-trade (points)" EA opens short-synthetic and long traded cross-pair positions.
Following message will appear in EA's log file:
2016.10.03 00:02:42 TriArbSell666 Direction = 0 deviation = 295.77 profit = 0.00
"TriArbSell" function name points to trade direction (sell-synthetic), "666" is EA's ID number (magic code), first line shows triangle's currencies quotes at the moment when arb. oppurtunity is detected and second line shows synthetic/cross-pair price deviation (in points). Direction = 0 means that at the moment there was no open positions.
As soon as EA recieves report from trade server that all orders is placed successfully EA prints following message to log-file:
in case of buy-synthetic
2016.10.03 17:00:02 DealBuy666 EURUSD Vol = 0.1 completed at 1.12154 after 1 tries
2016.10.03 17:00:02 Slippage = 12
2016.10.03 17:00:02 DealBuy666 GBPUSD
2016.10.03 17:00:02 DealBuy666 GBPUSD Vol = 0.09 completed at 1.28354 after 1 tries
2016.10.03 17:00:02 Slippage = 5
2016.10.03 17:00:02 DealBuy666 EURGBP
2016.10.03 17:00:09 DealBuy666 EURGBP Vol = 0.1 completed at 0.87351 after 1 tries
2016.10.03 17:00:09 Slippage = 29
and in case of sell-synthetic
2016.10.03 00:02:50 DealSell666 EURUSD Vol = 0.1 completed at 1.12403 after 1 tries
2016.10.03 00:02:50 Slippage = 0
2016.10.03 00:02:50 DealSell666 GBPUSD
2016.10.03 00:02:52 DealSell666 GBPUSD Vol = 0.09 completed at 1.29265 after 1 tries
2016.10.03 00:02:52 Slippage = 7
2016.10.03 00:02:52 DealSell666 EURGBP
2016.10.03 00:02:56 DealSell666 EURGBP Vol = 0.1 completed at 0.86655 after 1 tries
2016.10.03 00:02:56 Slippage = 0
The number of tries (tries = 1) points to the fact that in this case order was placed from the first try. Maximal number of tries is specified by input variable "Max. number of trade retries". MMessage "Slipage = X" shows the difference (in points) between price recorded at the moment when arb. opportunity was detected and price that is placed in traded order. This variable shows the extention initial price deviation detected has been compensated to the moment order was finally placed (in other words, potential profit lost due to time delay between arb. detection and order placement).
In the next step, EA should check triangle integrity (all three positions are in place) but before this check begins EA should pause for some time specifyed by input variable "Pause before integrity check (msc)". This pause is neccessary for trading server being able to fulfill all orders just placed and open positions.
In case integrity is in check EA store the trade direction as Direction = 1 in case of buy-synthetic and Direction = -1 in case of sell-synthetic and starts monitoring open positions.
In case there is of empty gaps or excessive positions in triangle EA will try to oopen (in case of gaps) or close (in case of excessive) positions. Maximal number of tries is specified be input variable "Max. number of trade retries". In case EA fails to fix triangle integrity in last try it will close all positions printing appropriate message to the log file.
In position monitoring regime, EA calculates current profit over regular time intervals as were specified by "Arb. period (msec)" input variable. In case total profit calculated for whole triangle exceeds the take profit value as specified by "Take Profit (USD)" input variable EA closes all positions.
In this case log-message will print in case of closing buy-synthetic positions:
2016.10.12 19:58:06 ProfitBuy666 Direction = 1 profit = 5.20
and in case of closing sell-synthetic positions:
2016.10.18 11:30:00 ProfitSell666 Direction = -1 profit = 5.90
Here "ProfitBuy" function name and Direction = 1 points to the fact that position closed was buy-synthetic, "666" is an EA's ID (magic code) and "profit = 5.20" shows the profit value at the moment of close order was sent to trade server (due to time delay and slipage real close price could differ).
IMPORTANT NOTE!!! "Take Profit (USD)" input variable is specified in deposit currency. So if deposit (and profit) is in EUR please specify amount of take profit in EUR term.
After all three orders were placed to trading server following message appears:
in case of closed position is buy-synthetic
2016.10.12 19:58:17 DealSell666 EURUSD Vol = 0.1 completed at 1.10297 after 1 tries
2016.10.12 19:58:17 Slippage = 0
2016.10.12 19:58:17 DealSell666 GBPUSD
2016.10.12 19:58:21 DealSell666 GBPUSD Vol = 0.09 completed at 1.22214 after 1 tries
2016.10.12 19:58:21 Slippage = 20
2016.10.12 19:58:21 DealSell666 EURGBP
2016.10.12 19:58:24 DealSell666 EURGBP Vol = 0.1 completed at 0.90265 after 1 tries
2016.10.12 19:58:24 Slippage = 85
in case of closed position is sell-synthetic
2016.10.18 11:30:04 DealBuy666 EURUSD Vol = 0.1 completed at 1.10158 after 1 tries
2016.10.18 11:30:04 Slippage = 5
2016.10.18 11:30:04 DealBuy666 GBPUSD
2016.10.18 11:30:09 DealBuy666 GBPUSD Vol = 0.09 completed at 1.22579 after 1 tries
2016.10.18 11:30:09 Slippage = 79
2016.10.18 11:30:09 DealBuy666 EURGBP
2016.10.18 11:30:10 DealBuy666 EURGBP Vol = 0.1 completed at 0.89828 after 1 tries
2016.10.18 11:30:10 Slippage = 3
In case of account margin mode is "hedging" additional message will be printed to log:
2016.10.12 19:58:36 CloseBy666 GBPUSD completed after 1 tries
2016.10.12 19:58:52 CloseBy666 EURGBP completed after 1 tries
This EA doesn't use Stop-Loss per se Nevertheless, in case position is in "red" for long time and total loss exceeds (in absolute terms) amount specified by input variable "Max. Loss (USD)", EA will check inverce cross-pair/synthetic price deviation to close the position.
Buy-synthetic position will be closed if total triangle position's loss exceeds (in absolute term) value specifyed by input variable "Max. Loss (USD)" and synthetic bid / cross-pair ask difference exceeds value specified by "Min. deviation for OUT-trade (points)" input variable.
In this case following message will bve printed to log-file:
2016.10.07 02:39:29 TriArbSell666 Direction = 1 deviation = 14.37 profit = -8.50
"TriArbSell" function name and "Direction = 1" point to buy-synthetic position is closed and "profit = -8.50" points to the fact that position is closed as "stop-loss".
Sell-synthetic position will be closed if total triangle position loss exceeds (in absolute term) value specifyed by input variable "Max. Loss (USD)" and cross-pair bid - synthetic ask difference exceeds value specified by "Min. deviation for OUT-trade (points)" input variable.
In this case following message will bve printed to log-file:
2016.10.07 02:32:21 TriArbBuy666 Direction = -1 deviation = 15.25profit = -12.19
"TriArbSell" function name and "Direction = -1" point to sell-synthetic position is closed and "profit = -12.19" points to the fact that position is closed as "stop-loss".
Input variables and its recommended values
Few words on correct selection of currency pairs compraising triangle.
EA is pretty flexible in terms of currency pair selection. Still it is very important to select pairs correctly.
To do this it is recommended to start from cross pair. Let us assume we have chosen EURJPY as a cross-pair. In this case following three steps should be completed.
Step 1. Incert EURJPY - as "Cross pare symbol" input variable: in our case EURJPY is a cross-pair symbol.
Step 2. Incert the first cross-pair's symbol as "First cross pair symbol" input variable: in our case EUR is a first symbol in cross pair so you should put EURUSD as first cross pair symbol.
IMPORTANT NOTE! First cross pair symbol always must by in DIRECT QOTATION!
Step 3. Incert second cross pair symbol as "Second cross pair symbol" input variable: in our case JPY is a second cross-pair's symbol so you should put USDJPY as a second cross pair.
Please note that USDJPY is in inderect quotation. In this case you should toggle input variable "Second major is in direct quotation" to false position.
That's essentially is. Our triangle is ready.
Table below lists all input variables and its recommended values.
|Cross pair symbol||EURJPY||Cross pair (e.g. EURJPY)|
|First cross pair symbol||EURUSD||First symbol in cross pair (e.g. EURUSD)|
|Second cross pair symbol||USDJPY||Second symbol in cross pair (e.g. USDJPY)|
|Second symbol is in direct quotation||false||USDJPY is a second symbol and it is in inderect quottion|
|Expert Advisor ID (Magic Number)||666||EA's ID (magic number) You can put several EAs on different charts. To prevent interference use different ID (magic) numbers.|
|Max deviation (slipage)||30||It is critical for this EA to complete all deals so chose higher slippage number to increas trade probability|
|Arb. period (msec)||500||Time period to reculculate arbitrage deviation and profit|
|Max. number of trade retries||10||Max. number EA retries to trade in case of fail (e.g. due to slippage). In case you see one or two positions are not open from time to time increas number of trade retries.|
|Min. deviation for IN-trade (points)||10||Min. amount of synthetic cross vs. cross price deviation to open position. EA prints actual price deviation at wich it decided to open position. In case EA trades to frequent and profit is not sufficient (e.g. due to slippage) to steady growth in equity you may chose to increase this parameter.|
|Min. deviation for OUT-trade (points)||10||Min. amount of synthetic cross vs. cross pair price deviation to close position in case total loss exceeds Max loss input variable. It is recommmended to chose OUT deviation at least equal or greater than IN devation.|
|Take Profit (USD)||10||It is male sence to play with this parameter. If you chose this parameter too low positions possibly will be closed prematurely. Moreover some profit will be eliminated due to slippage. In case you chose to high take profit position's maximum profit could be insufficient to close the position Please note that profit depends on lot size. It is particulalry impossibe to have $5 profit using 0.01 trading lot.|
|Max. Loss (USD)||15||This value should be at least equal or greater Take profit level.|
|Trading volume||1||Please do not use more than 1 (one) lot for $10'000 account.|