Corrected generalized DEMA

Category: Indicators By: Nicolas Created: November 20, 2018, 2:44 PM
November 20, 2018, 2:44 PM
Indicators
9 Comments

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:

  • color change on slope change
  • color change on outer (floating) levels cross
  • color change on middle (floating) level cross
  • color change on average (DEMA) value cross

 

//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)

 

Download
Filename: dema-corrected-1.png
Downloads: 85
Download
Filename: dema-corrected.png
Downloads: 77
Download
Filename: PRC_Corrected-generalized-DEMA.itf
Downloads: 321
Download
Filename: corrected-generalized-DEMA-indicator.png
Downloads: 111
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Logo Logo
Loading...