The Spearman-Pearson Correlation Oscillator is grounded in two foundational statistical measures: Pearsonās correlation coefficient (1895) and Spearmanās rank correlation coefficient (1904). These metrics quantify distinct aspects of the relationship between price and time, providing a dual perspective on market dynamics.
Pearsonās Correlation Coefficient (r) evaluates the linear relationship between price (p[sub]i[/sub]) and time index (i):
r = (Ī£ (p[sub]i[/sub] - pĀÆ)(i - iĀÆ)) / ā(Ī£ (p[sub]i[/sub] - pĀÆ)[sup]2[/sup] Ī£ (i - iĀÆ)[sup]2[/sup])
Here, pĀÆ and iĀÆ are the means of price and time indices, respectively. A high absolute value of r indicates a strong linear trend, with positive values reflecting upward movement and negative values indicating downward movement.
Spearmanās Rank Correlation Coefficient (Ļ) assesses the monotonic relationship by converting price and time into ranks:
Ļ = 1 - (6 Ī£ d[sub]i[/sub][sup]2[/sup]) / (n (n[sup]2[/sup] - 1))
where d[sub]i[/sub] is the difference between the rank of price and the rank of time for each observation, and n is the number of observations. Spearmanās Ļ is robust to non-linear relationships, capturing whether price and time ranks move in tandem.
Indicator Design
The indicator computes two correlation measuresāFast (default: 8 bars) and Slow (default: 12 bars)āusing either Pearsonās r or Spearmanās Ļ, as selected by the user. Each correlation is smoothed with a simple moving average (default: 4 bars) to reduce noise, and the values are inverted to align with traditional oscillator interpretation (negative values indicate potential buying opportunities, positive values suggest selling).
Signal Generation:
- Crossover Arrows: A buy arrow is plotted when the Fast correlation crosses above the Slow correlation within the user-defined oversold zone (default: -0.7), indicating a potential reversal. Conversely, a sell arrow appears when the Fast correlation crosses below the Slow correlation in the overbought zone (default: +0.7).
- Entry Dots: Following an arrow, a gold entry dot is plotted when the Fast correlation crosses back into the neutral zone (i.e., above -0.7 for buys, below +0.7 for sells). This confirms that momentum has stabilized, filtering out transient spikes.
- Moving Average (MA) Filter: Restricts buy signals to bars where the price is above a user-defined MA (default: 50-period SMA) and sell signals to bars where the price is below it, ensuring alignment with the broader trend.
- Average True Range (ATR) Filter: Suppresses signals when volatility, measured by ATR (default: 14 periods), falls below a user-specified threshold, reducing false signals in low-volatility conditions.
- Dual Correlation Framework: Combines Fast and Slow correlations, selectable as Pearson or Spearman, with independent smoothing.
- Two-Stage Signal Logic: Arrows identify initial crossovers in overbought/oversold zones, while entry dots confirm momentum stabilization.
- Robust Implementation: Handles edge cases (e.g., insufficient data, ties in ranks) and includes optional MA and ATR filters for enhanced signal reliability.