OPEN-SOURCE SCRIPT
已更新 LinReg SlopeChange

This indicator is a precise trend-following tool that tracks the acceleration (rate of change) in the price's linear regression curve. While a standard Linear Regression (LR) indicator simply shows the direction of the price, this tool focuses on detecting whether a trend is gaining momentum or exhausting by measuring the Slope Delta.
Here is a detailed guide explaining the technical structure, parameters, and usage of the indicator:
1. Core Calculation Logic
-The indicator processes market movements through a three-stage mathematical filter:
-Linear Regression (LR): It calculates the "best-fit" line for prices over a specified period (len).
-Slope Percentage (Slope %): It calculates the difference between the current LR value and the previous bar's LR value, expressed as a percentage of the current value.
-Slope Change (Slope Delta): This is the heart of the indicator. It calculates the difference between the current slope percentage and the previous bar's slope percentage. Mathematically, this acts as the "acceleration" (second derivative) of the price action.
2. Input Parameters
-LR Length : The number of lookback bars used for the regression calculation. Higher values lag more but provide more reliable signals.
-Slope Change Threshold (%) : The minimum slope change required to trigger a signal. This can be increased to avoid false signals in noisy (sideways) markets.
-Source : The price data used for calculations (Usually set to close).
3. Signals and Visualization
The indicator operates on a sequential signal logic, meaning it does not produce consecutive "BUY" or "SELL" signals; it waits for a trend reversal.
BUY Signal: Occurs when the momentum of the slope (Slope Delta) breaks above your defined threshold_chg. It is marked by a green triangle on the chart.
SELL Signal: Occurs when the slope momentum breaks below the negative threshold. It is marked by a red inverted triangle.
Background Color: Highlights the active trend by shading the "BUY" zone green and the "SELL" zone red.
4. Usage Strategies
A. Catching Trend Reversals
Because this indicator notices weakening in the slope before the price fully turns, it can respond faster than classic Moving Averages (MA). If the slope begins to decrease (negative delta) during an uptrend, it may serve as a leading signal of a potential peak.
B. Consolidations and Breakouts
When the price is moving sideways, the slope is near zero. Thanks to the Slope Change Threshold parameter, the indicator captures the surge in momentum when price breaks out of stagnation, confirming the start of a new trend.
C. Filtering
Using this indicator in conjunction with a volume indicator (e.g., RV) or an oscillator (like RSI) will increase the success rate. It is particularly powerful for determining trend direction on higher timeframes (4H, Daily).
Note: The threshold_chg (Threshold) parameter should be adjusted according to the volatility of the pair you are trading. For volatile assets like cryptocurrencies, keeping this value slightly higher will reduce "whipsaw" or false signals.
Here is a detailed guide explaining the technical structure, parameters, and usage of the indicator:
1. Core Calculation Logic
-The indicator processes market movements through a three-stage mathematical filter:
-Linear Regression (LR): It calculates the "best-fit" line for prices over a specified period (len).
-Slope Percentage (Slope %): It calculates the difference between the current LR value and the previous bar's LR value, expressed as a percentage of the current value.
-Slope Change (Slope Delta): This is the heart of the indicator. It calculates the difference between the current slope percentage and the previous bar's slope percentage. Mathematically, this acts as the "acceleration" (second derivative) of the price action.
2. Input Parameters
-LR Length : The number of lookback bars used for the regression calculation. Higher values lag more but provide more reliable signals.
-Slope Change Threshold (%) : The minimum slope change required to trigger a signal. This can be increased to avoid false signals in noisy (sideways) markets.
-Source : The price data used for calculations (Usually set to close).
3. Signals and Visualization
The indicator operates on a sequential signal logic, meaning it does not produce consecutive "BUY" or "SELL" signals; it waits for a trend reversal.
BUY Signal: Occurs when the momentum of the slope (Slope Delta) breaks above your defined threshold_chg. It is marked by a green triangle on the chart.
SELL Signal: Occurs when the slope momentum breaks below the negative threshold. It is marked by a red inverted triangle.
Background Color: Highlights the active trend by shading the "BUY" zone green and the "SELL" zone red.
4. Usage Strategies
A. Catching Trend Reversals
Because this indicator notices weakening in the slope before the price fully turns, it can respond faster than classic Moving Averages (MA). If the slope begins to decrease (negative delta) during an uptrend, it may serve as a leading signal of a potential peak.
B. Consolidations and Breakouts
When the price is moving sideways, the slope is near zero. Thanks to the Slope Change Threshold parameter, the indicator captures the surge in momentum when price breaks out of stagnation, confirming the start of a new trend.
C. Filtering
Using this indicator in conjunction with a volume indicator (e.g., RV) or an oscillator (like RSI) will increase the success rate. It is particularly powerful for determining trend direction on higher timeframes (4H, Daily).
Note: The threshold_chg (Threshold) parameter should be adjusted according to the volatility of the pair you are trading. For volatile assets like cryptocurrencies, keeping this value slightly higher will reduce "whipsaw" or false signals.
版本注释
timeframe版本注释
sign版本注释
I changed the calculation method. Now, instead of using average value of slope delta, indicator uses average of previous slope values.开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。