Rolling Correlation¶
Math · Rolling
Pearson correlation of two series over the trailing N bars (−1…+1). For pairs / cross-asset relationships and confirming that two signals move together. NaN during warmup or when a window is flat.
Rolling Correlation measures how tightly two series have moved together over the last N bars, on a scale of −1 to +1. +1 means they rose and fell in lockstep, −1 means they moved exactly opposite, and 0 means no linear relationship. It's the core tool for pairs trading and for confirming that two signals actually agree.
How it works¶
Each bar the block computes the Pearson correlation coefficient of inputs A and B over the trailing window. It standardises both series within the window and measures how their movements line up. Output is NaN during warmup, and also when either window is perfectly flat (correlation is undefined with zero variance). Lookahead-free.
When to use it¶
Use it for cross-asset and pairs work — is EURUSD still tracking GBPUSD? — where a breakdown in correlation is itself the signal. It's also a confluence check: correlate two of your own indicators to confirm they're telling the same story before you size up. Falling correlation warns that a hedge or a spread relationship is drifting apart.
Example¶
Pairs divergence: feed two symbols' closes into A and B (window = 50). When the correlation stays high but the price spread stretches wide, you have a mean-reversion setup; gate your entry with LessThan on the spread and GreaterThan on the correlation.
Tips & gotchas¶
- Correlation is not causation — it only measures co-movement, and it can flip fast.
- NaN when a window is flat — a dead-quiet series has no correlation to report.
- Short windows are noisy; longer windows are steadier but slower to notice a regime change.
- Needs a second data source wired into B for cross-asset use.
Related blocks¶
Inputs¶
| Socket | Type | What to wire in |
|---|---|---|
| A | series / bars |
First series. BARS uses close. |
| B | series / bars |
Second series. BARS uses close. |
Outputs¶
| Output | Type | Plots as | Description |
|---|---|---|---|
| corr | series |
Line · sub-pane | Rolling Pearson correlation (−1…+1). |
Parameters¶
| Parameter | Type | Default | What it does |
|---|---|---|---|
| Window (bars) | number · 2–500 | 14 |
Bars in the rolling window. |
Reference auto-generated from the block catalog · category Math.