Setting up TriArb Trader version 9.1 and higher

Setting up TriArb Trader version 9.1 and higher

15 December 2016, 00:40
oschenker
[Deleted]
3
1 526

Introduction

Inter-market 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 immediately.

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 assets' short term price deviation. Presumably, arbitrager believes the price deviation is going to disappear in short term period and he will be able to profit after closing out positions. In contrast to inter-market arbitrage, statistical arbitrage bears a risk of persistence in price deviation which will prevent arbitrager from closing a deal with a profit in reasonable time.

Triangular arbitrage, when traded on inter-bank currency exchange market, is an inter-market arbitrage per se. As an example, arbitrager might buy the EUR from Dealer A delivering him USD buying at the same time GBP from Dealer B delivering him EUR he just bought and, simultaneously, buying back USD from Dealer C delivering him GBP he bought from Dealer B. Occasionally, it might occur 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 amount of currency he bought is kept as a collateral in hands of his dealer. The only way arbitrager could profit from triangular exchange rate discrepancy 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 before 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 inter-market, arbitrage. Saying this, it make sense to figure out what statistically cointegrated assets are used in triangular arbitrage on marginal account.

Cross-rate vs. 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 the 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 referred as base currency's cross-rate. Cross-rate could be calculated as base currency rate expressed in USD divided 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 multiplied by USDJPY. 

As volume of international trades transacted in national currencies (bypassing USD) increased, cross-rate exchange transactions became more and more frequent and liquid so cross currency pairs now emerged as independently traded in FOREX market instruments.

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 important to note that traded cross pair rate is not necessary should be equal to synthetic or calculated cross rate since synthetic rate depends presumably on demand and supply in two national currencies relative to USD (majors) as soon as traded cross-pair's rate 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 directions.

It make sense, therefore, trying to exploit such deviation to profit by statistically arbitraging traded cross vs. synthetic cross rates.

TriArb Trader Algorithm

Over regular time intervals, specified 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 a positive difference (deviation) between cross-pair bid-rate and synthetic ask-rate is larger than value specified by input variable "Min. deviation (points)", EA opens "BUY-triangle"long-synthetic (which consists of two positions in majors) versus short cross-pair - position. After such a trade, following message will appear in Expert's log file:

2017.05.30 11:57:33.739 TriArbTrader (EURUSD,H1)        111 TriArbSpread       +Deviation = 16.36
2017.05.30 11:57:33.739 TriArbTrader (EURUSD,H1)        111 DealBuy            3 orders are sent in 586 mksec.
2017.05.30 11:57:33.739 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURUSD Open in 9471 mksec. Slippage = 0.00.
2017.05.30 11:57:33.755 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction GBPUSD Open in 10912 mksec. Slippage = 0.00.
2017.05.30 11:57:33.755 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURGBP Open in 10949 mksec. Slippage = 0.00.
2017.05.30 11:57:33.755 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction All requests are checked. Net positions = 3. Closed profit = 0.00.

First line shows deviation size. "+" sign means cross rate is higher than synthetic rate - therefor "DealBuy" function - buy synthetic / sell cross. "111" - is Expert's ID (magic code). Second line shows time delay between moment EA has calculated deviation and moment it sent trade orders. Following three lines show execution time and slippage in all tree pairs of triangle and final line reports deal result (Net positions open in case of open-in deals and Closed profit in case of close-out).

Accordingly, in case positive difference between synthetic bid-rate and traded cross-pair ask-rate is larger than value specified by input variable "Min. deviation (points)", EA opens "SELL-triangle" - short-synthetic versus long traded cross-pair -  positions.

Following message will appear in EA's log file in this case:

2017.05.30 13:45:26.736 TriArbTrader (EURUSD,H1)        111 TriArbSpread       -Deviation = -18.49
2017.05.30 13:45:26.736 TriArbTrader (EURUSD,H1)        111 DealSell           3 orders are sent in 1496 mksec.
2017.05.30 13:45:26.736 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURUSD Open in 10085 mksec. Slippage = 0.00.
2017.05.30 13:45:26.736 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction GBPUSD Open in 12457 mksec. Slippage = 0.00.
2017.05.30 13:45:26.736 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURGBP Open in 13405 mksec. Slippage = 0.00.
2017.05.30 13:45:26.736 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction All requests are checked. Net positions = -3. Closed profit = 0.00.

