Skip to content
All library documents

Rolling Spearman Rank Correlation for Comparing Market Series

Article TradingView scripts

Summary

This indicator computes a rolling Spearman rank correlation between a chosen chart source and the closing price of a selected symbol. It ranks observations within the lookback window, assigns average ranks to tied values, and then calculates correlation from the ranked series. For windows without ties, it uses the standard rank-difference expression; when ties occur, it uses a covariance-based calculation on the ranks.

The output ranges from negative to positive association: positive values indicate that the series tend to move in the same direction, negative values that they tend to move oppositely, and values near zero that there is little rank association in the window. The display marks these reference levels and colors the plotted columns by correlation strength. This is a descriptive comparison tool, not a trading strategy or evidence of predictive power. Correlation can change with the selected symbol, source, and lookback, and the document provides no performance study or guidance for dealing with asynchronous market data.

Key ideas

  • The indicator measures rank association between a selected chart source and another symbol's closing price.
  • It ranks values within a rolling window and gives tied observations their average rank.
  • Positive and negative readings represent same-direction and opposite-direction rank association, respectively.
  • The calculation uses a separate covariance-based method when either series contains tied ranks.
  • The indicator describes co-movement and provides no evidence that correlation predicts returns.

Tags

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