R2

Category: Indicators

The R2 function in ProBuilder language calculates the R-Squared value, which is a statistical measure of how well the regression predictions approximate the real data points. An R-Squared value is used in trading to determine the strength of a trend based on linear regression over a specified number of periods. The closer the value is to 1, the stronger the trend.

Syntax:

R2[N](price)

Where N represents the number of periods over which the R-Squared value is calculated, and price indicates the price series used in the calculation.

Example:

i1 = R2[20](close)
LR1 = linearregression[20](close)
LR2 = linearregression[20](close[1])

if(i1 > 0.4 AND LR1 < LR2) THEN
    bullish = 0
    bearish = -1
ELSIF(i1 > 0.4 AND LR1 > LR2) THEN
    bullish = 1
    bearish = 0
ELSE
    bullish = 0
    bearish = 0
ENDIF

RETURN bullish, bearish

In this example, the R-Squared value is calculated over the last 20 periods of the close price. The script then compares the current linear regression value (LR1) with the previous period’s linear regression value (LR2). Depending on the R-Squared value and the comparison of LR1 and LR2, the script sets the bullish and bearish indicators.

  • R2[N](price): Calculates the R-Squared value which indicates the goodness of fit of a linear regression model.
  • linearregression[N](price): Computes the value of a linear regression line over N periods for the given price.
  • The condition checks if the trend strength is significant (i1 > 0.4) and determines the trend direction based on the slope of the regression line.

This function is particularly useful for traders who use statistical methods to validate the strength of trends and make informed decisions based on historical price movements.

Related Instructions:

Logo Logo
Loading...