← Back to Home
Trading Strategy
πŸ”„

Pairs Trading Strategy

Profit from diverging co-integrated assets regardless of market direction.

Start Automating Free β†’

Want to automate this strategy? Try auto-Trading free β€” no credit card required.

Pairs Trading Strategy chart

Overview

What is Pairs Trading Strategy?

Pairs trading is a market-neutral strategy that simultaneously buys one asset and short-sells a closely related asset when their price ratio or spread diverges significantly from its historical mean. Because the position is hedged (long one, short the other), it is largely insulated from broad market moves β€” the trade profits purely from the relative movement between the two assets.

The strategy requires identifying two assets with a strong co-integration relationship β€” meaning their prices tend to move together over time due to shared fundamentals. Classic pairs include: Coca-Cola vs Pepsi, Gold vs Silver, two ETFs tracking the same index, or a stock vs its sector ETF. Statistical tests (Augmented Dickey-Fuller, Johansen) verify co-integration before deploying capital.

When the spread between the two assets exceeds a threshold (typically 2 standard deviations from the historical mean), the trader shorts the outperformer and buys the underperformer, betting on mean reversion of the spread. The position is closed when the spread reverts to the mean.

Risk management focuses on the spread β€” not the individual assets. A stop-loss is placed at a further standard deviation expansion (e.g., 3 SD) to protect against co-integration breakdown, which occurs when the fundamental relationship between the two assets changes permanently.

How It Works in auto-Trading

Automate It

auto-Trading's pairs trading module runs co-integration tests on user-specified asset pairs and monitors the rolling spread Z-score continuously. When the Z-score exceeds the configured entry threshold, the system simultaneously places long and short orders with position sizes matched by beta or dollar value. The exit trigger and stop-loss are set at configurable Z-score levels.

Try Free β†’

Strategy Code

Pick a script below, copy it, and use it on your chart.

Pine Script (TradingView)

This is a TradingView Pine Script strategy example for this page concept. Paste it into the TradingView Pine Editor, add it to your chart, and run it in the Strategy Tester.

//@version=6
strategy("Pairs Trading Strategy", overlay=true)
len = input.int(20, "BB Length")
mult = input.float(2.0, "Std Dev")
basis = ta.sma(close, len)

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

ThinkScript (thinkorswim)

This is a thinkorswim ThinkScript strategy example for this page concept. Open thinkorswim, create a custom strategy, paste the script, and apply it to your chart.

input length = 20;
input numDev = 2.0;
def mid = Average(close, length);
def up = mid + numDev * StDev(close, length);
def dn = mid - numDev * StDev(close, length);

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

Ready to automate Pairs Trading Strategy?

Join thousands of traders who use auto-Trading to execute this strategy automatically, 24/7.

Get Started Free β†’

All Strategies & Signals

Continue Learning

Trading Strategies

Trading Signals & Indicators