// CTI LONG UP
// CTI BARD
//Ehler's Correlation Trend Indicator (CTI) //PRC_R-Squared coefficient | indicator
//19.09.2018 //Updated to double Ehler's R2 03/05/2020
//Nicolas @ www.prorealcode.com //Sharing ProRealTime knowledge
// --- settings
LPeriod = 30 //Add in Variables perso = 30
SPeriod = 5 //Add in Variables perso = 5
// --- end of settings
///////////////////////////////////////////////////////////////////////////////////////////////////
// Defparam calculateonlastbars = 100
//Short
SumSx = 0 // the price curve
SumSy = 0
SumSxx = 0
SumSxy = 0
SumSyy = 0 // the trend line
data=customclose
for count = 0 to SPeriod-1 do
X = Data[count] // the price curve
Y = -count // the trend line
SumSx = SumSx + X
SumSy = SumSy + Y
SumSxx = SumSxx + X*X
SumSxy = SumSxy + X*Y
SumSyy = SumSyy + Y*Y
next
if(SPeriod*SumSxx-SumSx*SumSx > 0 and SPeriod*SumSyy-SumSy*SumSy > 0) then
// CTIShort = (SPeriod*SumSxy-SumSx*SumSy)/Sqrt((SPeriod*SumSxx-SumSx*SumSx)*(SPeriod*SumSyy-SumSy*SumSy))
endif
///////////////////////////////////////////////////////////////////////////////////////////////////
//Long
SumLx = 0
SumLy = 0
SumLxx = 0
SumLxy = 0
SumLyy = 0
for count = 0 to LPeriod-1 do
X = Data[count] // the price curve
Y = -count // the trend line
SumLx = SumLx + X
SumLy = SumLy + Y
SumLxx = SumLxx + X*X
SumLxy = SumLxy + X*Y
SumLyy = SumLyy + Y*Y
next
if(LPeriod*SumLxx-SumLx*SumLx > 0 and LPeriod*SumLyy-SumLy*SumLy > 0) then
CTILong = (LPeriod*SumLxy-SumLx*SumLy)/Sqrt((LPeriod*SumLxx-SumLx*SumLx)*(LPeriod*SumLyy-SumLy*SumLy))
endif
c1 = CTIlong < - 0.8
c2 = CTIlong [1] < CTIlong [2]
c3 = CTIlong > CTIlong [1]
SCREENER [c1 and c2 and c3 ]