This expiremental version of the ADX trend indicator is using VHF filter (Vertical Horizontal filter) smoothed with ISSM function (Exponential Smoothing and Innovation State Space Model).
It has floating levels (and so median one too), which make it adaptive to market, relying on last higher highs and lower lows of the indicator. These levels seem to be sometimes a bit ‘out of sync’, but it is already the case in the original version.
Periods, smoothing, dynamic levels threshold can be modified in the settings.
This indicator was converted from a MT4 code version by a request in the Spanish forum.
//PRC_ADX VHF adaptive floatlvls | indicator
//25.05.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from MT4 code version
//period = 25 // ADXm period
//Smooth = 15 // Smoothing period for price filter
//minmaxPeriod = 25 // Period for floating zero
//upLevel = 90 // Upper level
//downLevel = 10 // Lower level
if barindex>period+minmaxPeriod then
noise = 0
vhf = 0
mmax = Close[0]
mmin = Close[0]
for k=0 to period-1 do
noise = noise+Abs(Close[k]-Close[k+1])
mmax = Max(Close[k],mmax)
mmin = Min(Close[k],mmin)
next
if (noise>0) then
vhf = (mmax-mmin)/noise
endif
tperiod = period
fzPeriod = minmaxPeriod
if (vhf>0) then
tperiod = -Log(vhf)*period
fzPeriod = round(Max(-Log(vhf)*minmaxPeriod,3))
endif
alpha = 2.0/(tperiod+1.0)
//ISSM settings
Pi = 3.14159265358979323846264338327950288
a1 = Exp(-1.414*Pi/Smooth)
b1 = 2.0*a1*Cos(1.414*Pi/Smooth)
sc2 = b1
sc3 = -a1*a1
sc1 = 1.0 - sc2 - sc3
//Exponential Smoothing and Innovation State Space Model (ISSM)
tprice = High
workSsm01 = tprice
if barindex>1 then
workSsm11 = sc1*(workSsm01+workSsm01[1])/2.0 + sc2*workSsm11[1] + sc3*workSsm11[2]
else
workSsm11 = tprice
endif
hc = workSsm11
//Exponential Smoothing and Innovation State Space Model (ISSM)
tprice = Low
workSsm02 = tprice
if barindex>1 then
workSsm12 = sc1*(workSsm02+workSsm02[1])/2.0 + sc2*workSsm12[1] + sc3*workSsm12[2]
else
workSsm12 = tprice
endif
lc = workSsm12
//Exponential Smoothing and Innovation State Space Model (ISSM)
tprice = Close[1]
workSsm03 = tprice
if barindex>1 then
workSsm13 = sc1*(workSsm03+workSsm03[1])/2.0 + sc2*workSsm13[1] + sc3*workSsm13[2]
else
workSsm13 = tprice
endif
cp = workSsm13
//Exponential Smoothing and Innovation State Space Model (ISSM)
tprice = High[1]
workSsm04 = tprice
if barindex>1 then
workSsm14 = sc1*(workSsm04+workSsm04[1])/2.0 + sc2*workSsm14[1] + sc3*workSsm14[2]
else
workSsm14 = tprice
endif
hp = workSsm14
//Exponential Smoothing and Innovation State Space Model (ISSM)
tprice = Low[1]
workSsm05 = tprice
if barindex>1 then
workSsm15 = sc1*(workSsm05+workSsm05[1])/2.0 + sc2*workSsm15[1] + sc3*workSsm15[2]
else
workSsm15 = tprice
endif
lp = workSsm15
dh = Max(hc-hp,0)
dl = Max(lp-lc,0)
if(dh=dl) then
dh=0
dl=0
elsif(dh<dl) then
dh=0
elsif(dl<dh) then
dl=0
endif
ttr = Max(hc,cp)-Min(lc,cp)
dhk = 0
dlk = 0
if(ttr<>0) then
dhk = 100.0*dh/ttr
dlk = 100.0*dl/ttr
endif
workzdh = workzdh[1] + alpha*(dhk-workzdh[1])
workzdl = workzdl[1] + alpha*(dlk-workzdl[1])
dDI = workzdh - workzdl
div = Abs(workzdh + workzdl)
temp = 0
if( div <> 0.0) then
temp = 100*dDI/div
endif
aADX = aADX[1]+alpha*(temp-aADX[1])
//floating levels
//flLookBack = MinMaxPeriod // Floating levels lookback period
flLevelUp = upLevel // Floating levels up level %
flLevelDown = downLevel // Floating levels down level %
maxi = highest[fzperiod](aadx)
mini = lowest[fzperiod](aadx)
rrange = maxi-mini
flu = mini+flLevelUp*rrange/100.0
fld = mini+flLevelDown*rrange/100.0
flm = mini+0.5*rrange
//colors
r=244
g=164
b= 96
if aadx>flm then
r=30
g=144
b=255
endif
endif
return aadx coloured(r,g,b)style(line,3), flu coloured(100,100,100) style(dottedline),fld coloured(100,100,100) style(dottedline),flm coloured(100,100,100) style(dottedline)