Skip to content
All library documents

Long-Only Pair Reversion Using a Median-Based Z-Score Spread

Article TradingView scripts

Summary

This strategy compares two instruments by calculating a rolling z-score for each price series, then subtracting the paired instrument’s score from the main instrument’s score. It applies a modified z-score to that spread using the rolling median and median absolute deviation, a robust alternative to relying only on the mean and standard deviation. A user-defined negative threshold signals a long position in the main instrument, and the position closes when the modified score returns to zero or above.

The code allows the user to choose the comparison symbol and lookback length, and includes commission and slippage assumptions in its strategy settings. However, despite the pairs-trading label, it only trades the main instrument and does not hedge with a position in the second instrument. It also offers no evidence that the pair is cointegrated or that the spread is stationary, and no performance results. Those omissions limit the statistical-arbitrage interpretation and make pair selection and out-of-sample validation essential considerations.

Key ideas

  • The method subtracts one instrument’s rolling price z-score from another’s.
  • A median and median absolute deviation transform the spread into a modified z-score.
  • A sufficiently negative reading opens a long position in the main instrument, which closes at zero or above.
  • The second instrument is used as a signal input and does not receive a hedging trade.
  • No cointegration analysis or strategy performance evidence is supplied.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.