linreg

forge.tafunctionSince Forge API 1
Functionpython
forge.ta.linreg(source: ArrayLike, period: int = 14) -> np.ndarray

The regression line at the newest bar of the window: a + b * (period - 1).

Parameters

NameTypeDefault
sourceArrayLike
periodint14

Indicator: Linear regression

Classpython
forge.ta.LinReg(**inputs: Any) -> None

Least squares line fitted to the last N values, read at the newest bar.

Inputs

NameTypeDefaultRange
sourcesourceclose
periodint142 to 5000

Fit a straight line by least squares to the last period values, with t = 0 at the oldest.

b = (period * sum(t*y) - sum(t) * sum(y)) / (period * sum(t^2) - sum(t)^2)

a = (sum(y) - b * sum(t)) / period

LinReg = a + b * (period - 1)