OPEN-SOURCE SCRIPT
Volume Weighted Correlation

This indicator analyzes the structural relationship between two
assets by decomposing the Total Correlation into two distinct,
interpretable components: "Between-Bar" (Inter-Bar) and
"Within-Bar" (Intra-Bar) correlation.
Key Features:
1. **Hybrid Copula Estimator:** Unlike standard correlation, which
often fails on High/Low range data, this indicator fuses two
metrics to ensure mathematical rigor:
- **Magnitude:** Derived from Rogers-Satchell Volatility.
- **Direction:** Derived from Log-Returns.
This allows for precise correlation estimates even on intra-bar data.
2. **Two-Component Correlation Decomposition:** The indicator
separates correlation based on the 'Estimate Bar Statistics' option.
- **Standard Mode (`Estimate Bar Statistics` = OFF):** Calculates
correlation based on the selected `Source` (Close-to-Close).
- **Decomposition Mode (`Estimate Bar Statistics` = ON):** The
indicator uses a statistical model ('Estimator') to
calculate *within-bar* correlation.
This separates the relationship into:
- **Between-Bar Correlation (Green/Red):** Correlation of the
price paths (means). Indicates if the macro movements of the
assets are aligned (Inter-Bar correlation).
- **Within-Bar Correlation (Blue):** Correlation of the
microstructure (Intra-Bar volatility/noise).
3. **Visual Decomposition Logic:** Total Correlation is the
primary metric displayed. Since Correlation Coefficients are not
linearly additive, this indicator calculates the *exact* Total
Correlation and partitions the area/ratios based on the additive
Covariance Decomposition (`CovTot = CovBtw + CovWtn`). This
ensures the displayed total correlation remains mathematically accurate.
4. **Dual Display Modes:** The indicator offers two modes to
visualize this decomposition:
- **Absolute Mode:** Displays the *Total Correlation* as the main
line, with the background filled by the stacked components
(Between vs. Within). Shows the *magnitude* of the relationship.
- **Relative Mode:** Displays the **Energy Ratios** (-1.0 to 1.0)
of each component using L1-Normalization. This isolates the
*structure/quality* of the relationship (e.g., "Is the correlation
driven by price movement or just by volatility coupling?").
5. **Calculation Options:**
- **Normalization:** An optional 'Normalize' setting
calculates an **Exponential Regression Curve** (log-space),
creating a constant percentage variance environment. Essential
for comparing assets with different scales (e.g., BTC vs EURUSD).
- **Volume Weighting:** An option (`Volume weighted`) applies
volume weighting to all mean and covariance calculations.
6. **Correlation Cycle Analysis:**
- **Pivot Detection:** Includes a built-in pivot detector
that identifies significant turning points (highs and lows) in
the *Total Correlation* line. (Note: This is only visible
in 'Absolute Mode').
- **Flexible Pivot Algorithms:** Supports various underlying
mathematical models for pivot detection provided by the
core library.
7. **Note on Confirmation (Lag):** Pivot signals are confirmed
using a lookback method. A pivot is only plotted *after*
the `Pivot Right Bars` input has passed, which introduces
an inherent lag.
8. **Multi-Timeframe (MTF) Capability:**
- **MTF Correlation Lines:** The correlation lines can be
calculated on a higher timeframe, with standard options
to handle gaps (`Fill Gaps`) and prevent repainting
(`Wait for...`).
- **Limitation:** The Pivot detection (`Calculate Pivots`) is
**disabled** if a Higher Timeframe (HTF) is selected.
9. **Integrated Alerts:** Includes comprehensive alerts for:
- Correlation magnitude (High Positive / High Inverse).
- Character changes (Inter-Bar vs. Intra-Bar dominance).
- Total Correlation pivot (High/Low) detection.
---
**DISCLAIMER**
1. **For Informational/Educational Use Only:** This indicator is
provided for informational and educational purposes only. It does
not constitute financial, investment, or trading advice, nor is
it a recommendation to buy or sell any asset.
2. **Use at Your Own Risk:** All trading decisions you make based on
the information or signals generated by this indicator are made
solely at your own risk.
3. **No Guarantee of Performance:** Past performance is not an
indicator of future results. The author makes no guarantee
regarding the accuracy of the signals or future profitability.
4. **No Liability:** The author shall not be held liable for any
financial losses or damages incurred directly or indirectly from
the use of this indicator.
5. **Signals Are Not Recommendations:** The alerts and visual signals
(e.g., crossovers) generated by this tool are not direct
recommendations to buy or sell. They are technical observations
for your own analysis and consideration.
assets by decomposing the Total Correlation into two distinct,
interpretable components: "Between-Bar" (Inter-Bar) and
"Within-Bar" (Intra-Bar) correlation.
Key Features:
1. **Hybrid Copula Estimator:** Unlike standard correlation, which
often fails on High/Low range data, this indicator fuses two
metrics to ensure mathematical rigor:
- **Magnitude:** Derived from Rogers-Satchell Volatility.
- **Direction:** Derived from Log-Returns.
This allows for precise correlation estimates even on intra-bar data.
2. **Two-Component Correlation Decomposition:** The indicator
separates correlation based on the 'Estimate Bar Statistics' option.
- **Standard Mode (`Estimate Bar Statistics` = OFF):** Calculates
correlation based on the selected `Source` (Close-to-Close).
- **Decomposition Mode (`Estimate Bar Statistics` = ON):** The
indicator uses a statistical model ('Estimator') to
calculate *within-bar* correlation.
This separates the relationship into:
- **Between-Bar Correlation (Green/Red):** Correlation of the
price paths (means). Indicates if the macro movements of the
assets are aligned (Inter-Bar correlation).
- **Within-Bar Correlation (Blue):** Correlation of the
microstructure (Intra-Bar volatility/noise).
3. **Visual Decomposition Logic:** Total Correlation is the
primary metric displayed. Since Correlation Coefficients are not
linearly additive, this indicator calculates the *exact* Total
Correlation and partitions the area/ratios based on the additive
Covariance Decomposition (`CovTot = CovBtw + CovWtn`). This
ensures the displayed total correlation remains mathematically accurate.
4. **Dual Display Modes:** The indicator offers two modes to
visualize this decomposition:
- **Absolute Mode:** Displays the *Total Correlation* as the main
line, with the background filled by the stacked components
(Between vs. Within). Shows the *magnitude* of the relationship.
- **Relative Mode:** Displays the **Energy Ratios** (-1.0 to 1.0)
of each component using L1-Normalization. This isolates the
*structure/quality* of the relationship (e.g., "Is the correlation
driven by price movement or just by volatility coupling?").
5. **Calculation Options:**
- **Normalization:** An optional 'Normalize' setting
calculates an **Exponential Regression Curve** (log-space),
creating a constant percentage variance environment. Essential
for comparing assets with different scales (e.g., BTC vs EURUSD).
- **Volume Weighting:** An option (`Volume weighted`) applies
volume weighting to all mean and covariance calculations.
6. **Correlation Cycle Analysis:**
- **Pivot Detection:** Includes a built-in pivot detector
that identifies significant turning points (highs and lows) in
the *Total Correlation* line. (Note: This is only visible
in 'Absolute Mode').
- **Flexible Pivot Algorithms:** Supports various underlying
mathematical models for pivot detection provided by the
core library.
7. **Note on Confirmation (Lag):** Pivot signals are confirmed
using a lookback method. A pivot is only plotted *after*
the `Pivot Right Bars` input has passed, which introduces
an inherent lag.
8. **Multi-Timeframe (MTF) Capability:**
- **MTF Correlation Lines:** The correlation lines can be
calculated on a higher timeframe, with standard options
to handle gaps (`Fill Gaps`) and prevent repainting
(`Wait for...`).
- **Limitation:** The Pivot detection (`Calculate Pivots`) is
**disabled** if a Higher Timeframe (HTF) is selected.
9. **Integrated Alerts:** Includes comprehensive alerts for:
- Correlation magnitude (High Positive / High Inverse).
- Character changes (Inter-Bar vs. Intra-Bar dominance).
- Total Correlation pivot (High/Low) detection.
---
**DISCLAIMER**
1. **For Informational/Educational Use Only:** This indicator is
provided for informational and educational purposes only. It does
not constitute financial, investment, or trading advice, nor is
it a recommendation to buy or sell any asset.
2. **Use at Your Own Risk:** All trading decisions you make based on
the information or signals generated by this indicator are made
solely at your own risk.
3. **No Guarantee of Performance:** Past performance is not an
indicator of future results. The author makes no guarantee
regarding the accuracy of the signals or future profitability.
4. **No Liability:** The author shall not be held liable for any
financial losses or damages incurred directly or indirectly from
the use of this indicator.
5. **Signals Are Not Recommendations:** The alerts and visual signals
(e.g., crossovers) generated by this tool are not direct
recommendations to buy or sell. They are technical observations
for your own analysis and consideration.
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.