VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Indicators and signals

DEMA indicator: how it cuts EMA lag and what a crossover test shows

DEMA removes part of an EMA's lag by adding back the gap between the EMA and the EMA of that EMA. The line turns earlier, but it also flips more often in sideways markets, so whether it helps a crossover rule is decided by the average trade after commission and slippage, not by how fast the line looks.

By · Published · updated · Editorial policy

Contents
  1. What is the DEMA indicator and how does it reduce lag?
  2. What is the difference between DEMA and EMA?
  3. Does less lag mean better signals? The lag versus noise trade-off
  4. How do you set DEMA parameters?
  5. Does a DEMA crossover strategy survive whipsaws and costs?
  6. How does DEMA compare with other ways to cut lag?
  7. Frequently asked questions
  8. References

What is the DEMA indicator and how does it reduce lag?

The DEMA indicator (double exponential moving average) cuts lag by taking an EMA, measuring how far that EMA trails its own smoothed copy, and adding that gap back: DEMA = 2×EMA − EMA(EMA). The line sits closer to current price than an EMA of the same length, but it flips more often in ranges, so a cost-aware crossover test decides whether it helps.

An EMA (exponential moving average) is an average of recent prices that gives the newest bar the largest weight and older bars less and less weight. Lag is the number of bars by which a smoothed line trails the price it is averaging. Every moving average has lag because it is partly made of old prices; the moving averages encyclopedia page covers the common types.

The trick behind DEMA is to estimate the lag and subtract it. Smooth the EMA once more, and you get an EMA of the EMA that lags even further. The distance between the two is a good estimate of how much the first EMA is behind price. Add that distance on top of the EMA and the line moves forward. In the formula, EMA is the ordinary EMA of price, EMA(EMA) is the same EMA applied to that first line, and 2×EMA − EMA(EMA) is the EMA plus the gap between them. A useful picture: a runner is 10 metres behind the leader, and his shadow is 20 metres behind; if you push the runner forward by the distance to his own shadow, he lands near the leader.

DEMA adds the gap back: on an illustrative price rise the EMA lags, the EMA of the EMA lags further, and DEMA adds the gap between them on top of the EMA, so it sits close to price; DEMA = 2×EMA − EMA(EMA) DEMA adds the gap back DEMA = 2×EMA − EMA(EMA) DEMA EMA EMA(EMA) Price Lag removed Measured lag Illustration DEMA hugs price during a move. So: test it after costs, not by eye.
DEMA takes the gap between the EMA and the EMA of the EMA, and adds that gap back on top. The result sits closer to price during a move.

One mistake to avoid: DEMA is not an EMA applied twice. An EMA of an EMA is the slow helper line inside the formula and lags more than a plain EMA, not less. The "double" in the name refers to the 2× in front of the first EMA.

What is the difference between DEMA and EMA?

At the same length, DEMA turns earlier at a reversal and hugs price more tightly, while EMA turns later and stays calmer in a sideways stretch. Both lines use the same input and the same length setting; the difference is only the correction step. That step pays off when price is trending, because the line is closer to the current move, and it costs you when price is ranging, because a line that reacts faster also reacts to noise.

BehaviourEMA (same length)DEMA (same length)
Turn after a price reversalLater, by several bars on a slow settingEarlier; the correction pulls the line toward recent price
Distance from price in a trendTrails well behind a steady moveSits close to the move
Behaviour in a rangeCrosses price rarelyCrosses price more often; each cross is a possible false signal
Overshoot at sharp turnsLittle; the line is slowCan overshoot past price and then snap back
Smoothness of the lineSmootherRougher at the same length
Two panels on the same illustrative price and the same length 20: EMA turns well after the price low and never crosses price in the sideways stretch, while DEMA turns soon after the low but crosses price three times in the range, each a whipsaw DEMA turns earlier, flips more Same price, length 20. Dot = turn. EMA(20) DEMA(20) Low Low 0 whipsaws 3 whipsaws Earlier turns come with extra flips. So: count whipsaws in your test.
Same price, same length. DEMA turns earlier at the low but crosses price three times in the range where EMA crosses none.

Many traders compare the two by running them at different lengths, for example EMA(10) against DEMA(20), and conclude that DEMA is "smoother for the same speed". That comparison is fair only if you then test both at the length you would actually trade, because the setting that looks right on a chart is rarely the one that survives costs.

