Re: 👨‍🔬 Cagliostro's MT5 Laboratory

91
UPDATED
Cagliostro wrote: Sat Mar 22, 2025 2:19 am Hello fellow traders.

I thought that could be interesting to share with you some of the MT5 stuff I am testing, researching and coding. As some of you know, I switched fully to MT5 last month, so am working to improve my MT5 arsenal.

List of Indicators
-The Oracle
-AVWAP with Bands
-Radius Trend
-X-Stoch
-KoncordePlus

Rules are simple.
-This is a testing lab, you don't pay to get and test stuff, it's all free.
-As per above, feedback and suggestions will be much appreciated.
-But no complaints or lamentations will be appreciated or considered.

Today's the Spring Equinox, the real start of the new year! So there is no better day to start sharing something!

The Oracle
In the shadowed depths of Delphi ancient ruins, where logic and mystery intertwine, lies The Oracle—an artifact of unfathomable power. Forged in an era when the stars whispered secrets to the bold, it transcends mere computation, unveiling glimpses of fate’s hidden currents. Its cryptic code, a relic of a lost civilization, pulses with esoteric wisdom, inviting the daring to pierce the veil of time—though its full mysteries remain tantalizingly out of reach.

It includes 7 indicators chosen, tested and optimized among hundreds in the last 4 months, including the Ehlers's Universal Strength indicator and my Rolling VWAP. Keep it at level 6 for M1/M3/M5 trading and let me know how it goes. Happy Equinox!

April 1 Update [Version 1.0], download it again.
-Incremental processing for all trend updates
-Buffer optimization
-VWAP pre-computation
-Added a Trend Strength Index

April 2 Update, download it again.
-Added customization for histograms and TSI label

April 8 Update, download it again.
-Added MTF validation
-Improved memory management
-Implemented incremental resizing for all buffers
-Fixed trend array stale impacting specific brokers
-Added Data Fetch Logging
-Added Error Handling for all indicators

April 9 Update, download it again.
-Removed redundant trend array shrink
-Improved FetchIndicatorData
-Aligned Local Timers to Server Timers
-Fixed MQL5’s native data sync in retry loop

April 13 Update, download it again.
-Added TF spec to Alerts
-Improved fault tolerance logic

April 19 Update [Version 2.0], download it again.
-Added multiple instances logic for calculations and alerts
-Replaced global variables with instance-specific storage
-Added MTF data sync checks with fallback
-Implemented instance-specific sync failure and anti-freeze mechanism
-Enhanced MTF data fetching with hybrid fetch resizing and index validation

April 25 Update, download it again.
-Instance complete isolation + timer-based handle sync to improve multi instance and multi chart setups.
-MTF sync watchdog with automatic fallback – prevents freezes when higher-timeframe series aren’t ready.
-Per bar indicator fetch cache – to cut CopyBuffer calls by ~50 %.
-Cumulative sum arrays – to reduce CPU load by ~ 40/50%
-Safe math guards – averts divide-by-zero exceptions and silent freezes.
-Histogram color/index refactor – ensures crisp visuals with zero repaint artefacts.
-Alert state isolation – blocks duplicate pop-ups and aligns messages with the correct chart.

April 28 Update, download it again.
-Implemented a new ring-buffer architecture, reducing memory usage by ~95–96%.
-Added resize-on-demand mechanism, cutting CPU overhead by ~90% for array operations.
-Implemented a MTF dynamic caching system to ensure zero recalculation on HTF closed candles
-Moved periodic object cleanup to OnTimer, eliminating per-tick overhead.
-Added pre-sized caches, preventing per-bar resizes.
-Implemented data tail clearing, ensuring accuracy during partial data fetches and broker data blackouts.
-Added series orientation for MTF buffers, improving data ordering.
-Added a separate performance logging logic, enhancing debugging clarity.

April 30 Update, download it again.
-Added Data Stream Watchdog.
-Revamped the MTF and multi-instance sync.
-Removed MTF caching to limit data leak.

The Oracle.ex5


Note: if you face issues, please use version 2.0

Oracle 2.0.ex5
These users thanked the author Cagliostro for the post (total 13):
WN25, mazibee, jmussol, davidpont, Abzak, LakoFX, ManilaSpurs, fnz, doolfrews, Lucas, Philanthropy, kudrpenk, jackboton
"I conjure from shadows and shape fortunes from the unseen. The treasure lies hidden in plain sight, beneath the sunlight." - Cagliostro


Re: 👨‍🔬 Cagliostro's MT5 Laboratory

92
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.
These users thanked the author Cagliostro for the post (total 10):
mazibee, didichung, Abzak, doolfrews, RodrigoRT7, kudrpenk, gamerredd, AlgoAlex811, LakoFX, Ricstar_8
"I conjure from shadows and shape fortunes from the unseen. The treasure lies hidden in plain sight, beneath the sunlight." - Cagliostro