DEMA average is a double Exponential Moving Average. It was created to reduce the amount of lag time found in traditional moving averages. It was first released in the February 1994 TASC magazine.
This version embed the corrected function, it measures deviations of the DEMA values, if the changes are not significant, then the value is “flattened”.
It also includes the floating levels functionality (2 levels based on recent highest high and lowest low of the corrected curve).
The DEMA and corrected DEMA change color following these criteria:
//PRC_Corrected generalized DEMA | indicator
//20.11.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//original idea from mladen (MT5 indi)
// --- settings
inpPeriod = 25 // Period
inpFlPeriod = 25 // Floating levels period
inpFlUp = 90 // Upper level %
inpFlDown = 10 // Lower level %
// --- end of settings
// DEMA
Series = customclose // Price
Period = MAX(inpPeriod, 1)
if barindex>Period*2 then
avg = DEMA[Period](Series)
//Corrected function
n = Period
SA = avg
v1 = SQUARE(STD[n](Series))
v2 = SQUARE(CA[1]-SA)
if(v2<v1) then
k=0
else
k=1-v1/v2
CA=CA[1]+K*(SA-CA[1])
endif
//colors
if CA>CA[1] then
r=60
g=179
b=113
elsif CA<CA[1] then
r=255
g=69
b=0
endif
if avg>CA then
ravg=60
gavg=179
bavg=113
elsif avg<CA then
ravg=255
gavg=69
bavg=0
endif
imin = lowest[inpFlPeriod](CA)
imax = highest[inpFlPeriod](CA)
rrange = imax-imin
flup = imin+inpFlUp*rrange/100.0
fldn = imin+inpFlDown*rrange/100.0
flmi = imin+50*rrange/100.0
drawcandle(flup,fldn,flup,fldn) coloured(169,169,169,40) bordercolor(169,169,169,0)
endif
return avg coloured(ravg,gavg,bavg) style(line,1) as "DEMA", ca coloured(r,g,b) style(line,2) as "corrected DEMA", flmi coloured(169,169,169) style(dottedline)