ta.linreg()Linear Regression
Computes the value of the linear regression line fitted to the source over the last length bars at a given offset. It summarizes the best-fit straight-line trend through the window and can project forward or backward along that line.
Syntax
ta.linreg(source, length, offset) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
| length | series int | Number of bars used for the regression window. |
| offset | simple int | Offset along the regression line; default 0. |
Returns
Linear regression curve value.
Remarks
na values in the source series are ignored.
Code Examples
//@version=6
indicator("ta.linreg")
plot(ta.linreg(close, 20, 0))Trading Applications
Fit a linear trend line to recent price data
Predict future price direction based on regression slope
Identify overbought/oversold when price deviates from regression
Use as a dynamic trend channel center line
Frequently Asked Questions
Generate ta.linreg() Code with AI
Draft Pine Script using ta.linreg() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
Related Pine Script Functions
ta.sma() - Simple Moving Average
Learn how to use ta.sma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Simple Moving Average function.
ta.ema() - Exponential Moving Average
Learn how to use ta.ema() in Pine Script. Syntax, parameters, code examples, and trading applications for the Exponential Moving Average function.
ta.alma() - Arnaud Legoux Moving Average
Learn how to use ta.alma() in Pine Script. Syntax, parameters including offset and sigma, code examples for ALMA.
ta.stdev() - Standard Deviation
Learn how to use ta.stdev() in Pine Script. Syntax, parameters, code examples for statistical standard deviation calculation.
ta.correlation() - Correlation
Learn how to use ta.correlation() in Pine Script. Calculate correlation coefficient between two series.