OPEN-SOURCE SCRIPT
Telah dikemas kini Compare Strength with SLOPE

Description
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!
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!
Nota Keluaran
Indicator Name: Relative Strength SlopePurpose:
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.
Nota Keluaran
Indicator: Compare Strength (Slope-based)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.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.