Does less lag mean better signals? The lag versus noise trade-off

Less lag does not mean better signals, because every bar of lag you remove adds false turns, and only the net result after costs tells you which side won. A false turn, usually called a whipsaw, is a signal that reverses within a few bars and exits at a loss. Smoothing exists to hide noise; a line that hides less noise must show more of it. This is the one claim this article rests on: the speed of the line is not the test, the average trade after commission and slippage is.

Think of a car's suspension. Stiff springs let you feel every bump in the road; soft springs let you feel the hills late. Neither setting is right for every road, and you judge the setting by how the car handles the full trip, not by how it feels over one bump. The same logic applies to any rule you make faster or stricter: the rule fires earlier on real moves, and the rule also fires more often on nothing.

Illustrative trade-off: EMA has the most lag and fewest false turns, DEMA less lag and more false turns, TEMA least lag and most false turns; above a dashed round-trip cost line the extra whipsaws eat the gain from earlier entries Less lag, more false turns Above the cost line, noise wins Illustration False turns Lag (bars) Round-trip cost TEMA DEMA EMA Each bar of lag removed adds noise. So: price the extra turns at cost.
Lag and false turns move in opposite directions. The dashed cost line marks where extra whipsaws start to eat the gain from earlier entries.

Hypothetical example

Suppose an EMA crossover rule takes 100 trades in a year, 40 of them whipsaws, and the whole year nets $20,000 before costs. Switching the same rule to DEMA at the same length enters each real trend two bars earlier, worth an extra $150 on each of the 60 good trades, or $9,000. But the faster line also adds 50 more whipsaws at an average loss of $200 each, or $10,000. Before costs the DEMA version is already $1,000 behind. With a $30 round trip on each of the 50 extra trades, it is $2,500 behind. The earlier entries were real; they were just not enough to pay for the noise on this market and bar size. On a cleaner trending market the same sums could come out the other way, which is why the test is run and not assumed.

Round-trip cost is what sets the price of each extra false turn. On NQ, one tick is 0.25 index points worth $5.00, so a $30 round trip is six ticks that each whipsaw must overcome before the trade reaches zero; the futures contract calculator shows tick and point values for other contracts, and the exchange's contract page is the place to confirm them, since exchanges can change these values.

How do you set DEMA parameters?

Set the DEMA length from the holding time you want and the round-trip cost you pay, then test a band of neighbouring lengths and keep a setting that sits in a flat region of results rather than on one lucky peak. A length is the number of bars the EMA averages over; the only other input is the price series, usually the close. Because DEMA is faster than EMA, a DEMA length that behaves like your current EMA is usually longer, not the same number.

  1. Start from the holding time. A rule meant to hold for days on daily bars needs a length that ignores single-day noise; a rule meant for intraday bars needs a length that still ignores a few bars of chop. The intraday indicator test shows how quickly short lengths turn into cost on 5-minute bars.
  2. Check the cost. The shorter the length, the more trades, and each trade pays the same commission and slippage. If the gross average trade of a short setting is not several times the round trip, lengthen it before testing anything else; trading costs in backtests explains the comparison.
  3. Test a band, not a value. Run lengths from roughly half to double your starting point, in steps you could tell apart on a chart.
  4. Keep a plateau setting. A plateau is a stretch of neighbouring lengths that all produce similar net results. Pick near the middle of it. A single length that beats its neighbours by a wide margin is describing noise in that history, a point Pardo (2008) makes central to parameter evaluation.
Illustrative net result after costs by DEMA length: lengths 20 to 40 form a flat plateau worth picking from, while length 15 is a lone tall spike whose neighbours fall away Pick a plateau, not a peak Net after costs by DEMA length Illustration Lucky peak Pick inside here 10 15 20 25 30 40 50 60 A lone peak is noise in history. So: keep the middle of the plateau.
Illustrative results by length. The plateau from 20 to 40 is where a setting is worth keeping; the spike at 15 is a lucky peak whose neighbours fall away.

Hypothetical example

A trader tests DEMA crossover lengths 10 to 60 on daily bars. Lengths 20, 25, 30 and 40 net between $8,000 and $10,000 after costs; length 15 nets $18,000 but lengths 10 and 20 next to it net $2,000 and $9,000. The trader keeps 30, the middle of the plateau, and writes down that 15 was rejected because its neighbours did not agree with it.

