Cointegrated Pairs Trading Indicator
Model Lelothoane is a forex trading system model packaged into an indicator executable on a PC running Metatrader 4. The model exploits the mean-reversion property of stationary processes. Stationarity is determined or confirmed by performing cointegration tests between two forex instruments. In the case that there is strong evidence of cointegration the two instruments can be traded as one stationary process. The trader can make entries every time the model spread/deviation (residual time series) crosses a new multiple of standard deviation from on its way from the mean. The indicator plots four multiples of standard deviation (-4 Std, -3 Std, -2 Std, -1 Std, 1 Std, 2 Std, 3 Std, 4 Std) in the indicator window below the main chart window. The indicator also displays some useful information (i.e. cointegration model parameters, lot size ratio, standard deviation, model deviation, levels, etc) in the main chart window.
To explain this operation further, suppose the model spread crosses the first standard deviation (negative or positive side) away from the mean. Then the trader will open two orders which together act as one order pair for model spread as a synthetic instrument (a stationary one). If the model spread goes further away to cross the second standard deviation from the mean, the trader can pen a new order pair with same lot sizes. The trader should wait until the model spread reverts back to the mean (i.e. level 0) and close all trades and start afresh. The end result is always that when the model mean finally reverts back to the mean there will be net profit in so far as the cointegration model is still valid.
There is a good reason why it is safe to keep opening order pairs as the model spread keeps moving away from the mean. That reason is that, since the model spread is a tested stationary process then it has a tendency of mean reversion and binning this process result in Gaussian histogram profile and this tells us that the probability of model spread moving further and further away from the mean decreases exponentially. It is for this reason that always betting that model spread is bound to revert back to the mean value results in an investment system with a positive expectation value which can be calculated explicitly given the mean and variance of the Gaussian histogram profile.
The lot size ratio is given by the coefficients of the instruments displayed in the main chart window (i.e. if the model is EURUD = -1.14*USDCHF + 1.86 for example, then the lot size ratio should be EURUSD : USDCHF = 1.00 : 1.14. Here are some few rules regarding what to buy/sell and when. Suppose the cointegration model example is given by EURUSD = M*USDCHF + C. Then the rules are as follows (Remember we only make entries when the model spread crosses multiples of standard deviation when it moves away from the mean):
1. If Model deviation is negative (i.e. negative level) AND the coefficient M is positive, do the following: (a) buy EURUSD and sell USDCHF and (b) set the lot size ratio of EURSD : USDCHF = 1 : abs(M).
2. If Model deviation is negative (i.e. negative level) AND the coefficient M is negative, do the following: (a) buy EURUSD and buy USDCHF and (b) set the lot size ratio of EURSD : USDCHF = 1 : abs(M).
3. If Model deviation is positive (i.e. negative level) AND the coefficient M is positive, do the following: (a) sell EURUSD and buy USDCHF and (b) set the lot size ratio of EURSD : USDCHF = 1 : abs(M).4. If Model deviation is positive (i.e. negative level) AND the coefficient M is negative, do the following: (a) sell EURUSD and sell USDCHF and (b) set the lot size ratio of EURSD : USDCHF = 1 : abs(M).
The robot has various input parameters (set at default settings) some of which are described below:
1. N is the data size for building cointegration model.
2. TFrame is the time frame in minutes.
3. PairOne & PairTwo are two trading instruments which are to tested for cointegration and traded if the test succeeds. The robot will report back if the chosen instruments have weak or no significant cointegration and the user should react by choosing a different combination.