← Back to Blog
Strategies

Pairs Trading Strategy: Trade the Gap Between Two Stocks

How a pairs trading bot works: compare a stock to a related one, measure the gap with a z-score, and buy the cheap side when the gap stretches. Includes risks and a plain-English example.

VibeTrader Team November 6, 2026 6 min read

What Is Pairs Trading?

Most strategies look at one price at a time. Pairs trading looks at two prices and asks a different question: is one of them unusually cheap or expensive compared with the other?

Take two companies whose businesses overlap, say two big beverage makers. Their share prices usually drift in similar directions because the same customers, costs and headlines affect both. The ratio between the two prices (one divided by the other) tends to wander around some typical level. Pairs trading is built on the idea that when the ratio stretches far from its usual level, it has often drifted back toward it afterward. Often is not always, and that distinction matters for everything below.

A bot on VibeTrader trades one symbol, the one the bot is built on. The second symbol is the yardstick. When the bot's stock looks cheap against the yardstick, the bot can buy it. When the gap closes, it sells.


Picking a Pair

The whole strategy depends on the two symbols having a real reason to move together. A few places to look:

  • Same industry, similar business. Two large companies selling to the same customers, or two banks, or two chipmakers.
  • An ETF and one of its biggest holdings. A semiconductor ETF and the chip company that makes up a large share of it will share a lot of movement, because one is partly made of the other.
  • A supply chain. A company and one of its major suppliers or customers can be tied together by the same demand.

A reason matters more than a chart. Two prices can wiggle together by coincidence for a year and then stop. Ask whether you could explain, in one sentence, why they should be linked.

VibeTrader compares stocks and ETFs with other stocks and ETFs, and crypto with other crypto. A stock against a crypto pair is not supported, because the two trade on different clocks: a stock market closes each evening while crypto keeps going, so a comparison would mix prices from different moments. If you try one, the bot builder tells you so in a sentence and suggests pairing within the same kind of asset.


The Z-Score, in Words

Saying "the gap looks big" is vague. A z-score makes it a number.

Imagine plotting the price ratio every day for the last 60 days. It bounces around an average, sometimes above, sometimes below. Now measure how far today's ratio sits from that average, counted in units of how much the ratio typically bounces. That count is the z-score.

  • Near 0: the ratio is close to its recent average. Nothing unusual.
  • Around -2: the ratio is about two typical bounces below its average. Your stock is cheap against the other one.
  • Around +2: about two typical bounces above. Your stock is expensive against the other one.

The scale adjusts itself. A pair that normally moves a lot needs a bigger gap to reach -2 than a pair that moves very little, so one threshold works across different pairs.

VibeTrader's pair indicator uses a 60-bar lookback by default and also shows the ratio itself, the average ratio, and how far the ratio is from that average in percent. You can change the lookback. A shorter window reacts faster and flags more gaps; a longer one is steadier. There is also a single-symbol z-score (20 bars by default) if you want to apply the same idea to one price without a partner.


How the Pair Check Reads the Past Year

When you create a pair bot, VibeTrader looks back over the previous year of prices for the two symbols and leaves you a short note. It reports what happened in the past tense: whether the price ratio returned to its average during that year, or whether it drifted away and stayed away.

That note is a look in the rear-view mirror, nothing more. It can tell you that a pair you picked behaved like a pair last year, or that it did not. It cannot tell you what the ratio will do next month. Treat a "drifted" note as a reason to rethink the pair, and treat a "returned" note as a reason to keep going carefully, not as a green light.

Pair rules also act on the bar's close by default. The bot waits for a bar to finish before judging the gap, so a brief spike in the middle of a bar does not trigger a trade.


A Worked Example in VibeChat

You do not need to write conditions by hand. Describe the idea to VibeChat in plain English:

Example prompt: "Buy KO when its price is 2 standard deviations cheap compared to PEP over the last 60 days, checked at the daily close, and sell when the gap closes back to normal."

VibeChat turns that into a bot on KO. The entry is a z-score of -2 or lower against PEP over 60 bars, and the exit is the gap closing back toward normal. You can read the generated rules, change the threshold or lookback, and add a stop loss before anything runs.

If you would rather start from a template, the app includes ready-made ones: Pairs Mean Reversion (KO against PEP), ETF vs Its Leader (SMH against NVDA), Bitcoin Stocks Gap (MSTR against COIN) and Z-Score Mean Reversion for a single symbol. Each one is an editable starting point.

Run it on a paper account first and watch how often the gap appears, how long it takes to close, and what happens when it does not.


Risks to Understand First

Pairs trading sounds tidy. Be clear-eyed about where it can go wrong.

  • Relationships break. Two companies can stop moving together because of a merger, a scandal, a new product or a change in business. A ratio that has returned to its average for years can leave for good.
  • Gaps can keep widening. A z-score of -2 is not a floor. The gap can go to -3, -4 and beyond while your bot is already holding shares. A stop loss limits the damage, but it also locks in a loss on a gap that might have closed later.
  • The bot buys only the cheap side. A textbook pairs trade buys one stock and sells the other short at the same time, so the market's overall moves partly cancel. A VibeTrader pair bot trades only its own symbol. If the whole market falls, your stock can fall with it even though it is "cheap" against the other one. The ratio is a signal, not a hedge.
  • The past year is only the past year. The pair check describes history. Conditions change.

Sizing matters too: keep each position small enough that being wrong about one pair is survivable. Paper trade first, for long enough to see the pair behave both ways.


Try It

  • Create a free VibeTrader account
  • Start on a paper account
  • Open VibeChat and describe a pair, or pick the Pairs Mean Reversion template
  • Read the pair check note, adjust the threshold and add a stop loss
  • Watch it run before deciding anything further

If you are new to the underlying idea, read mean reversion trading first, and see how it fits with the other approaches in best trading bot strategies.

This article is educational and is not investment advice. Trading involves risk, including loss of principal.

Ready to Automate Your Trading?

VibeTrader lets you create trading bots using plain English. No coding required.

Create Your First Bot Free →