Pearson Correlation Coefficient
Pearson Correlation Coefficient
Pearson Correlation Coefficient
It has a value between +1 and −1, where 1 is total positive linear correlation, 0 is no
linear correlation and −1 is total negative linear correlation. It’s often denoted by r for
sample correlation and ρ for population correlation.
When option “R” for "Correlation variants" is chosen, the value would be the same as
TradingView's built in correlation() function. For "Adjusted R ", the calculation is based on
the traditional Pearson. The sample r is a biased estimate of population ρ. The adjusted r
gets rid of some of the bias but not all. As the sample size or lookback period increases,
adjusted r will be closer to r.
Displays :
When p is lower than 0.05 and r > 0, correlation coefficient shows red, p-value shows
yellow, panel shows “Significant Positive Correlation”.
When p is lower than 0.05 and r < 0, correlation coefficient shows green, p-value shows
yellow, panel shows “Significant Negative Correlation”.
When p is higher than 0.05, correlation, correlation coefficient shows white, p-value
shows grey, panel shows “Insignificant Correlation”.
=========================
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © balipour
//@version=4
study("Correlation with P-Value & Confidence Interval [pig]", "BA🐷 CC", false, format.price, 3)
bgcolor(#000000c0)
lenMinusOne = len - 1
round(abs(src) * p) / p * sign(src)
label PnL_Label = na
label.delete(PnL_Label[1])
mode = input("Adjusted R", "Correlation Variants ", input.string , options=["R", "Adjusted R"])
//Stats Settings
float r = na
if(mode == "R")
r := R
r := adjr
float r2 = na
if(mode == "R")
r2 := R2
r2 := adjR2
// Fisher Transform
// P Test
t = sqrt((1.0 - pow(r , 2)) / (len - 2)) // T value based on t distribution degrees of freedom 2
#FFFFFFff
// Information Panel
sig() =>
"Insignificant Correlation"
if(pan)
"\n\n" + sig()