Compare Strength with SLOPE

This indicator compares the relative strength between the current asset and a benchmark (e.g., BTC vs. ETH or AAPL vs. SPY) using a linear regression slope of their ratio over time.
The ratio is calculated as: close / benchmark
A linear regression slope is computed over a user-defined window
The slope represents trend strength: if it’s rising, the current asset is outperforming the benchmark
Plots
Gray Line: The raw ratio between the asset and benchmark
Orange Line: The slope of the ratio (shows momentum)
Background Color:
Green: The asset is significantly stronger than the benchmark
Red: The asset is significantly weaker than the benchmark
No color: No clear trend
Settings
Slope Window Length: Number of candles used in the regression (default = 10)
Slope Threshold: Sensitivity of trend detection. Smaller values detect weaker trends.
Example Use Cases
Style Rotation Strategy: Use the slope to determine whether "Growth" or "Value" style is leading.
Pair Trading / Relative Performance: Track which asset is leading in a pair (e.g., BTC vs ETH).
Factor Timing: Serve as a timing model to allocate between different sectors or factors.
Happy trading!
Purpose:
Compare the strength of the current asset to a benchmark (e.g. BTC vs ETH or stock vs index) by computing the linear regression slope of their price ratio.
Inputs:
Benchmark Symbol: Reference symbol to compare against.
Slope Window: Number of bars used to calculate the slope.
Threshold: Minimum slope magnitude to classify trend as meaningful.
Interpretation:
Red background: Current asset is trending stronger than the benchmark (positive slope).
Green background: Benchmark is outperforming the current asset (negative slope).
Gray ratio line: Displays the price ratio between current asset and benchmark.
Orange line: Shows the actual slope value over time.
This TradingView indicator compares the relative strength between the current chart asset and a selected benchmark asset. It uses the slope of the log-transformed ratio of the two price series to identify trend bias.
What’s New
We updated the calculation to use math.log(close / benchmark_close) instead of simple division. This log transformation ensures:
Scale invariance across vastly different asset price levels (e.g., BTC vs altcoins)
Symmetrical treatment of upward and downward movements
Smoother slope calculation for better trend sensitivity
Inputs
Symbol: The benchmark asset (e.g., BINANCE:BTCUSDT)
Length: Period used for slope calculation (default: 10)
Multiplier: A scaling factor applied to the log-ratio for better visibility (default: 1000)
Interpretation
Red background: The current asset is stronger than the benchmark (positive slope)
Green background: The current asset is weaker than the benchmark (negative slope)
Flat slope: No clear dominance, trend is neutral
Why Use Log-Ratio + Slope?
Using math.log(price / benchmark) provides a more reliable measure of relative price movement across assets with different nominal values. Applying a slope to this ratio allows us to determine which asset is gaining strength faster.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.