This version of the Laguerre filter on price uses dynamic Gamma calculation based on recent ATR, making it more adaptive and versatile to the recent market movement.
The indicator has also a dynamic channel made of self adjusting levels that act as signals filtering.
You have the ability to change the period used for the levels with the “inpPeriod1” setting, if it is set to 0, the period is the same as the one used for the ATR.
You can add or remove the filling color added between the Laguerre curve and the channel with the “ColorFill” setting.
//PRC_ATR adaptiveLaguerreFilter | indicator
//12.10.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from MT5 version
// --- settings
inpPeriod = 14 // Period
inpPeriod1 = 0 // Levels period (<=1 for same as filter period)
ColorFill = 1 // 1=true ; 0=false
// --- end of settings
Series = customclose
atrperiod = max(1,inpPeriod)
atr= averagetruerange[atrperiod]
mmax = highest[atrPeriod](atr)
mmin = lowest[atrPeriod](atr)
if mmin<>mmax then
coeff=1-(atr-mmin)/(mmax-mmin)
else
coeff=0.5
endif
coeff = (coeff+1.0)/2.0
period = inpPeriod*coeff
gamma = 1.0 - 10.0/(period+9.0)
once l0 = Series
once l1 = Series
once l2 = Series
once l3 = Series
IF BarIndex < max(inpPeriod,inpPeriod1) THEN
laguerre = Series
ELSE
l0 = (1 - gamma) * Series + gamma * l0[1]
l1 = -gamma * l0 + l0[1] + gamma * l1[1]
l2 = -gamma * l1 + l1[1] + gamma * l2[1]
l3 = -gamma * l2 + l2[1] + gamma * l3[1]
laguerre = (l0 + 2 * l1 + 2 * l2 + l3) / 6
val=laguerre
lvlPeriod=inpPeriod
if inpPeriod1>0 then
lvlPeriod=inpperiod1
endif
alpha = 2.0/(1.0+lvlPeriod)
if val>leveld then
levelu = levelu[1]+alpha*(val-levelu[1])
endif
if val<levelu then
leveld = leveld[1]+alpha*(val-leveld[1])
endif
//OB and OS colors
r=200
g=200
b=200
if val>levelu then
r=50
g=205
b=50
if colorfill then
drawbarchart(val,levelu,val,levelu) coloured(r,g,b)
endif
elsif val<leveld then
r=255
g=20
b=147
if colorfill then
drawbarchart(val,leveld,val,leveld) coloured(r,g,b)
endif
endif
ENDIF
return val coloured(r,g,b) style(line,3), levelu coloured(50,205,50) style(dottedline), leveld coloured(255,20,147) style(dottedline)