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.
---
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.