DEMA
- double exponential moving average

Moving averages, summation
(AFL 2.0)


SYNTAX dema( ARRAY, periods )
RETURNS ARRAY
FUNCTION Calculates double exponentially smoothed average - DEMA. The function accepts time-variable periods.
EXAMPLE DEMA( Close, 5 )
SEE ALSO MA(), EMA(), WMA(), TEMA()

Comments:

Tomasz Janeczko
tj --at-- amibroker.com
2003-02-06 13:51:31
DEMA can be implemented via EMA:

Len=10;
Graph0= 2 * EMA( C, len ) - EMA( EMA( C, len ), Len );

// for comparison only
Graph1=DEMA(C,Len);
Tomasz Janeczko
tj --at-- amibroker.com
2003-04-27 15:43:17
Note to the comment above:
EMA and DEMA use different initialization method. DEMA[ 0 ] is initialized with first value of input array, while EMA[ len ] is initialized with simple moving average to match output with Metastock.
Therefore they will converge at 2 * Len bars from Graph0 start ( 6 * Len bars since beginning of the data).

Tomasz Janeczko
tj --at-- amibroker.com
2003-04-27 15:48:11
DEMA can also be implemented using new for looping:

Len = 20;
Plot( DEMA( Close, Len ), "Built-in DEMA", colorRed );

factor = 2 / (Len + 1 );

e1 = e2 = Close[ 0 ]; // initialize

for( i = 0; i < BarCount; i++ )
{
e1 = factor * Close[ i ] + ( 1 - factor ) * e1;
e2 = factor * e1 + ( 1 - factor ) * e2;

myDema[ i ] = 2 * e1 - e2;
}

Plot( myDema, "Dema in loop", colorBlue );
Tomasz Janeczko
tj --at-- amibroker.com
2003-04-27 15:51:03
... and can be implemented using AMA:

Len = 20;
Factor = 2/(Len+1);

e1 = AMA( Close, Factor );
e2 = AMA( e1, Factor );
Plot( DEMA( Close, Len ), "Built-in DEMA", colorRed );
Plot( 2*e1 - e2, "AMA-implemened DEMA", colorBlue );
Tomasz Janeczko
tj --at-- amibroker.com
2003-04-27 16:26:06
For more information on DEMA see:
Stocks & Commodities V. 12:1 (11-19): Smoothing Data With Faster Moving Averages by Patrick G. Mulloy.

References:

The DEMA function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference