//---------------------------------------//
//PRC_USI Ultimate Strength Idx
//version = 0
//19.11.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//---------------------------------------//
// inputs
//---------------------------------------//
src=close
l1=28
l2=4
//---------------------------------------//
// Prev. calculations
//---------------------------------------//
eps=ticksize
diff=src-src[1]
if diff>0 then
su=diff
sd=0
else
su=0
sd=-diff
endif
//---------------------------------------//
// USU calculation
//---------------------------------------//
srcUSU=average[l2](su)
a1su=exp(-1.414*3.1416/l1)
c2su=2*a1su*cos(1.414*3.1416/l1*(180/3.1416))
c3su=-a1su*a1su
c1su=(1+c2su-c3su)/4
if barindex<6 then
usu=srcUsu
else
usu=(1-c1su)*srcUsu+(2*c1su-c2su)*srcUsu[1]-(c1su+c3su)*srcUsu[2]+c2su*usu[1]+c3su*usu[2]
endif
//---------------------------------------//
// USD calculation
//---------------------------------------//
srcUSD=average[l2](sd)
a1sd=exp(-1.414*3.1416/l1)
c2sd=2*a1sd*cos(1.414*3.1416/l1*(180/3.1416))
c3sd=-a1sd*a1sd
c1sd=(1+c2sd-c3sd)/4
if barindex<6 then
usd=srcUsd
else
usd=(1-c1sd)*srcUsd+(2*c1sd-c2sd)*srcUsd[1]-(c1sd+c3sd)*srcUsd[2]+c2sd*usd[1]+c3sd*usd[2]
endif
//---------------------------------------//
// USI calculation
//---------------------------------------//
if (usu+usd) <>0 and usu>eps and usd>eps then
usi=(usu-usd)/(usu+usd)
endif
//---------------------------------------//
// Plot configuration
//---------------------------------------//
midline=0
if usi>midline then
r=0
g=255
b=0
a=50
else
r=255
g=0
b=0
a=50
endif
colorbetween(usi,midline,r,g,b,a)
//---------------------------------------//
return usi as "USI" coloured("blue")style(line,2), 0 as "zero" style(line)