Skip to main content

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

ParameterTypePurpose
xseriesInput series, taken into calculation
nintegerNumber of bars to calculate the regression
offsetnumericRegression offset

Returns: series.

Example

linear_regression = linreg(close, 25, 2)

Formula

The formula for calculating the linreg function is:

image.png

The function is calculated using the least squares method.