I apologize for not reading all postings of this thread, so I might have informed you already. For those long threads it would be good to have a âsearch the threadâ function. Anyway, here are a couple of scripts (systems) that do what you might be looking for, I am not posting the code, since you can take a look at it when clicking the link but I add the description of the publishers so that you know which might be of interest for you. You can also test some of them after clicking the link::
1. From the article "Pair Trade II System" from the Trading System Lab section of the February 2002 issue of Active Trader. This script always uses Microsoft as the second symbol of the Pair Trade. You can modify the script to use a different symbol.
http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/editsystem?id=14030
2. This is from S&C March 2001 issue.
Pairs Trading is a very interesting strategy because it is "market neutral". That means it should perform equally well in bull or bear markets. Two closely correlated stocks are chosen. Whenever there is a strong deviation from their "should-be" ratio, one is bought and the other sold short, hoping that they will soon come back to their "normal" ratio. Additional information and a complete explanation of the strategy can be found in the S&C article by Stéphane Reverre.
To use this script, you must create a watchlist which contains the symbols SC and RD.
The results are certainly not spectacular, but this strategy produces a steady stream of income and shows exceptionally low drawdowns. Example $imulator result: RD/SC pair, 2000 bars, 50 % of capital for each trade (i.e. 50 % SC AND 50 % RD), one way commissions 2 $.
The 103 % profit in 8 years is about 9.5 % a year, but the exposure is only 20 %, so we could try to find some additional pairs to approach 100 % exposure and obtain a reasonable income from this strategy.
To get this strategy to produce money, it is essential to chose a broker with low commissions. We should pay no more than 1 or 2 $ commissions for a 5000 $ position. Example: 5000 $ is about 123 shares of RD (as of 02/08/2002, closing price = 40.54 $), commissions 1 Cent/share = 1.23 $.
http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/editsystem?id=6655
3. This is an enhanced version of the original "Pairs Trading" script (the one above). It avoids unnecessary trades by providing exit thresholds. It now uses market orders to make it convenient to trade.
Thanks to jrbyrd's contribution, you can now click on any symbol in a watchlist, and it choses the best correlated symbol automatically. The correlation coefficient is displayed in a small text pane below the price pane, so that you can see if the chosen pair is appropriate for pairs trading.
This script is vulnerable to bad data quality. There should be no missing/double bars in your data, otherwise you will see a shift between the two trades of a pair trade (different entry/exit dates for the two symbols). If you're not sure about the quality of your data, you can disable "Strict Synchronization Check" in Tools/Options/System to avoid error messages. "Reverse Synchronization" must be enabled.
If you want to further explore the correlations between the stocks in your watchlists, see discussion thread "Correlation Analyser" (on the WL site).PS: The script doesn't work on the web site, for WLD owners only!
http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/editsystem?id=6990
I hope you find some valuable information in the various systems. Programming pairs systems is surely aimed more for the advanced user then for beginners, but the description might give you some idea. All example above are not my work. The credit belongs to the nice people who were kind enough to share their programming work and ideas with the trading community. Most of all what you will find is the possibility to add empirical evidence on some of the assumptions or a base for furhter studies.
Volker