Skip to content

LINEARREG_SLOPE

Summary

Slope 'm' of the least-squares best-fit line (y = b + m*x) over the last optInTimePeriod bars. Reports the per-bar rate of change of the fitted trend line. Positive slope = rising trend, negative = falling; magnitude is price change per bar.

Formula

m = (n·SumXY − SumX·SumY) / Divisor SumX = n(n−1)/2, SumXSqr = n(n−1)(2n−1)/6, Divisor = SumX² − n·SumXSqr SumXY = Σ i·y[today−i], SumY = Σ y[today−i], i=0..n−1, n=period, y=inReal

Inputs

  • inReal — Data series to fit

Outputs

  • outReal — Slope m of the fitted line

Parameters

  • optInTimePeriod — Number of bars in the regression window

Implementation

TA-Lib Definition: linearreg_slope.c · linearreg_slope.yaml

Native File
C ta_LINEARREG_SLOPE.c
Rust linearreg_slope.rs
Java Core.java

TA-Lib is also available for Python, R and more using a wrapper.

Aliases

Linear Regression Slope, LSMA slope, least squares slope

See Also

LINEARREG · LINEARREG_INTERCEPT · LINEARREG_ANGLE · TSF