OPEN-SOURCE SCRIPT
更新済 Tri-Align Crypto Trend (EMA + Slope)

**Tri-Align Crypto Trend (EMA + Slope)**
Quickly see whether your coin is trending *with* Bitcoin. The indicator evaluates three pairs—**COIN/USDT**, **BTC/USDT**, and **COIN/BTC**—using a fast/slow EMA crossover plus the fast EMA’s slope. Each pair is tagged **Bullish / Bearish / Neutral** in a compact, color-coded table. Alerts fire when **all three** trends align (all bullish or all bearish).
**How to use**
1. Add the indicator to any crypto chart.
2. Set the three symbols (defaults: BNB/USDT, BTC/USDT, BNB/BTC) and optionally choose a signal timeframe.
3. Tune **Fast EMA**, **Slow EMA**, **Slope Lookback**, and **Min |Slope| %** to filter noise and require stronger momentum.
4. Create alerts: *Add alert →* choose the indicator and select **All Three Bullish**, **All Three Bearish**, or **All Three Aligned**.
**Logic**
* Bullish: `EMA_fast > EMA_slow` **and** fast EMA slope ≥ threshold
* Bearish: `EMA_fast < EMA_slow` **and** fast EMA slope ≤ −threshold
* Otherwise: Neutral
Tip: The **COIN/BTC** row reflects relative strength vs BTC—use it to avoid chasing coins that lag the benchmark. (For educational purposes; not financial advice.)
Quickly see whether your coin is trending *with* Bitcoin. The indicator evaluates three pairs—**COIN/USDT**, **BTC/USDT**, and **COIN/BTC**—using a fast/slow EMA crossover plus the fast EMA’s slope. Each pair is tagged **Bullish / Bearish / Neutral** in a compact, color-coded table. Alerts fire when **all three** trends align (all bullish or all bearish).
**How to use**
1. Add the indicator to any crypto chart.
2. Set the three symbols (defaults: BNB/USDT, BTC/USDT, BNB/BTC) and optionally choose a signal timeframe.
3. Tune **Fast EMA**, **Slow EMA**, **Slope Lookback**, and **Min |Slope| %** to filter noise and require stronger momentum.
4. Create alerts: *Add alert →* choose the indicator and select **All Three Bullish**, **All Three Bearish**, or **All Three Aligned**.
**Logic**
* Bullish: `EMA_fast > EMA_slow` **and** fast EMA slope ≥ threshold
* Bearish: `EMA_fast < EMA_slow` **and** fast EMA slope ≤ −threshold
* Otherwise: Neutral
Tip: The **COIN/BTC** row reflects relative strength vs BTC—use it to avoid chasing coins that lag the benchmark. (For educational purposes; not financial advice.)
リリースノート
**Tri-Align Crypto Trend (EMA + Slope + Strength)****What it does**
Checks whether your coin trends *with* Bitcoin by evaluating three pairs—**COIN/USDT**, **BTC/USDT**, **COIN/BTC**—on a chosen signal timeframe. Each pair is classified by fast/slow EMA structure **and** slope, shown in a compact table with a **Trend** label and a **Strength %** index. Alerts fire when all three pairs align (optionally only when they’re strong).
---
### Trend labels (how the regime is determined)
Let `F` = fast EMA, `S` = slow EMA; `sf`/`ss` = slopes of `F`/`S` over `slopeLen`.
Slopes are **positive / flat / negative** using a threshold `slopeThrPct`.
**Bull stack (F > S)**
* **Bull Acceleration**: `sf ↑` & `ss ↑`
* **Bull Pullback**: `sf ↓` & `ss ↑`
* **Bull Compression / Topping Risk**: `sf ↓` & `ss ↓`
* **Bull Re-ignite (Opposite)**: `sf ↑` & `ss ↓`
* **Bull Range-Above**: both flat
**Bear stack (F < S)**
* **Bear Acceleration**: `sf ↓` & `ss ↓`
* **Bear Rally (Countertrend)**: `sf ↑` & `ss ↓`
* **Bear Compression / Bottoming Risk**: `sf ↑` & `ss ↑`
* **Bear Re-assert (Opposite)**: `sf ↓` & `ss ↑`
* **Bear Range-Below**: both flat
For quick reading, the Trend cell is also color-coded: **green = bullish**, **red = bearish**, **yellow = neutral/transition** (pullbacks, rallies, ranges, compressions).
---
### Strength % (what the number means)
A **signed intensity score** for the current trend:
* **Positive** = bullish intensity, **Negative** = bearish intensity, **0%** = neutral/flat.
* Computed from two intuitive pieces (weights adjustable):
* **EMA gap %**: `100 * (F − S) / S` → structure
* **Fast EMA slope %**: `100 * (F − F[n]) / F` → momentum
* Composite (default): `wGap * |Gap%| + (1 − wGap) * |Slope%|`
Optional: **ATR-normalize** by `%ATR = 100 * ATR / close` to make values comparable across volatile pairs.
The **Strength** column shows this signed composite (rounded, with a heatmap background).
---
### Inputs (key)
Symbols, signal timeframe, `Fast/Slow EMA`, `Slope Lookback`, `Min |Slope| %`, plus strength controls: `Weight Gap`, `ATR-normalize`, `ATR Length`, and `Min |Strength|` for strong-alignment alerts.
---
### Alerts
* **All Three Bullish / Bearish**
* **All Three Aligned (Bull or Bear)**
* **All Aligned + Strong**: alignment **and** each row’s `|Strength| ≥ Min |Strength|`.
**Tip:** Watch **COIN/BTC** to gauge relative strength vs BTC; require **Aligned + Strong** to filter weak, low-quality moves.
リリースノート
**Tri-Align Crypto Trend (EMA + Slope + Strength)****What it does**
Checks whether your coin trends *with* Bitcoin by evaluating three pairs—**COIN/USDT**, **BTC/USDT**, **COIN/BTC**—on a chosen signal timeframe. Each pair is classified by fast/slow EMA structure **and** slope, shown in a compact table with a **Trend** label and a **Strength %** index. Alerts fire when all three pairs align (optionally only when they’re strong).
---
### Trend labels (how the regime is determined)
Let `F` = fast EMA, `S` = slow EMA; `sf`/`ss` = slopes of `F`/`S` over `slopeLen`.
Slopes are **positive / flat / negative** using a threshold `slopeThrPct`.
**Bull stack (F > S)**
* **Bull Acceleration**: `sf ↑` & `ss ↑`
* **Bull Pullback**: `sf ↓` & `ss ↑`
* **Bull Compression / Topping Risk**: `sf ↓` & `ss ↓`
* **Bull Re-ignite (Opposite)**: `sf ↑` & `ss ↓`
* **Bull Range-Above**: both flat
**Bear stack (F < S)**
* **Bear Acceleration**: `sf ↓` & `ss ↓`
* **Bear Rally (Countertrend)**: `sf ↑` & `ss ↓`
* **Bear Compression / Bottoming Risk**: `sf ↑` & `ss ↑`
* **Bear Re-assert (Opposite)**: `sf ↓` & `ss ↑`
* **Bear Range-Below**: both flat
For quick reading, the Trend cell is also color-coded: **green = bullish**, **red = bearish**, **yellow = neutral/transition** (pullbacks, rallies, ranges, compressions).
---
### Strength % (what the number means)
A **signed intensity score** for the current trend:
* **Positive** = bullish intensity, **Negative** = bearish intensity, **0%** = neutral/flat.
* Computed from two intuitive pieces (weights adjustable):
* **EMA gap %**: `100 * (F − S) / S` → structure
* **Fast EMA slope %**: `100 * (F − F[n]) / F` → momentum
* Composite (default): `wGap * |Gap%| + (1 − wGap) * |Slope%|`
Optional: **ATR-normalize** by `%ATR = 100 * ATR / close` to make values comparable across volatile pairs.
The **Strength** column shows this signed composite (rounded, with a heatmap background).
---
### Inputs (key)
Symbols, signal timeframe, `Fast/Slow EMA`, `Slope Lookback`, `Min |Slope| %`, plus strength controls: `Weight Gap`, `ATR-normalize`, `ATR Length`, and `Min |Strength|` for strong-alignment alerts.
---
### Alerts
* **All Three Bullish / Bearish**
* **All Three Aligned (Bull or Bear)**
* **All Aligned + Strong**: alignment **and** each row’s `|Strength| ≥ Min |Strength|`.
**Tip:** Watch **COIN/BTC** to gauge relative strength vs BTC; require **Aligned + Strong** to filter weak, low-quality moves.
リリースノート
**Tri-Align Crypto Trend (EMA + Slope + Strength)****What it does**
Checks whether your coin trends *with* Bitcoin by evaluating three pairs—**COIN/USDT**, **BTC/USDT**, **COIN/BTC**—on a chosen signal timeframe. Each pair is classified by fast/slow EMA structure **and** slope, shown in a compact table with a **Trend** label and a **Strength %** index. Alerts fire when all three pairs align (optionally only when they’re strong).
---
### Trend labels (how the regime is determined)
Let `F` = fast EMA, `S` = slow EMA; `sf`/`ss` = slopes of `F`/`S` over `slopeLen`.
Slopes are **positive / flat / negative** using a threshold `slopeThrPct`.
**Bull stack (F > S)**
* **Bull Acceleration**: `sf ↑` & `ss ↑`
* **Bull Pullback**: `sf ↓` & `ss ↑`
* **Bull Compression / Topping Risk**: `sf ↓` & `ss ↓`
* **Bull Re-ignite (Opposite)**: `sf ↑` & `ss ↓`
* **Bull Range-Above**: both flat
**Bear stack (F < S)**
* **Bear Acceleration**: `sf ↓` & `ss ↓`
* **Bear Rally (Countertrend)**: `sf ↑` & `ss ↓`
* **Bear Compression / Bottoming Risk**: `sf ↑` & `ss ↑`
* **Bear Re-assert (Opposite)**: `sf ↓` & `ss ↑`
* **Bear Range-Below**: both flat
For quick reading, the Trend cell is also color-coded: **green = bullish**, **red = bearish**, **yellow = neutral/transition** (pullbacks, rallies, ranges, compressions).
---
### Strength % (what the number means)
A **signed intensity score** for the current trend:
* **Positive** = bullish intensity, **Negative** = bearish intensity, **0%** = neutral/flat.
* Computed from two intuitive pieces (weights adjustable):
* **EMA gap %**: `100 * (F − S) / S` → structure
* **Fast EMA slope %**: `100 * (F − F[n]) / F` → momentum
* Composite (default): `wGap * |Gap%| + (1 − wGap) * |Slope%|`
Optional: **ATR-normalize** by `%ATR = 100 * ATR / close` to make values comparable across volatile pairs.
The **Strength** column shows this signed composite (rounded, with a heatmap background).
---
### Inputs (key)
Symbols, signal timeframe, `Fast/Slow EMA`, `Slope Lookback`, `Min |Slope| %`, plus strength controls: `Weight Gap`, `ATR-normalize`, `ATR Length`, and `Min |Strength|` for strong-alignment alerts.
---
### Alerts
* **All Three Bullish / Bearish**
* **All Three Aligned (Bull or Bear)**
* **All Aligned + Strong**: alignment **and** each row’s `|Strength| ≥ Min |Strength|`.
**Tip:** Watch **COIN/BTC** to gauge relative strength vs BTC; require **Aligned + Strong** to filter weak, low-quality moves.
リリースノート
# Tri-Align Crypto Trend (EMA + Slope)This document summarizes the `pine/multi-align.pine` indicator: what it computes, how it decides trend state, the available inputs, on-chart labeling and table behavior, and tuning notes.
## Purpose
Tri-Align is a compact trend/alignment indicator for crypto symbols. It evaluates trend alignment across three components:
- Coin / Quote (e.g. BTCUSDT or selected primary symbol)
- BTC / Quote (BTC benchmark)
- Coin / BTC (coin priced in BTC, or synthesized from coin/USDT and BTC/USDT when the direct pair is missing)
The indicator combines two signals per pair: a pair of moving averages (fast / slow) and a slope (momentum) estimate. It computes a composite "strength" from the MA gap and slope and reports per-symbol states (Bull / Bear / Neutral / Data NA), shows a small summary table, emits consolidated change labels on the chart, and offers alerts for global alignment states.
## Output
- Table (top-right) with rows for each tracked symbol: Pair, Trend (state text + optional emoji), and Strength %.
- On-chart consolidated change label(s) per bar: one bullish label above the candle and/or one bearish label below the candle listing which symbols changed on that bar (multi-line). Labels' nose points toward the candle to make association clear.
- Alerts for: All Bullish, All Bearish, Any Align (bull or bear), and All Aligned + Strong.
## Key inputs (high-level)
- `tf` (Signal timeframe): blank = chart timeframe
- `fastLen`, `slowLen` (fast/slow MA lengths)
- `maType` (MA engine for fast/slow): options DEMA (default), KAMA, EMA, SMA
- KAMA parameters: `kamaFastPeriod`, `kamaSlowPeriod` (used when KAMA selected)
- `slopeLen` (slope lookback), `slopeThrPct` (min |slope| %; 0 disables threshold)
- `atrNorm` / `atrLen` (normalize strength by ATR) and `minStrAbs` (min strength to consider "strong")
- Several toggles: include USDT/BTC dominance rows, auto-detect symbols, show EMAs, use emoji, etc.
(See the script inputs for full names and defaults.)
## How the indicator decides state (algorithm)
1. Moving averages (fast / slow) are computed for each tracked symbol in the chosen `maType`:
- DEMA uses TradingView's `tvta.dema(...)` implementation.
- KAMA uses an internal KAMA routine (converted from a Pine v4 reference) when selected.
- SMA / EMA use built-in `ta.sma` / `ta.ema`.
2. Slope calculation (momentum): the indicator computes a percent slope for the fast MA (and slow MA for context). The slope is expressed as a percentage of the MA value.
3. Composite strength: a weighted combination of the MA gap (gap% between fast and slow) and the slope magnitude is used:
composite = wGap * |gapPct| + (1 - wGap) * |slopePct|
Optionally this composite strength is normalized by ATR (if `atrNorm` is enabled) to yield percentage-of-price strength.
4. State rules per symbol:
- Bull stack (fast > slow) and slope sufficiently positive => Bull (state = 1)
- Bear stack (fast < slow) and slope sufficiently negative => Bear (state = -1)
- If the EMAs are stacked but slope/strength conditions are weaker, the script reports a Neutral stack state (state = 0).
- When data is missing for a symbol (invalid symbol / not available), the table shows "Data NA".
5. Adaptive slope thresholds (optional): you can enable dynamic thresholds that scale with volatility. The dynamic threshold is computed per-symbol as:
$dynThr = k * (ATR(atrLen) / close \times 100)$
If enabled, comparisons against slope use ±dynThr instead of a fixed `slopeThrPct`.
## Synthesizing Coin/BTC when a direct pair is missing
If the direct `COIN:BTC` pair is not available, the indicator will synthesize a coin/BTC series using the ratio:
- fastX = fast(COIN/USDT) / fast(BTC/USDT)
- slowX = slow(COIN/USDT) / slow(BTC/USDT)
- closeX = close(COIN/USDT) / close(BTC/USDT)
This synthesized series is evaluated with the same trend logic (slope, gap, strength). When ATR-normalization is requested for the synthetic ratio, the indicator requests ATR from a real symbol (e.g. the coin/USDT symbol) to avoid requesting ATR on a synthetic series.
## Labeling & UI behavior
- Change labels are recorded when the current non-zero meaningful state differs from the previous meaningful non-zero state (this avoids flicker from bull -> neutral -> bull).
- Multiple symbols that changed in the same direction on the same bar are consolidated into one multi-line label per direction (one up, one down) to reduce clutter.
- Bull labels are placed above the candle and use the label style with the nose pointing down; bear labels are placed below and point up.
- Primary fast/slow MAs can optionally be plotted on the chart.
## Alerts
- `All Symbols Bullish` — fires when all tracked symbols evaluate bullish.
- `All Symbols Bearish` — fires when all tracked symbols evaluate bearish.
- `All Symbols Aligned (Bull or Bear)` — fires when either all bullish or all bearish.
- `All Aligned + Strong` — fires when all aligned and each passes the minimum strength threshold `minStrAbs`.
Alert messages are short and designed for use with TradingView alert actions.
## Implementation notes & limitations
- DEMA is sourced from TradingView's `TradingView/ta/10` library (`tvta.dema`) to ensure correctness and consistency.
- KAMA is implemented locally (converted from Pine v4 reference). While tested for correctness, KAMA uses a recursive update and a loop for volatility computation; it is slightly heavier than simple EMA/DEMA.
- The slope and strength calculations use percent-of-price units to allow fair comparisons across assets of different nominal prices; enabling adaptive slope thresholds (`dynThr`) further scales decision thresholds by volatility (ATR) so small/large coins behave more consistently.
## Changelog
### v1.5.0 — MA engine selector and KAMA/DEMA support
- Added `maType` input to choose the moving-average engine for fast/slow MAs: `DEMA` (default), `KAMA`, `EMA`, or `SMA`.
- DEMA now uses TradingView's `TradingView/ta/10` library (`tvta.dema(...)`) for correctness.
- Implemented an internal KAMA routine (converted from a Pine v4 reference) and exposed KAMA alpha inputs `kamaFastPeriod` and `kamaSlowPeriod`.
- The trend evaluation, synthetic coin/BTC computation and primary MA plots now respect the selected `maType`.
## Tuning tips
- If you want earlier turn detection, try KAMA or DEMA for faster reaction (tweak KAMA fast/slow alpha inputs if using KAMA).
- If signals are noisy, increase `slopeLen` (smoother slope lookback) or raise `slopeThrPct` / enable `adaptiveSlopeThr` with a larger `k` multiplier.
- Use `atrNorm` when you want strength expressed relative to price volatility (helps compare strength across coins).
- If many symbols change simultaneously and the multi-line label gets too tall, consider enabling fewer symbols or add a line-limit for the label (possible enhancement).
リリースノート
# Tri-Align Crypto Trend (EMA + Slope)## Purpose
Tri-Align is a compact trend/alignment indicator for crypto symbols. It evaluates trend alignment across three components:
- Coin / Quote (e.g. BTCUSDT or selected primary symbol)
- BTC / Quote (BTC benchmark)
- Coin / BTC (coin priced in BTC, or synthesized from coin/USDT and BTC/USDT when the direct pair is missing)
The indicator combines two signals per pair: a pair of moving averages (fast / slow) and a slope (momentum) estimate. It computes a composite "strength" from the MA gap and slope and reports per-symbol states (Bull / Bear / Neutral / Data NA), shows a small summary table, emits consolidated change labels on the chart, and offers alerts for global alignment states.
## Key inputs (high-level)
- `tf` (Signal timeframe): blank = chart timeframe
- `fastLen`, `slowLen` (fast/slow MA lengths)
- `maType` (MA engine for fast/slow): options DEMA (default), KAMA, EMA, SMA
- KAMA parameters: `kamaFastPeriod`, `kamaSlowPeriod` (used when KAMA selected)
- `slopeLen` (slope lookback), `slopeThrPct` (min |slope| %; 0 disables threshold)
- `atrNorm` / `atrLen` (normalize strength by ATR) and `minStrAbs` (min strength to consider "strong")
- Several toggles: include USDT/BTC dominance rows, auto-detect symbols, show EMAs, use emoji, etc.
## Synthesizing Coin/BTC when a direct pair is missing
If the direct `COIN:BTC` pair is not available, the indicator will synthesize a coin/BTC series using the ratio:
- fastX = fast(COIN/USDT) / fast(BTC/USDT)
- slowX = slow(COIN/USDT) / slow(BTC/USDT)
- closeX = close(COIN/USDT) / close(BTC/USDT)
This synthesized series is evaluated with the same trend logic (slope, gap, strength). When ATR-normalization is requested for the synthetic ratio, the indicator requests ATR from a real symbol (e.g. the coin/USDT symbol) to avoid requesting ATR on a synthetic series.
## Residual Momentum (BTC-Hedged)
The indicator can optionally compute **residual momentum**, a measure of a coin's idiosyncratic out- or underperformance versus BTC after controlling for beta (market sensitivity).
### Concept
- **Standard COIN/BTC** assumes a fixed beta of 1: it directly compares price ratios and cannot distinguish between true alpha (unique performance) and changes in market beta.
- **Residual momentum** estimates the coin's true **beta relative to BTC** over a rolling window and removes the portion of coin returns explained by BTC movement. What remains is the coin's **idiosyncratic momentum**—whether it's outperforming or underperforming BTC independent of the broader market.
### Usage & integration
- **Enable**: Toggle `Include Residual Momentum (BTC-hedged)?` in inputs.
- **Controls**:
- `nBeta` (default 50): lookback window for rolling beta estimation. Larger values yield more stable betas; smaller values react faster.
- `nSignal` (default 20): lookback for momentum smoothing.
- `useZ` (default true): if true, uses Z-score normalization (volume-adjusted, unitless); if false, uses raw residual momentum in log-return % units.
- `zThr` (default 0.5): threshold for bullish (Z > zThr) or bearish (Z < −zThr) signal when using Z-score.
- `requireResidualAlign` (default false): if enabled, gates **all-aligned conditions** to require residual bullish or bearish confirmation, making the indicator more conservative.
### Table display
When enabled, a new row **"Residual vs BTC"** appears in the indicator table:
- **Trend column**: Bullish if residual momentum is positive (or Z > zThr), Bearish if negative (or Z < −zThr), Neutral otherwise.
- **Strength column**: displays the Z-score (if using Z-score) or the scaled raw residual momentum (% per bar).
- **Color**: Green for bullish residuals, red for bearish, gray if data is NA.
### Interpretation
- **Positive residual momentum**: the coin is outperforming BTC after removing market-beta effects → alpha.
- **Negative residual momentum**: the coin is underperforming BTC after beta-adjustment → potential weakness or divergence.
- **Residual + Tri-Align agreement**: confirms that the coin is not just moving with BTC, but has independent directional conviction.
### Caveats
- Beta estimates can be unstable in very low-volume or choppy periods; ensure sufficient history (nBeta ≥ 5).
- Residual momentum works best on longer timeframes (4h, daily+) where log-returns are more stable; on very low timeframes, log-returns may be noisy.
- Residuals are **not** a substitute for position sizing or risk management; they indicate *relative* momentum, not magnitude of move.
## Mean Reversion (RSI + Z-Score Extremes)
Mean reversion events detect when a price series has stretched to extremes—either overbought or oversold—based on two complementary metrics:
## Tuning tips
- If you want earlier turn detection, try KAMA or DEMA for faster reaction (tweak KAMA fast/slow alpha inputs if using KAMA).
- If signals are noisy, increase `slopeLen` (smoother slope lookback) or raise `slopeThrPct` / enable `adaptiveSlopeThr` with a larger `k` multiplier.
- Use `atrNorm` when you want strength expressed relative to price volatility (helps compare strength across coins).
- **Mean reversion tuning**: Lower `rsiThreshold` or `zscoreThreshold` for tighter, earlier extremes; raise them for delayed but fewer false signals. Increase `cooldownBars` if MR labels appear too frequently.
- If many symbols change simultaneously and the multi-line label gets too tall, consider enabling fewer symbols or add a line-limit for the label (possible enhancement).
リリースノート
# Tri-Align Crypto Trend (EMA + Slope)## Purpose
Tri-Align is a compact trend/alignment indicator for crypto symbols. It evaluates trend alignment across three components:
- Coin / Quote (e.g. BTCUSDT or selected primary symbol)
- BTC / Quote (BTC benchmark)
- Coin / BTC (coin priced in BTC, or synthesized from coin/USDT and BTC/USDT when the direct pair is missing)
The indicator combines two signals per pair: a pair of moving averages (fast / slow) and a slope (momentum) estimate. It computes a composite "strength" from the MA gap and slope and reports per-symbol states (Bull / Bear / Neutral / Data NA), shows a small summary table, emits consolidated change labels on the chart, and offers alerts for global alignment states.
## Key inputs (high-level)
- `tf` (Signal timeframe): blank = chart timeframe
- `fastLen`, `slowLen` (fast/slow MA lengths)
- `maType` (MA engine for fast/slow): options DEMA (default), KAMA, EMA, SMA
- KAMA parameters: `kamaFastPeriod`, `kamaSlowPeriod` (used when KAMA selected)
- `slopeLen` (slope lookback), `slopeThrPct` (min |slope| %; 0 disables threshold)
- `atrNorm` / `atrLen` (normalize strength by ATR) and `minStrAbs` (min strength to consider "strong")
- Several toggles: include USDT/BTC dominance rows, auto-detect symbols, show EMAs, use emoji, etc.
## Synthesizing Coin/BTC when a direct pair is missing
If the direct `COIN:BTC` pair is not available, the indicator will synthesize a coin/BTC series using the ratio:
- fastX = fast(COIN/USDT) / fast(BTC/USDT)
- slowX = slow(COIN/USDT) / slow(BTC/USDT)
- closeX = close(COIN/USDT) / close(BTC/USDT)
This synthesized series is evaluated with the same trend logic (slope, gap, strength). When ATR-normalization is requested for the synthetic ratio, the indicator requests ATR from a real symbol (e.g. the coin/USDT symbol) to avoid requesting ATR on a synthetic series.
## Residual Momentum (BTC-Hedged)
The indicator can optionally compute **residual momentum**, a measure of a coin's idiosyncratic out- or underperformance versus BTC after controlling for beta (market sensitivity).
### Concept
- **Standard COIN/BTC** assumes a fixed beta of 1: it directly compares price ratios and cannot distinguish between true alpha (unique performance) and changes in market beta.
- **Residual momentum** estimates the coin's true **beta relative to BTC** over a rolling window and removes the portion of coin returns explained by BTC movement. What remains is the coin's **idiosyncratic momentum**—whether it's outperforming or underperforming BTC independent of the broader market.
### Usage & integration
- **Enable**: Toggle `Include Residual Momentum (BTC-hedged)?` in inputs.
- **Controls**:
- `nBeta` (default 50): lookback window for rolling beta estimation. Larger values yield more stable betas; smaller values react faster.
- `nSignal` (default 20): lookback for momentum smoothing.
- `useZ` (default true): if true, uses Z-score normalization (volume-adjusted, unitless); if false, uses raw residual momentum in log-return % units.
- `zThr` (default 0.5): threshold for bullish (Z > zThr) or bearish (Z < −zThr) signal when using Z-score.
- `requireResidualAlign` (default false): if enabled, gates **all-aligned conditions** to require residual bullish or bearish confirmation, making the indicator more conservative.
### Table display
When enabled, a new row **"Residual vs BTC"** appears in the indicator table:
- **Trend column**: Bullish if residual momentum is positive (or Z > zThr), Bearish if negative (or Z < −zThr), Neutral otherwise.
- **Strength column**: displays the Z-score (if using Z-score) or the scaled raw residual momentum (% per bar).
- **Color**: Green for bullish residuals, red for bearish, gray if data is NA.
### Interpretation
- **Positive residual momentum**: the coin is outperforming BTC after removing market-beta effects → alpha.
- **Negative residual momentum**: the coin is underperforming BTC after beta-adjustment → potential weakness or divergence.
- **Residual + Tri-Align agreement**: confirms that the coin is not just moving with BTC, but has independent directional conviction.
### Caveats
- Beta estimates can be unstable in very low-volume or choppy periods; ensure sufficient history (nBeta ≥ 5).
- Residual momentum works best on longer timeframes (4h, daily+) where log-returns are more stable; on very low timeframes, log-returns may be noisy.
- Residuals are **not** a substitute for position sizing or risk management; they indicate *relative* momentum, not magnitude of move.
## Mean Reversion (RSI + Z-Score Extremes)
Mean reversion events detect when a price series has stretched to extremes—either overbought or oversold—based on two complementary metrics:
## Tuning tips
- If you want earlier turn detection, try KAMA or DEMA for faster reaction (tweak KAMA fast/slow alpha inputs if using KAMA).
- If signals are noisy, increase `slopeLen` (smoother slope lookback) or raise `slopeThrPct` / enable `adaptiveSlopeThr` with a larger `k` multiplier.
- Use `atrNorm` when you want strength expressed relative to price volatility (helps compare strength across coins).
- **Mean reversion tuning**: Lower `rsiThreshold` or `zscoreThreshold` for tighter, earlier extremes; raise them for delayed but fewer false signals. Increase `cooldownBars` if MR labels appear too frequently.
- If many symbols change simultaneously and the multi-line label gets too tall, consider enabling fewer symbols or add a line-limit for the label (possible enhancement).
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。