What It Does

ES/NQ Pair Spread runs on daily bars. On every session close where both legs printed, the strategy:

  1. Computes the closing price ratio ratio = ES_close / NQ_close.
  2. Pulls the prior lookback_days daily ratios (default 60), computes their mean and standard deviation.
  3. Computes today’s z-score: z = (today_ratio - mean) / stdev.
  4. If flat and z >= entry_z (default 2.0): short the spread by selling ES and buying NQ (the ratio is high relative to history; ES is “expensive”).
  5. If flat and z <= -entry_z: long the spread by buying ES and selling NQ (the ratio is low; ES is “cheap”).
  6. If in a position and |z| <= exit_z (default 0.5): flatten both legs.

The strategy has no stops, no profit targets, no holding-period limit. The z-score crossing back through the exit band is the only exit. A spread that keeps stretching against the position is held until it eventually reverts or the backtest ends.

Why Pair Trades Get Used

ES and NQ are both US equity index futures and move together most of the time. The differences between them are driven by sector composition: NQ is concentrated in mega-cap tech, ES is more diversified. When tech outperforms the broader market for a stretch, the ratio drifts lower; when value rotates in, the ratio drifts higher. Either move tends to mean-revert over weeks to months because the underlying correlation between the two indices remains high.

A pair spread isolates this relative move. By design it has less directional exposure than a single-leg position: a 5% market crash that hits both indices equally leaves the spread unchanged. The trade pays off when the relationship between the two legs reverts, not when the market itself moves.

The flip side: when the relationship structurally changes (sector rotation that does not unwind, a regulatory event that affects one index more than the other), the spread can stretch beyond historical bands and stay there. The strategy does not detect or adapt to regime changes; it just keeps placing the same trade.

Notional Balance

ES and NQ are dollar-asymmetric futures. ES is $50 per point; at ~5000, one contract represents ~$250k notional. NQ is $20 per point; at ~20000, one contract is ~$400k notional. The default es_quantity:nq_quantity of 2:1 brings these closer to balance at typical 2020-2024 prices, but does not auto-rebalance as prices drift. Users running the strategy at very different price regimes may want to adjust the leg sizes.

Presets

Five presets cover the canonical variants:

  • Classic Z=2 Both Sides: the default starting point. Trades both directions at 2-stdev entry, 0.5-stdev exit.
  • Tight Z=1.5 / Wide Z=2.5: narrower or wider entry bands. Tighter fires more often with more whipsaw; wider fires rarely but with cleaner setups.
  • Long Spread Only / Short Spread Only: directional variants for when you have a view on which side of the relationship is more reliable.

Best In

  • Periods of moderate but persistent rotation between large-cap tech and the broader market.
  • Research where you want a market-neutral baseline.
  • Studies that want to test whether ES-NQ correlation breakdowns produce tradable signals.

Where It Struggles

  • Sustained regime changes. A multi-year tech outperformance keeps the ratio low and the long-spread leg keeps re-entering as the spread stretches further.
  • Periods of high overall market volatility. The z-score thresholds were tuned for the 2020-2024 window; in high-vol regimes the same z value represents a much larger dollar move.
  • Funding cost is not modeled. Real pair trades have margin requirements on both legs and may have implicit financing costs not reflected in the backtest.

What It Does Not Do

  • No stops, no targets, no time-based exit. A spread that never reverts to the exit band stays open.
  • No dynamic leg sizing. The es_quantity:nq_quantity ratio is fixed per preset.
  • No regime detection. The strategy keeps applying the same z-score rule whether the relationship is range-bound or trending.
  • No spread adjustment for index changes. NQ index reconstitutions occasionally change the basket weighting; the strategy treats prices as continuous.

Test this strategy

Run it on your contracts, timeframes, and parameters.