linreg
Syntax Format
linreg(x, n, offset)
Overview
The linreg function provides the linear regression curve for the given series over the n period – a line that best fits the prices specified over a time frame you indicated. The offset parameter can also be used to shift the line. The linreg function can be helpful in trend script indicators, showing trend direction and potential reversal points.
Parameters
| Parameter | Type | Purpose | 
|---|---|---|
| x | series | Input series, taken into calculation | 
| n | integer | Number of bars to calculate the regression | 
| offset | numeric | Regression offset | 
Returns: series.
Example
linear_regression = linreg(close, 25, 2)
Formula
The formula for calculating the linreg function is:

The function is calculated using the least squares method.