Phase change index by M.H. Pee as featured in TASC magazine.
Which phase is your market going through? Find out by using this indicator.
Prices at any time can be up, down, or unchanged. A period where market prices remain relatively unchanged is referred to as a consolidation. A period that witnesses relatively higher prices is referred to as an uptrend, while a period of relatively lower prices is called a downtrend.
The Phase Change Index (PCI) is an indicator designed specifically to detect changes in market phases.
The original indicator was not smoothed, in this version you can set a smoothing period to get a smoothed curve averaged with Jurik MA, easier to read (default is 30 periods). In the picture you can see a smoothed version (above) and the normal version (below).
//PRC_PhaseChangeIndex PCI | indicator
//20.09.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from MT5 version
// --- settings
inpLength = 30 // Phase change index period
inpLevelHigh = 80 // Level high
inpLevelLow = 20 // Level low
inpSmooth = 30 // Smoothing Period
inpInverted = 1 // Display type (1=inverted ; 0=normal)
// --- end of settings
prices = customclose
imomentum = prices-prices[inpLength]
sumUpDi = 0
sumDnDi = 0
for j=1 to inpLength-1 do
gradient = prices[inpLength]+imomentum*(inpLength-j)/(inpLength)
deviation = prices[j]-gradient
if (deviation > 0) then
sumUpDi = sumUpDi+deviation
else
sumDnDi = sumDnDi-deviation
endif
next
//PCI calculation
if sumUpDi+sumDnDi<>0 then
val = 100.0*sumUpDi/(sumUpDi+sumDnDi)
endif
if inpInverted then
val=100-val
endif
levdn = 50
if val>inpLevelHigh then
levup = 100
elsif val<inpLevelLow then
levup =0
else
levup=50
endif
//smoothing the PCI
if inpSmooth>1 then
Series=val
Period=inpSmooth
// Pow = 5 ({ 1..10 })
// R = 1.5 ({0.5..2.5})
Pow = 10
R = 2.5
beta = 0.45 * (Period - 1) / (0.45 * (Period - 1) + 2)
IF Pow = 1 THEN
alpha = beta
ELSIF Pow = 2 THEN
alpha = beta * beta
ELSIF Pow = 3 THEN
alpha = beta * beta * beta
ELSIF Pow = 4 THEN
alpha = beta * beta * beta * beta
ELSIF Pow = 5 THEN
alpha = beta * beta * beta * beta * beta
ELSIF Pow = 6 THEN
alpha = beta * beta * beta * beta * beta * beta
ELSIF Pow = 7 THEN
alpha = beta * beta * beta * beta * beta * beta * beta
ELSIF Pow = 8 THEN
alpha = beta * beta * beta * beta * beta * beta * beta * beta
ELSIF Pow = 9 THEN
alpha = beta * beta * beta * beta * beta * beta * beta * beta * beta
ELSIF Pow = 10 THEN
alpha = beta * beta * beta * beta * beta * beta * beta * beta * beta
ENDIF
IF BarIndex = 0 THEN
Filt0 = Series
Filt1 = Series
AFR = Series
ELSE
Filt0 = (1 - alpha) * Series + alpha * Filt0[1]
Det0 = (Series - Filt0[0]) * (1 - beta) + beta * Det0[1]
Filt1 = Filt0[0] + R * Det0[0]
Det1 = (Filt1[0] - AFR[1]) * ((1 - alpha) * (1 - alpha)) + (alpha * alpha) * Det1[1]
AFR = AFR[1] + Det1[0]
sval = AFR
ENDIF
else
sval=val
endif
r=169
g=169
b=169
if sval>inpLevelHigh then
r=0
g=191
b=255
endif
if sval<inpLevelLow then
r=244
g=164
b=96
endif
return levup coloured(220,220,220,100) style(histogram) as "levup", levdn coloured(220,220,220) style(line,1) as "levdn", sval coloured(r,g,b) style(line,4) as "PCI", 80 coloured(192,192,192) style(dottedline) as "level 80", 20 coloured(192,192,192) style(dottedline) as "level 20"