OPEN-SOURCE SCRIPT
QuantLabs Multi Asset Similarity Matrix [V3 Final]

The Market is a graph. See the flows:
The QuantLabs MASM is not a standard correlation table. It is an Alpha-Grade Scanner architected to reveal the hidden "hydraulic" relationships between global macro assets in real-time.
Rebuilt from the ground up for Version 3, this engine pushes the absolute limits of the Pine Script™ runtime. It utilizes a proprietary Logarithmic Math Engine, Symmetric Compute Optimization, and a futuristic "Ghost Mode" interface to deliver a 15x15 real-time correlation matrix with zero lag.
Under the Hood: The Quant Architecture
We stripped away standard libraries to build a lean, high-performance engine designed for institutional-grade accuracy.
1. Alpha Math Engine (Logarithmic Returns) Most tools calculate correlation based on Price, which generates spurious signals (e.g., "Everything is correlated in a bull run").
The Solution: Our engine computes Logarithmic Returns (log(close/close[i+1])) by default. This measures the correlation of change (Velocity & Vector), not price levels.
The Result: A mathematically rigorous view of statistical relationships that filters out the noise of general market drift.
Dual-Core: Toggle seamlessly between "Alpha Mode" (Log Returns) for verified stats and "Visual Mode" (Price) for trend alignment.
Calculation Modes: Pearson (Standard), Euclidean (Distance), Cosine (Vector), Manhattan (Grid).
2. Symmetric Compute Optimization Calculating a 15x15 matrix requires evaluating 225 unique relationships per bar, which often crashes memory limits.
The Fix: The V3 Engine utilizes Symmetric Logic, recognizing that Correlation(A, B) == Correlation(B, A).
The Gain: By computing only the lower triangle of the matrix and mirroring pointers to the upper triangle, we reduced computational load by 50%, ensuring a lightning-fast data feed even on lower timeframes.
3. Context-Aware "Ghost Mode" The UI is designed for professional traders who need focus, not clutter.
Smart Detection: The matrix automatically detects your current chart's Ticker ID. If you are trading QQQ, the matrix will visually highlight the Nas100 row and column, making them opaque and bright while dimming the rest.
Dynamic Transparency: Irrelevant data ("Noise" < 0.3 correlation) fades into the background. Only significant "Alpha Signals" (> 0.7) glow with full Neon Saturation.
Key Features
Dominant Flow Scanner: The matrix scans all 105 unique pairs every tick and prints the #1 Strongest Correlation at the bottom of the pane (e.g., DOMINANT FLOW: Bitcoin ↔ Nas100 [0.85]).
Streak Counter: A "Stubbornness" metric that tracks how many consecutive days a strong correlation has persisted. Instantly identify if a move is a "flash event" or a "structural trend."
Neon Palette: Proprietary color mapping using Electric Blue (+1.0) for lockstep correlation and Deep Red (-1.0) for inverse hedging.
Usage Guide
Placement: Best viewed in a bottom pane (Footer).
Assets: Pre-loaded with the Essential 15 Macro Drivers (Indices, BTC, Gold, Oil, Rates, FX, Key Sectors). Fully editable via settings (Ticker|Name).
Reading the Grid:
🔵 Bright Blue: Assets moving in lockstep (Risk-On).
🔴 Bright Red: Assets moving perfectly opposite (Hedge/Risk-Off).
⚫ Faded/Black: No statistical relationship (Decoupled).
Key Improvements Made:
Formatting: Added clear bullet points and bolding to make it scannable.
Clarity: Clarified the "Logarithmic Returns" section to explain why it matters (Velocity vs. Price Levels).
Tone: Maintained the "high-tech/quant" vibe but removed slightly clunky phrases like "spurious signals" (unless you prefer that academic tone, in which case I left it in as it fits the persona).
Structure: Grouped the "Modes" under the Math Engine for better logic.
Created and designed with love by David James @QuantLabs : )
The QuantLabs MASM is not a standard correlation table. It is an Alpha-Grade Scanner architected to reveal the hidden "hydraulic" relationships between global macro assets in real-time.
Rebuilt from the ground up for Version 3, this engine pushes the absolute limits of the Pine Script™ runtime. It utilizes a proprietary Logarithmic Math Engine, Symmetric Compute Optimization, and a futuristic "Ghost Mode" interface to deliver a 15x15 real-time correlation matrix with zero lag.
Under the Hood: The Quant Architecture
We stripped away standard libraries to build a lean, high-performance engine designed for institutional-grade accuracy.
1. Alpha Math Engine (Logarithmic Returns) Most tools calculate correlation based on Price, which generates spurious signals (e.g., "Everything is correlated in a bull run").
The Solution: Our engine computes Logarithmic Returns (log(close/close[i+1])) by default. This measures the correlation of change (Velocity & Vector), not price levels.
The Result: A mathematically rigorous view of statistical relationships that filters out the noise of general market drift.
Dual-Core: Toggle seamlessly between "Alpha Mode" (Log Returns) for verified stats and "Visual Mode" (Price) for trend alignment.
Calculation Modes: Pearson (Standard), Euclidean (Distance), Cosine (Vector), Manhattan (Grid).
2. Symmetric Compute Optimization Calculating a 15x15 matrix requires evaluating 225 unique relationships per bar, which often crashes memory limits.
The Fix: The V3 Engine utilizes Symmetric Logic, recognizing that Correlation(A, B) == Correlation(B, A).
The Gain: By computing only the lower triangle of the matrix and mirroring pointers to the upper triangle, we reduced computational load by 50%, ensuring a lightning-fast data feed even on lower timeframes.
3. Context-Aware "Ghost Mode" The UI is designed for professional traders who need focus, not clutter.
Smart Detection: The matrix automatically detects your current chart's Ticker ID. If you are trading QQQ, the matrix will visually highlight the Nas100 row and column, making them opaque and bright while dimming the rest.
Dynamic Transparency: Irrelevant data ("Noise" < 0.3 correlation) fades into the background. Only significant "Alpha Signals" (> 0.7) glow with full Neon Saturation.
Key Features
Dominant Flow Scanner: The matrix scans all 105 unique pairs every tick and prints the #1 Strongest Correlation at the bottom of the pane (e.g., DOMINANT FLOW: Bitcoin ↔ Nas100 [0.85]).
Streak Counter: A "Stubbornness" metric that tracks how many consecutive days a strong correlation has persisted. Instantly identify if a move is a "flash event" or a "structural trend."
Neon Palette: Proprietary color mapping using Electric Blue (+1.0) for lockstep correlation and Deep Red (-1.0) for inverse hedging.
Usage Guide
Placement: Best viewed in a bottom pane (Footer).
Assets: Pre-loaded with the Essential 15 Macro Drivers (Indices, BTC, Gold, Oil, Rates, FX, Key Sectors). Fully editable via settings (Ticker|Name).
Reading the Grid:
🔵 Bright Blue: Assets moving in lockstep (Risk-On).
🔴 Bright Red: Assets moving perfectly opposite (Hedge/Risk-Off).
⚫ Faded/Black: No statistical relationship (Decoupled).
Key Improvements Made:
Formatting: Added clear bullet points and bolding to make it scannable.
Clarity: Clarified the "Logarithmic Returns" section to explain why it matters (Velocity vs. Price Levels).
Tone: Maintained the "high-tech/quant" vibe but removed slightly clunky phrases like "spurious signals" (unless you prefer that academic tone, in which case I left it in as it fits the persona).
Structure: Grouped the "Modes" under the Math Engine for better logic.
Created and designed with love by David James @QuantLabs : )
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.