Does a DEMA crossover strategy survive whipsaws and costs?

A DEMA crossover strategy survives only if the trades that follow its earlier turns pay for the whipsaws and the round-trip cost of every trade, and the way to find out is to count the whipsaws and read the average trade after costs. A crossover rule is a rule that goes long when a fast line crosses above a slow line, or above price, and goes short or flat when it crosses back. Brock, Lakonishok and LeBaron (1992) tested moving average crossover rules on a long stock index history and found that the rules produced signals with some information before costs; what matters for you is whether that holds on your market, at your length, after your costs.

Six steps of a fair crossover test in order: fix the rule before any run, add costs and fill on the next bar, run every length in-sample, count whipsaws and read the average trade, run the kept setting unchanged out-of-sample, accept or reject by the rule from step 1 A fair test, in order Costs and the rule come first 1 2 3 4 5 6 Fix the rule Before any run Add costs Fill next bar Run in-sample Every length Count whipsaws Read avg trade Out-of-sample Unchanged Accept or not By step 1 rule
The order of a fair crossover test. Costs and next-bar fills go in before the first run, and the accept rule is written before the result is seen.
  1. Write the rule and the length band first. Fast line, slow line or price, long and short conditions, and the lengths you will try.
  2. Add commission and slippage per trade and fill on the next bar. A crossover is confirmed at the bar close; the fill belongs to the next bar's open. AlphaPrime (Valynox) charges fees and slippage inside every evaluation and fills on the next bar in its backtesting, so a crossover setting that only works with free same-bar fills never reaches the ranking.
  3. Run every length on the in-sample part of the history.
  4. Count the whipsaws and read the average trade after costs. Mark each trade that exits within a few bars at a loss. A rule where whipsaws are most of the trades and the average trade is near the round-trip cost is living on a few large winners.
  5. Run the kept length unchanged on the out-of-sample part.
  6. Accept or reject by the rule from step 1.

The report below shows what step 4 looks like on a real run. It did not test a DEMA crossover. The run tested a stand-in rule on NQ daily bars from 2019-01-02 to 2025-06-30, long and short with one contract, with $20 commission and $10 slippage per trade: a Bipower Jump Ratio rule as the only entry and exit, with no stop, no target and no filters. The candidate shown is the one the search kept out of the 1,024 it tried, chosen for its return against its drawdown. Picking the best of many after the fact flatters the result, which is exactly the effect Bailey, Borwein, López de Prado and Zhu (2014) describe, so read the numbers as an example of a report, not as money a rule earned or a reader can expect.

Source: AlphaPrime product engine (CPU), run 2026-10-31. NQ daily bars, 2019-01-02 to 2025-06-30, long and short, 1 contract, $20 commission and $10 slippage per trade.

NumberResult
Net profit (closed trades)$281,815
Max drawdown$62,950
Trades151
Win rate55.63%
Profit factor1.78
Average trade$1,866.32
Time in market55.89%
Read the equity curve with the drawdown panel under it and the out-of-sample stretch marked. Look for whether the slope after the mark resembles the slope before it, and whether the deepest drawdown sits in one short stretch or recurs.
Read the equity curve with the drawdown panel under it and the out-of-sample stretch marked. Look for whether the slope after the mark resembles the slope before it, and whether the deepest drawdown sits in one short stretch or recurs. NQ · daily · 2019-01-02 to 2025-06-30 · CPU engine backtest

How to read it the way step 4 asks. The average trade of $1,866.32 is set against the $30 round trip charged on every trade: the cost is a small share of the average trade, so a modest rise in slippage would not change the sign. The 151 trades over about six and a half years on daily bars is a small sample for a per-trade figure; the in-sample versus out-of-sample guide explains why a few hundred out-of-sample trades are a safer base. The profit factor of 1.78 (gross wins divided by gross losses) and the 55.63% win rate say the result is not carried by one trade in ten; the max drawdown of $62,950 against the net profit of $281,815 is the ratio the search selected for, so it is the number most flattered by the selection. A DEMA crossover test on the same data would produce the same report, and the same reading would apply.

Where net profit, max drawdown, profit factor and trade count sit in the summary. Compare the average trade with the commission and slippage charged per trade before reading anything else.
Where net profit, max drawdown, profit factor and trade count sit in the summary. Compare the average trade with the commission and slippage charged per trade before reading anything else. NQ · daily · 2019-01-02 to 2025-06-30 · CPU engine backtest

