OPEN-SOURCE SCRIPT

Volume Weighted LR Correlation

69
This indicator analyzes the structural relationship between two
assets by decomposing the Total Correlation into three distinct,
interpretable components using a Weighted Linear Regression model
and a Hybrid Copula Estimator.

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 (robust to trend).
- **Direction:** Derived from Log-Returns.
This allows for precise correlation estimates even on intra-bar data.

2. **Three-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`.
- **Decomposition Mode (`Estimate Bar Statistics` = ON):** The
indicator uses a statistical model ('Estimator') to
calculate *within-bar* correlation.
This separates the relationship into:
- **Trend Correlation (Green/Red):** Correlation of the regression
slopes. Indicates if assets are trending in the same direction.
- **Residual Correlation (Yellow):** Correlation of the noise
around the trend (Cointegration). Indicates if assets
mean-revert together, even if trends differ.
- **Within-Bar Correlation (Blue):** Correlation of the
microstructure (intra-bar volatility).

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. 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
(Trend, Residual, 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 Trend or just by Noise?").

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 regression 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.
- **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).
- Correlation character changes/emerging/fading.
- 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.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.