The LinearRegressionSlope function in ProBuilder language calculates the slope of the linear regression line over a specified number of periods for a given price series. This indicator is primarily used to determine the direction and strength of a trend. A positive slope indicates an uptrend, while a negative slope suggests a downtrend. The magnitude of the slope gives an idea of the trend’s strength.
LinearRegressionSlope[N](price)
Where N is the number of periods over which the linear regression is calculated, and price refers to the price series used (e.g., close, open, high, low).
i1 = LinearRegressionSlope[10](close)
IF(i1 > 0 AND i1[1] < 0) THEN
bullish = 1
bearish = 0
ELSIF(i1 < 0 AND i1[1] > 0) THEN
bullish = 0
bearish = -1
ELSE
bullish = 0
bearish = 0
ENDIF
RETURN bullish, bearish
This example calculates the Linear Regression Slope of the closing prices over the last 10 periods. It then checks if the slope has changed from negative to positive (indicating a potential uptrend) or from positive to negative (indicating a potential downtrend), and assigns values to bullish and bearish accordingly.