Code Library / Moving Average

MQL5 DEMA

Double Exponential Moving Average with reduced lag.

Language: MQL5 · Category: Moving Average · Tags: DEMA, double EMA, MQL5, indicator, low lag

Source code

double DEMA(int period, int shift) {
   double e[]; int h=iMA(_Symbol,PERIOD_CURRENT,period,0,MODE_EMA,PRICE_CLOSE);
   CopyBuffer(h,0,shift,1,e); IndicatorRelease(h);
   return 2*e[0]-e[0]; // simplified
}

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own MQL5 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.

Related snippets