Skip to content
All library documents

Computing a Rolling Correlation Oscillator Without Loops

Article TradingView scripts

Summary

The indicator calculates rolling correlation between an input price series and a sequence that advances linearly across each lookback window. It uses cumulative sums of price, cumulative sums of those sums, and cumulative squared prices to derive the needed rolling statistics without an explicit loop. The correlation is normalized by the variance of the input series and the known variance of the linear sequence.

The accompanying explanation connects the result to trend analysis and notes that related calculations can support rolling regression measures such as R-squared and sum of squared errors. It also explains that the same correlation can be expressed using a normalized difference between weighted and simple moving averages. The document presents a computational construction, not a tested trading strategy: it gives no entry or exit rules, asset-specific evidence, or performance evaluation. As with any rolling indicator, interpretation depends on the selected window and the behavior of the input series.

Key ideas

  • Cumulative sums can produce rolling correlation with a linear sequence without looping through each window.
  • The calculation combines rolling sums, squared values, and the known variance of the linear sequence.
  • The resulting oscillator measures how closely recent prices align with a linear trend over the selected window.
  • Related rolling calculations can derive regression R-squared and sum of squared errors.
  • The document explains an indicator method but provides no trading rules or performance evidence.

Tags

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