DEMA
DEMA is not a double average — it is an average plus an estimate of its own lag, added back. That extrapolation is what makes it lead, and it is also why the line can sit at a price the market never traded, which no true moving average can do. MetaTrader 5 ships it as iDEMA, and the length you set is half the history it needs.
- Period set
- 14
- Bars needed
- 26
- Buffers plotted
- 1 of 3
示意性 — 合成数据,非实时报价。
What DEMA tells you
Every moving average is late, and the lateness is not random — it is roughly proportional to the average's own distance behind price. DEMA exploits that. It takes an EMA, then takes an EMA of that EMA, and the gap between the two is a serviceable estimate of how far behind the first one is running. Doubling the first and subtracting the second adds that estimate back, so the line arrives at a new level far sooner. What you are looking at is therefore not an average of anything: it is an average with a correction bolted on, and corrections can be wrong in the direction of too much.
- It reaches a new level in about a third of the bars a plain EMA needs
- It can print values price never traded at — a real average cannot
- There is no adaptation: the smoothing is fixed, only the lag is cancelled
- 1 EMA of price, then an EMA of that EMA
- 2 Their difference estimates how far the first EMA is lagging
- 3 DEMA = 2 x EMA − EMA(EMA) — the same average with that lag added back
显示公式与计算详情
DEMA is one line of arithmetic:
DEMA = 2 × EMA(price) − EMA(EMA(price))
The trick is in the second term. An EMA lags price; an EMA of that EMA lags it again, by roughly the same amount. So the gap between the two is a usable estimate of how far behind the first one is running — and doubling the first while subtracting the second adds that estimate back on top.
That makes it an extrapolation, not an average. The distinction has a consequence you can see. A moving average is a weighted sum of the prices in its window whose weights add to one, so the result always lands somewhere between the lowest and highest of them. DEMA has no such guarantee:
- On a step from 100 to 110, the line peaks at 111.17 — above the highest price that ever existed in the series
- On a random walk with period 14, it sits outside the last fourteen bars’ high-low range on 2.1% of bars
- The same test run against the plain EMA it is built from: 0.0%
The upside is measured just as plainly. On that same step, a plain EMA needs 20 bars to reach 95% of the new level. DEMA needs 6.
The period is half the history. The second EMA cannot start until the first has produced values, so MT5 sets PLOT_DRAW_BEGIN to 2 × period − 2 and calculates nothing before then. A DEMA(14) needs 26 bars; a DEMA(50) needs 98. Nothing errors — the left of the chart is simply empty.
Earlier is not smoother. The usual reason to reach for this indicator is that an EMA feels late, and the usual mistake is to also expect it to be cleaner. It is the same EMA with a correction added, and the correction amplifies whatever the EMA was doing, noise included. In a trend that is exactly what you want. In a range the correction goes on supplying lead to a move that never arrives, and the crossings multiply — which is what the template’s stop distances, and the trend filter suggested above, exist to survive.
信号
DEMA 提供的可回测信号 — 及每个信号适合的市场状态。
Price Against the Line
Builder 可实现DEMA Against Its Own EMA
Builder 可实现Overshoot Past the Range
高级逻辑MT5 实现
MetaTrader 5 实际计算和绘制的内容——本页每条规则的依据。
缓冲区
| 索引 | 缓冲区 | MT5 中的绘制方式 | 存放内容 |
|---|---|---|---|
| 0 | MAIN_LINE | DEMA | The line, and the only series MT5 plots. The indicator declares three buffers, but the other two hold the intermediate EMA and the EMA of that EMA and are marked INDICATOR_CALCULATIONS — working storage rather than output. The Builder reads index 0. |
平台说明
最佳适用场景 / 谨慎使用
没有任何指标具有普适优势。以下是 DEMA 发挥作用的场景 — 以及可能误导的场景。
最佳适用场景
- Trends where being a few bars earlier is worth paying for
- As the fast side of a pair, where a slower line supplies the confirmation
- Timeframes where an EMA of the same length feels a beat behind the move
- Replacing an EMA that has been shortened repeatedly to chase responsiveness — this is the principled version of that
谨慎使用
- Ranges: the correction keeps adding lead to a move that is not going anywhere, so crossings multiply
- Treating the line as a level — it regularly sits where price has never been
- Short histories: nothing is drawn until twice the period minus two bars exist
- Assuming it is smoother than an EMA. It is not smoother; it is earlier, and earlier is noisier
构建 DEMA 策略
将信号接入进场和出场规则,然后导出可编译的 MT5 EA — 无需编写代码。
- Two DEMA nodes on Close — one at 14, one at 28
- Fast crosses above slow → Close the short, then Open Buy · SL 70 / TP 210
- Fast crosses below slow → Close the long, then Open Sell
- Both read the last closed bar, so a cross is a settled fact
- The close nodes are placed ahead of the entries, and the order matters
将 DEMA 与其他指标组合
单一指标很少独立有效。这些组合弥补了 DEMA 的盲点。
DEMA + Moving Average
- A plain EMA at 14
- DEMA at 14
- Compare
No single-flow template pairs them. Start from DEMA 14/28 Lead Cross, add a Moving Average node set to EMA 14, and put it into a Compare against the fast DEMA.
打开 Builder →DEMA + ADX
- ADX above 25
- Fast DEMA crosses above slow
- Buy
No single-flow template combines them. Add an ADX node with a Compare at 25 to DEMA 14/28 Lead Cross and join it to the Cross with an And gate.
打开 Builder →DEMA + FrAMA
- FrAMA above a fixed average
- Fast DEMA crosses above slow
- Buy
No single-flow template pairs them. Add a FrAMA node and a Moving Average node into a Compare, then join that to the DEMA Cross with an And gate.
打开 Builder →DEMA + TEMA
- TEMA at 14
- Fast DEMA crosses above slow
- Buy
No single-flow template pairs them. Add a TEMA node at 14 on Close to DEMA 14/28 Lead Cross and put it into a Compare against the fast DEMA — or start from EMA Cross Entry x TEMA Early Exit and add DEMA there instead.
打开 Builder →参数
在您自己的货币对和时间框架上验证的起始值 — 非保证设置。
| 参数 | 默认值 | 建议测试范围 | 功能说明 |
|---|---|---|---|
| Period | 14 | 1–999 | The EMA length used twice — once on price and once on the result. It behaves like an ordinary length in that longer is slower, but the history it consumes is not what you set: MT5 draws nothing until 2 × period − 2 bars exist, because the second EMA cannot start until the first one has. A DEMA(50) needs 98 bars. |
| Applied price | Close | Close / Open / High / Low / Median / Typical / Weighted | Which series the whole calculation runs on. Unlike FrAMA, where the setting barely matters, here it is a real control: both EMAs and therefore the correction are computed from whatever you choose. |
| Shift | 0 | 0–100 | Which bar to read. The template sets 1 so a cross is decided on a closed bar. This is not iDEMA's own ma_shift, which slides the drawn line sideways — the Builder pins that to 0 and exposes only the bar offset. |
| Timeframe | Current | Current / M1–MN1 | Which timeframe's bars the line is built from. Set above the chart and it becomes a faster-than-usual read of a slower trend, which is a reasonable way to use the lead without trading every crossing on the chart's own bars. |
初始预设
市场示例
DEMA 有效的场景、失效的场景,以及过滤器如何改变结果。
In before the average
A move begins and the fast line separates from the slow one several bars before the equivalent EMA pair would have crossed. The position is open for the part of the move that a slower crossover spends waiting.
The lead that led nowhere
A sideways stretch produces a cross, then the opposite cross four bars later, then a third. The correction term kept adding lead to a move that was never there — the failure mode the trend filter exists for.
Same stretch, strength required
The identical range with a trend-strength condition attached to the cross. The lines still cross and no order is sent, because the flow was asked for something the crossover alone cannot say.
FAQ
- Is DEMA built into MetaTrader 5?
- Yes. iDEMA is a standard MQL5 function taking a symbol, a timeframe, the period, an ma_shift and an applied price, and the terminal also ships a DEMA custom indicator under Indicators\Examples. The Builder calls the built-in, so a generated EA needs no extra files on the terminal that runs it.
- Is it just an EMA of an EMA?
- No — that would be slower, not faster. It uses an EMA of an EMA, but subtracts it: DEMA = 2 × EMA − EMA(EMA). The second term lags the first in the same way the first lags price, so their difference estimates that lag, and adding it back moves the line forward rather than smoothing it further.
- Why does it sometimes go above the highest price on the chart?
- Because it is an extrapolation, not an average. An average of a window always lands inside that window's range; the doubling and subtraction here remove that guarantee. Measured on a step from 100 to 110 the line peaks at 111.17, and on a random walk it sits outside the last fourteen bars' range on 2.1% of bars against 0.0% for a plain EMA. It is expected behaviour, and it is the reason not to read the line as a price level.
- How many bars does it need before it draws?
- 2 × period − 2. The EMA of the EMA cannot start until the first EMA has produced values, so a period of 14 needs 26 bars and a period of 50 needs 98. MT5 returns without calculating while the history is shorter, so the left of the chart is simply empty rather than wrong.
- How is it different from an adaptive average like FrAMA?
- They attack the same problem from opposite ends. An adaptive average varies how much smoothing to apply, measuring the market and easing off when it is directional. DEMA never changes its smoothing — it leaves the EMA exactly as it was and subtracts an estimate of the lag instead. The visible consequence is in ranges: an adaptive line goes flat and stops signalling, while DEMA keeps leading and keeps crossing.
- Can I build a DEMA EA without coding?
- Yes. The DEMA 14/28 Lead Cross template uses two DEMA nodes on Close and trades the crossings between them, closing the opposite side before it enters. The two periods, the applied price, the shift, the stop distances, the lot and the spread limit are all EA inputs.
- How should I validate settings before going live?
- Backtest on quality tick data, then demo, and read the trade list rather than only the curve. Two things are specific to this indicator. Make sure the test spans a range as well as a trend — the lead is an advantage in one and a liability in the other, and a test containing only trends measures half the behaviour. And resist shortening the period to get more lead: the correction already supplies it, and a shorter period compounds the overshoot rather than improving the timing.