# R-Squared (R^2)

R-squared is a statistical measure of how close the data are to the fitted regression line. It is also known as the coefficient of determination, or the coefficient of multiple determination for multiple regression.

R-squared runs from 0 to 1 with 0 meaning the linear regression does not fit the data at all and 1 meaning the linear regression fits the data perfectly.

Of Price |
`((x + 1) / 2 * (FAVGCx.z - AVGCx.z) / SQR((x ^ 2 - 1) * (AVG(Cz ^ 2, x) - AVGCx.z ^ 2) / 12)) ^ 2` |
`w` =Formula, `x` =Period,`z` =Offset |

Generalized |
`((x + 1) / 2 * (FAVG(w, x) - AVG(w, x)) / SQR((x ^ 2 - 1) * (AVG((w ) ^ 2, x) - AVG(w, x) ^ 2) / 12)) ^ 2` |

Where w is any formula returning a numeric value.

Where x is the period which must be an integer.

Where z is the offset. 1 would be 1 bar ago.

A 20 period R-Squared of price can be written as follows.

`((20 + 1) / 2 * (FAVGC20 - AVGC20) / SQR((20 ^ 2 - 1) * (AVG(C ^ 2, 20) - AVGC20 ^ 2) / 12)) ^ 2`

A 30 period R-Squared of MACD 12,26 can be written as follows.

`((30 + 1) / 2 * (FAVG(MACD12.26, 30) - AVG(MACD12.26, 30)) / SQR((30 ^ 2 - 1) * (AVG((MACD12.26 ) ^ 2, 30) - AVG(MACD12.26, 30) ^ 2) / 12)) ^ 2`