CoefficientR (Function)
The CoefficientR function calculates the Pearson product moment correlation coefficient, R.
The Pearson product coefficient, R, is a dimensionless index that ranges from -1.0 to 1.0 inclusive and reflects the extent of a linear relationship between Price and a dependent value for a specified period.
Pearson's product moment correlation coefficient, usually denoted by R, is one example of a correlation coefficient. It is a measure of the linear association between two variables that have been measured on interval or ratio scales.
A correlation coefficient is a number between -1 and 1, which measures the degree to which two variables are linearly related. If there is a perfect linear relationship with positive slope between the two variables, we have a correlation coefficient of 1; if there is a positive correlation, whenever one variable has a high (low) value, the other does also. If there is a perfect linear relationship with negative slope between the two variables, we have a correlation coefficient of -1; if there is a negative correlation, whenever one variable has a high (low) value, the other has a low (high) value. A correlation coefficient of 0 means that there is no linear relationship between the variables.
Syntax
CoefficientR(Indep,Dep,Length)
Returns (Double)
A numeric value between 1 and –1, for the current bar. If no value is calculated, the function returns (-2).
Parameters
|
Name |
Type |
Description |
|
Indep |
Numeric |
Specifies which independent bar value (price, function, or formula) to be considered when calculating coefficient R. |
|
Dep |
Numeric |
Specifies which dependent bar value (price, function, or formula) to be considered when calculating coefficient R. |
|
Length |
Numeric |
Set the number of bars to consider in the calculation of R. |
Remarks
Under certain circumstances the function may not calculate a value for CoefficientR for the current bar. When this happens the function returns –2. You may want to check for this value and not plot for the current bar. Also, if you are looking for negative correlation you may want to add range checking. For example, if R < -.75 AND R > -1.01 then …
The value for the Length input parameter should always be a whole number greater than 0.
Example
Assigns the CoefficientR of the Close to BarNumber over 20 bars to Value1, then plots a ShowMe on the High when Value1 is greater than .75:
Value1 = CoefficientR(BarNumber, Close, 20);
if Value1 > .75 then
Plot1(High, "CoefR");