Correlation (Function)

image\trumpet2.gif Disclaimer

The Correlation function calculates the correlation coefficient between an independent and dependent data series.

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

Correlation(Indep,Dep,Length)

Returns (Double)

A numeric value between 1 and –1 for the current bar.

Parameters

Name Type Description
Indep Numeric Specifies which independent bar value (price, function, or formula) to be considered when calculating the correlation.   
Dep Numeric Specifies which dependent bar value (price, function, or formula) to be considered when calculating the correlation.   
Length Numeric Set the number of bars to consider in the correlation coefficient.

Remarks

The input parameters Indep and Dep can be a bar value such as Close, High, Low, Open, or Volume. They can also be any mathematical calculation such as High + Low) / 2, or a numeric function such as RSI, Stochastic, or ADX.

The value for the Length input parameter should always be a whole number greater than 0.

Example

Assigns the Correlation of 2 symbols over 20 bars to Value1; the Close of data1 to the Close of data2, then plots a ShowMe on the High when Value1 is greater than .75:

Value1 = Correlation (Close of Data1, Close of Data2, 20);
if Value1 > .75 then
Plot1
(High, "Corr");