OPEN-SOURCE SCRIPT
已更新 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!
發行說明
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.
發行說明
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.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。