Attachments forums

List of attachments posted on this forum.


All files on forums: 159904

Re: 👨ā€🔬 Cagliostro's MT5 Laboratory

Cagliostro, Fri May 02, 2025 1:53 am

Spearman-Pearson Correlation Oscillator with Entries

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.
Optional Filters:
  • 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.
Core Features
  • 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.
All files in topic