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 Stephane Reverre.
To use this script, you must create a watchlist which contains the symbols INTC and MSFT (for example).
Tip:
When you use SetContext to enter a long with a different secondary symbol, after the trade RestoreContext reverts to the original symbol. However, when accessing the position object, for example, with IsLastPositionActive, there is no need to SetContext to the symbol traded in order to find the Position object. Passing the Position object to the exit signal should be sufficient.