OPEN-SOURCE SCRIPT
L-TPI Correlation Assets

# L-TPI Correlation Assets
A composite trend-probability indicator that scores the current asset's directional bias and **scales that score by its rolling correlation to Bitcoin (INDEX:BTCUSD)**. The result is a single weighted signal that strengthens when the asset is moving with BTC and fades toward neutral when the relationship breaks down.
---
## Concept
Most trend indicators tell you *what* an asset is doing. This one asks a second question: *how much does that signal matter right now, given the asset's relationship to the broader crypto market?*
The script does this in three stages:
1. **Trend Probability Index (TPI)** — a 4-filter composite that produces a normalized trend score in the range `[-1, +1]`.
2. **Multi-Period Correlation Weight** — a weighted average of the asset's price correlation to BTC across five lookback windows.
3. **Final Weighted Score** — the TPI multiplied by the correlation weight, with a configurable neutral zone around zero.
---
## 1. Trend Probability Index (TPI)
Four independent filters each cast a vote of `+1` (bullish) or `-1` (bearish):
| Filter | Logic | Bullish When |
|---|---|---|
| **f1 — ROC** | Rate of Change over *N* bars | ROC > 1 |
| **f2 — RSI** | Relative Strength Index | RSI > 50 |
| **f3 — EMA Cross** | Fast EMA vs. Slow EMA | Fast > Slow |
| **f4 — SMA** | Price vs. long SMA | Close > SMA |
- **Raw Trend Score** = `f1 + f2 + f3 + f4` → integer in `[-4, +4]`
- **Avg Trend Score** = `Raw / 4` → normalized to `[-1, +1]`
The Avg Trend Score is the TPI value passed forward.
---
## 2. Correlation Weight (vs. INDEX:BTCUSD)
The script computes the **Pearson correlation coefficient** between the chart asset's close and BTC's close across **five user-defined lookback windows** (default 30, 60, 90, 180, 365 bars). Each window has its own user weight (default 1, 2, 3, 4, 5 — favoring longer horizons).
For each window:
- Validity is checked: a window must have at least *Min valid obs ratio* (default 80%) of aligned, non-`na` bars.
- Invalid windows are excluded from the weighted average.
The final weight is a clamped weighted mean:
```
weight = clamp( Σ(corr_i × user_weight_i) / Σ(user_weight_i), -1, +1 )
```
BTC is fetched via `ticker.modify` so dividend/session adjustments on the chart propagate to the comparison series.
---
## 3. Final Weighted Score
```
final_weighted_score = avg_trend_score × weight
```
- **Range:** `[-1, +1]`
- **Strong bullish:** TPI is bullish *and* asset moves with BTC → score pushes toward +1
- **Strong bearish:** TPI is bearish *and* asset moves with BTC → score pushes toward −1
- **Neutral / decoupled:** TPI is mixed *or* correlation is weak → score collapses toward 0
A configurable **neutral zone** (default `±0.02`) flags conditions where the signal is too weak to act on.
---
## Visual Output
- **Final Weighted Score** — bold line; green above 0, red below, yellow in the neutral zone.
- **Correlation Weight** — stepline showing the current BTC-correlation multiplier.
- **Raw / Avg Trend Score** — the underlying TPI before correlation weighting.
- **Per-window correlations** — optional plots for the 30/60/90/180/365-bar `r` values.
- **Neutral zone** — optional background tint, threshold lines, and diamond marker.
- **Underlying filters** — ROC, RSI, EMAs, SMA can each be plotted individually.
### Tables
- **Signal Table** — every filter's state, raw/avg trend, correlation weight, final score, and overall bull/bear/neutral state.
- **Correlation Diagnostic Table** — per-window `r`, user weight, validity status, and resolved comparison symbol.
- **Final Score Table** — large display of the final weighted score for clean screenshots / streaming.
All tables have configurable positions.
---
## Inputs Overview
| Group | Key Inputs |
|---|---|
| Global | Timeframe |
| Neutral Zone | Low / High thresholds |
| ROC, RSI, EMA, SMA | Lengths for each filter |
| Correlation Weight | 5 × (period, weight), min valid obs ratio |
| Plot Toggles | Per-component visibility |
| Tables | Show/hide and positioning |
---
## How to Read It
- **Score > 0, rising, green:** trend filters and BTC correlation both supportive.
- **Score < 0, falling, red:** trend filters and BTC correlation both negative.
- **Score in yellow zone:** either filters are split, or the asset has decoupled from BTC — treat as no-trade.
- **Correlation weight near 0:** asset is currently uncorrelated with BTC; the trend signal is being intentionally muted.
---
## Notes & Limitations
- Comparison is hardcoded to `INDEX:BTCUSD`. Most useful on crypto and crypto-adjacent assets.
- Correlation is computed on **raw closes**, not returns. This produces smoother, more persistent `r` values that emphasize co-movement of price levels rather than short-term return co-movement.
- The TPI uses a fixed equal-weight blend of ROC, RSI, EMA cross, and SMA. It's a deliberately simple base; the correlation weighting is where the differentiation comes from.
- Designed for higher timeframes (default 1D). Works on lower TFs but the long correlation windows (e.g. 365 bars) become short in calendar time.
---
*Not financial advice. Always backtest and validate on your own instruments and timeframe before using any indicator for live decisions.*
A composite trend-probability indicator that scores the current asset's directional bias and **scales that score by its rolling correlation to Bitcoin (INDEX:BTCUSD)**. The result is a single weighted signal that strengthens when the asset is moving with BTC and fades toward neutral when the relationship breaks down.
---
## Concept
Most trend indicators tell you *what* an asset is doing. This one asks a second question: *how much does that signal matter right now, given the asset's relationship to the broader crypto market?*
The script does this in three stages:
1. **Trend Probability Index (TPI)** — a 4-filter composite that produces a normalized trend score in the range `[-1, +1]`.
2. **Multi-Period Correlation Weight** — a weighted average of the asset's price correlation to BTC across five lookback windows.
3. **Final Weighted Score** — the TPI multiplied by the correlation weight, with a configurable neutral zone around zero.
---
## 1. Trend Probability Index (TPI)
Four independent filters each cast a vote of `+1` (bullish) or `-1` (bearish):
| Filter | Logic | Bullish When |
|---|---|---|
| **f1 — ROC** | Rate of Change over *N* bars | ROC > 1 |
| **f2 — RSI** | Relative Strength Index | RSI > 50 |
| **f3 — EMA Cross** | Fast EMA vs. Slow EMA | Fast > Slow |
| **f4 — SMA** | Price vs. long SMA | Close > SMA |
- **Raw Trend Score** = `f1 + f2 + f3 + f4` → integer in `[-4, +4]`
- **Avg Trend Score** = `Raw / 4` → normalized to `[-1, +1]`
The Avg Trend Score is the TPI value passed forward.
---
## 2. Correlation Weight (vs. INDEX:BTCUSD)
The script computes the **Pearson correlation coefficient** between the chart asset's close and BTC's close across **five user-defined lookback windows** (default 30, 60, 90, 180, 365 bars). Each window has its own user weight (default 1, 2, 3, 4, 5 — favoring longer horizons).
For each window:
- Validity is checked: a window must have at least *Min valid obs ratio* (default 80%) of aligned, non-`na` bars.
- Invalid windows are excluded from the weighted average.
The final weight is a clamped weighted mean:
```
weight = clamp( Σ(corr_i × user_weight_i) / Σ(user_weight_i), -1, +1 )
```
BTC is fetched via `ticker.modify` so dividend/session adjustments on the chart propagate to the comparison series.
---
## 3. Final Weighted Score
```
final_weighted_score = avg_trend_score × weight
```
- **Range:** `[-1, +1]`
- **Strong bullish:** TPI is bullish *and* asset moves with BTC → score pushes toward +1
- **Strong bearish:** TPI is bearish *and* asset moves with BTC → score pushes toward −1
- **Neutral / decoupled:** TPI is mixed *or* correlation is weak → score collapses toward 0
A configurable **neutral zone** (default `±0.02`) flags conditions where the signal is too weak to act on.
---
## Visual Output
- **Final Weighted Score** — bold line; green above 0, red below, yellow in the neutral zone.
- **Correlation Weight** — stepline showing the current BTC-correlation multiplier.
- **Raw / Avg Trend Score** — the underlying TPI before correlation weighting.
- **Per-window correlations** — optional plots for the 30/60/90/180/365-bar `r` values.
- **Neutral zone** — optional background tint, threshold lines, and diamond marker.
- **Underlying filters** — ROC, RSI, EMAs, SMA can each be plotted individually.
### Tables
- **Signal Table** — every filter's state, raw/avg trend, correlation weight, final score, and overall bull/bear/neutral state.
- **Correlation Diagnostic Table** — per-window `r`, user weight, validity status, and resolved comparison symbol.
- **Final Score Table** — large display of the final weighted score for clean screenshots / streaming.
All tables have configurable positions.
---
## Inputs Overview
| Group | Key Inputs |
|---|---|
| Global | Timeframe |
| Neutral Zone | Low / High thresholds |
| ROC, RSI, EMA, SMA | Lengths for each filter |
| Correlation Weight | 5 × (period, weight), min valid obs ratio |
| Plot Toggles | Per-component visibility |
| Tables | Show/hide and positioning |
---
## How to Read It
- **Score > 0, rising, green:** trend filters and BTC correlation both supportive.
- **Score < 0, falling, red:** trend filters and BTC correlation both negative.
- **Score in yellow zone:** either filters are split, or the asset has decoupled from BTC — treat as no-trade.
- **Correlation weight near 0:** asset is currently uncorrelated with BTC; the trend signal is being intentionally muted.
---
## Notes & Limitations
- Comparison is hardcoded to `INDEX:BTCUSD`. Most useful on crypto and crypto-adjacent assets.
- Correlation is computed on **raw closes**, not returns. This produces smoother, more persistent `r` values that emphasize co-movement of price levels rather than short-term return co-movement.
- The TPI uses a fixed equal-weight blend of ROC, RSI, EMA cross, and SMA. It's a deliberately simple base; the correlation weighting is where the differentiation comes from.
- Designed for higher timeframes (default 1D). Works on lower TFs but the long correlation windows (e.g. 365 bars) become short in calendar time.
---
*Not financial advice. Always backtest and validate on your own instruments and timeframe before using any indicator for live decisions.*
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.