OPEN-SOURCE SCRIPT

Linear Regression Trendline on Close

281

This indicator draws a linear regression trendline that connects the closing prices of the last N candles, where N is a user-defined input.

🔹 Key Features:

Uses least-squares linear regression to fit a straight line to recent closes

Automatically adapts to any timeframe (5min, 1h, daily, etc.)

Input lets you select how many recent candles to include

Helps identify short-term trend direction and momentum

🔸 How to Use:

Set the "Number of Candles" input to choose how far back the regression line should look

The line updates in real time as new candles form

Use it to gauge short-term bias, or combine with support/resistance/zones for confirmation

🧠 Tip: Increase the number of candles for smoother trends; decrease for more reactive trendlines.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.