Skip to content

Linear Regression Slope

LINEARREG_SLOPE calculates the slope of the linear regression line.

Method

tm.ta.linearreg_slope(source, timeperiod)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
timeperiodintNumber of periods for the indicator14

Outputs

OutputType
linearreg_slopenp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Linear Regression Slope
linearreg_slope = tm.ta.linearreg_slope(data.close, timeperiod=14)
# Get the last value and print
last_value = linearreg_slope.iloc[-1]
tm.log(f"Last value of Linear Regression Slope is {last_value}")
# Plot the values of linearreg_slope
tm.plot(linearreg_slope, title="Linear Regression Slope", overlay=False)