OPEN-SOURCE SCRIPT
Relative Strength Ratio • Leader Shift Signals

## Overview
This indicator computes a **Relative Strength (RS) ratio** between your chart’s symbol and a reference symbol (e.g. BTC or index), then overlays an EMA-based trend filter and detects **RS divergences** via RSI on that ratio. It highlights when your symbol is leading vs lagging, and spots potential turning points via bullish/negative divergences. No alerts are forced, you get visual cues (lines & labels) only.
---
## How It Works
1. **RS Ratio** = (base symbol price) ÷ (reference symbol price).
2. Two EMAs (fast & slow) filter trend context and help identify “leader shifts” (when ratio crosses the fast EMA under trend constraints).
3. **RSI on the ratio** is used to detect divergences. We find swing highs/lows in the *ratio* and compare their RSI values:
* **Bearish RS divergence**: ratio makes a higher high, but RSI makes a lower high
* **Bullish RS divergence**: ratio makes a lower low, but RSI makes a higher low
4. When divergence is confirmed, the script draws connecting lines (and optional markers) on the RS ratio pane to visually flag them.
5. You can customize pivot sensitivity, minimum separation, colors, and toggles for which graphics to show.
---
## Best Usage Suggestions
* Use a **reference symbol** that is meaningfully related (e.g. BTC for altcoins, SPX for equities, or a sector index for a stock). The interpretive power comes from seeing relative strength vs a meaningful peer.
* On **higher timeframes** (4H, daily), divergences tend to carry more weight. On lower intraday charts, tighten pivot settings to avoid noise.
* Prefer divergence signals when the RS ratio is also in a favorable trend (e.g. above its EMA for bullish divergences, below for bearish). Using the trend filter EMAs helps reduce false signals.
* Always confirm divergence signals with **price structure, volume, or other momentum indicators**. Divergence is a warning or a hint—not a standalone trigger.
* Because RSI on ratio is subject to noise, avoid over-tuning pivots too tight; broader pivot widths give more robust divergence lines.
---
## Inputs & Customization
* **Reference Symbol & Timeframe** for ratio comparison
* **Fast EMA / Slow EMA lengths** and slope threshold (trend filter)
* **RSI length** applied to the RS ratio
* **Pivot left / right bars** and **min separation** to define sturdy swings
* **Toggle lines / markers** visibility, and pick colors for divergence, ratio, EMAs
* Optional “shade” or fill modes (if you have them)
---
## Limitations & Disclaimers
* Divergence does **not guarantee** reversals—it often signals **weakening momentum or potential turning zones**, which may not always play out.
* In extremely volatile or fast-moving markets, divergence lines may lag or fail.
* The script relies on historical data (no future lookahead). Because pivots are confirmed after a few bars, some signals show with delay.
* As always: combine with price action, structure, risk management. This is a tool—not a magic eight ball.
---
This indicator computes a **Relative Strength (RS) ratio** between your chart’s symbol and a reference symbol (e.g. BTC or index), then overlays an EMA-based trend filter and detects **RS divergences** via RSI on that ratio. It highlights when your symbol is leading vs lagging, and spots potential turning points via bullish/negative divergences. No alerts are forced, you get visual cues (lines & labels) only.
---
## How It Works
1. **RS Ratio** = (base symbol price) ÷ (reference symbol price).
2. Two EMAs (fast & slow) filter trend context and help identify “leader shifts” (when ratio crosses the fast EMA under trend constraints).
3. **RSI on the ratio** is used to detect divergences. We find swing highs/lows in the *ratio* and compare their RSI values:
* **Bearish RS divergence**: ratio makes a higher high, but RSI makes a lower high
* **Bullish RS divergence**: ratio makes a lower low, but RSI makes a higher low
4. When divergence is confirmed, the script draws connecting lines (and optional markers) on the RS ratio pane to visually flag them.
5. You can customize pivot sensitivity, minimum separation, colors, and toggles for which graphics to show.
---
## Best Usage Suggestions
* Use a **reference symbol** that is meaningfully related (e.g. BTC for altcoins, SPX for equities, or a sector index for a stock). The interpretive power comes from seeing relative strength vs a meaningful peer.
* On **higher timeframes** (4H, daily), divergences tend to carry more weight. On lower intraday charts, tighten pivot settings to avoid noise.
* Prefer divergence signals when the RS ratio is also in a favorable trend (e.g. above its EMA for bullish divergences, below for bearish). Using the trend filter EMAs helps reduce false signals.
* Always confirm divergence signals with **price structure, volume, or other momentum indicators**. Divergence is a warning or a hint—not a standalone trigger.
* Because RSI on ratio is subject to noise, avoid over-tuning pivots too tight; broader pivot widths give more robust divergence lines.
---
## Inputs & Customization
* **Reference Symbol & Timeframe** for ratio comparison
* **Fast EMA / Slow EMA lengths** and slope threshold (trend filter)
* **RSI length** applied to the RS ratio
* **Pivot left / right bars** and **min separation** to define sturdy swings
* **Toggle lines / markers** visibility, and pick colors for divergence, ratio, EMAs
* Optional “shade” or fill modes (if you have them)
---
## Limitations & Disclaimers
* Divergence does **not guarantee** reversals—it often signals **weakening momentum or potential turning zones**, which may not always play out.
* In extremely volatile or fast-moving markets, divergence lines may lag or fail.
* The script relies on historical data (no future lookahead). Because pivots are confirmed after a few bars, some signals show with delay.
* As always: combine with price action, structure, risk management. This is a tool—not a magic eight ball.
---
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.