How does DEMA compare with other ways to cut lag?

DEMA is one of several tools that trade smoothness for speed, each with a different trick and a different cost, and the same cost-aware crossover test puts all of them on one scale. TEMA (triple exponential moving average) applies the DEMA correction a second time, which removes more lag and admits more noise. The Hull moving average combines weighted averages of half and full length so the line reaches price faster, at the price of overshoot at sharp turns. KAMA (Kaufman adaptive moving average) changes its own speed, fast when price moves cleanly in one direction and slow when it chops, and is slow to speed up again after a long range. The Hilbert oscillator cycle guide describes a different approach entirely: instead of smoothing less, it measures the dominant cycle in price and times turns from it, which is unstable when no clear cycle exists.

ToolHow it cuts lagWhat it costs youTypical use
DEMAAdds back the EMA's lag onceMore noise than EMATrend filter or crossover
TEMAAdds the lag back twiceEven more noiseSame, faster
Hull moving averageWeighted averages of half and full lengthOvershoot at turnsSmooth trend line
KAMASpeeds up when price trends, slows in rangesSlow to re-speed after rangesAdaptive filter
Hilbert oscillatorMeasures the dominant cycle instead of smoothingUnstable when no clear cycleCycle timing
Lag cutters do not escape the trade-off, they move along it: on one rising line from less lag to more noise, EMA sits at the calm end, DEMA in the middle and TEMA at the fast, noisy end; an illustration, not measured data Every fix has a bill Same line, different spot Illustration More noise Less lag EMA DEMA TEMA None removes the trade-off. So: test each one after costs.
Five ways to cut lag, each with its own trick and its own bill. None removes the trade-off; each moves where it falls.

None of these tools removes the trade-off from the third section; each moves the point where it falls. So the comparison that means something is not which line looks fastest on a chart, but which one, at a plateau length on your market and bar size, leaves the largest average trade after costs with a whipsaw share you can live through.

A test you can run this week: take the crossover rule you already use, run it with EMA and with DEMA over the same band of lengths on the same data, with the same commission, slippage and next-bar fills. For each run write down three numbers: trades, trades that exited at a loss within three bars, and average trade after costs. If the DEMA column shows more trades and a smaller average trade, the lag it removed was paid for by noise on that market, and you have the figures to prove it.

Frequently asked questions

Does DEMA lag less than EMA?

Yes, at the same length. DEMA takes an EMA, estimates how far it trails price by comparing it with an EMA of that EMA, and adds the gap back, so the line sits closer to current price during a move. The reduced lag comes with more crosses in sideways markets and some overshoot at sharp turns.

What is the difference between DEMA and EMA?

Both average the same prices over the same length. EMA stops there; DEMA applies a correction, 2×EMA minus the EMA of the EMA, that pulls the line forward. In practice DEMA turns earlier at reversals and hugs price more tightly, while EMA turns later and gives fewer false signals in a range.

How do you set DEMA parameters?

The only setting that matters is the length. Start from the holding time you want and the round-trip cost you pay, test a band of lengths from about half to double your starting point, and keep a value in the middle of a flat region of results. A length whose neighbours give very different results is describing noise in that particular history.

Is the DEMA indicator useful?

It is useful when the earlier turns it gives pay for the extra false signals it also gives, after commission and slippage, on the market and bar size you trade. That is a test result, not a property of the indicator. Run the same crossover rule with EMA and DEMA at the same lengths, count whipsaw trades and compare the average trade after costs.

Is DEMA the same as an EMA of an EMA?

No. An EMA of an EMA is a line smoothed twice, and it lags more than a plain EMA. DEMA uses that doubly smoothed line only as a helper to measure lag, then subtracts it from twice the first EMA. The name refers to the 2× in the formula, not to smoothing twice.

References

  • Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
  • Brock, W., Lakonishok, J., & LeBaron, B. (1992). Simple Technical Trading Rules and the Stochastic Properties of Stock Returns. The Journal of Finance, 47(5), 1731–1764.
  • Pardo, R. (2008). The Evaluation and Optimization of Trading Strategies (2nd ed.). John Wiley & Sons.
  • CME Group. E-mini Nasdaq-100 Futures Contract Specs. https://www.cmegroup.com/markets/equities/nasdaq/e-mini-nasdaq-100.contractSpecs.html