First line shows deviation size. "-" sign means synthetic rate is higher than cross-rate - therefor "DealSell" function - sell synthetic / buy cross. "111" - is Expert's ID (magic code). Second line shows time delay between moment EA has calculated deviation and moment it sent trade orders. Following three lines show execution time and slippage in all tree pairs of triangle and final line reports deal result (Net positions open in case of open-in deals and Closed profit in case of close-out).

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 three positions.

In this case log-message will print following message. In case of closing BUY-triangle positions:

2017.05.30 11:59:23.173 TriArbTrader (EURUSD,H1)        111 ProfitCheck        Profit 1.33.
2017.05.30 11:59:23.173 TriArbTrader (EURUSD,H1)        111 DealSell           3 orders are sent in 665 mksec.
2017.05.30 11:59:23.173 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURUSD Closed in 9138 mksec. Slippage = 0.00.
2017.05.30 11:59:23.173 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction GBPUSD Closed in 11071 mksec. Slippage = 0.00.
2017.05.30 11:59:23.189 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURGBP Closed in 12992 mksec. Slippage = -2.00.
2017.05.30 11:59:23.189 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction All requests are checked. Net positions = 0. Closed profit = 1.09.

and in case of closing SELL-triangle positions:

2017.05.30 13:45:43.740 TriArbTrader (EURUSD,H1)        111 ProfitCheck        Profit 2.13.
2017.05.30 13:45:43.740 TriArbTrader (EURUSD,H1)        111 DealBuy            3 orders are sent in 514 mksec.
2017.05.30 13:45:43.740 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURUSD Closed in 4881 mksec. Slippage = 0.00.
2017.05.30 13:45:43.740 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction GBPUSD Closed in 7533 mksec. Slippage = 0.00.
2017.05.30 13:45:43.740 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction EURGBP Closed in 7903 mksec. Slippage = 0.00.
2017.05.30 13:45:43.740 TriArbTrader (EURUSD,H1)        111 OnTradeTransaction All requests are checked. Net positions = 0. Closed profit = 2.13.

First line shows profit value. "DealBuy" or "DealSell" function occurs in revers direction to initial trade. "111" - is Expert's ID (magic code). Second line shows time delay between moment EA has calculated profit and moment it sent trade orders. Following three lines show execution time and slippage in all tree pairs of triangle and final line reports deal result (Net positions open in case of open-in deals and Closed profit in case of close-out). 

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.

Input variables and its recommended values

Few words on correct specification of currency pairs comprising triangle.

EA is pretty flexible in terms of currency pair specification. Still it is very important to follow one simple rule explained below.

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 QUOTATION!

Step 3. Insert 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 indirect 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!!!

List below guide you to specify and set-up all EA's input variables.

  • Cross pair symbol - symbol of the cross pair. For example, EURJPY or EURGBP.
  • First cross pair's symbol - the first symbol of the cross pair. Both for EURJPY and EURGBP it is EUR (EURUSD).
  • Second cross pair symbol - the second symbol of the cross pair. For EURJPY JPY (USDJPY). For EURGBP - GBP (GBPUSD).
  • Second symbol is in direct quotation - "true", if the second symbol is given in a direct quotation. GBPUSD is in a direct quotation => "true""false" if the second symbol is given in an indirect quotation. USDJPY is in an indirect quotation => "false".
  • Expert Adviser ID (Magic Number) - ID of the Expert Adviser, a unique number for each EA on the account.
  • Arb. period (ms) - period for checking the arbitrage conditions. The optimal value in the range 300-500 ms.
  • Min. deviation (points) - threshold deviation to open positions. The optimal value is in the range of 8-15 points for a five-digit account.
  • Take Profit (USD) - target profit (in the deposit currency) of all three positions, at which the EA will close the triangle. The optimal value ~ Min. deviation Trading volume.
  • Trading volume - lot size. The optimal value depends on the broker's liquidity. With low liquidity, the order is executed at a weighted average price.
Share it with friends: