Back to Guides
Guide

Triple Exponential Moving Average Formula (TEMA and DEMA)

The triple exponential moving average formula, the DEMA formula, and what the guides leave out: less lag is bought by weighting old bars negatively.

The triple exponential moving average is TEMA = 3 x EMA1 - 3 x EMA2 + EMA3, where EMA1 is an EMA of price, EMA2 is an EMA of EMA1, EMA3 is an EMA of EMA2, and every step uses the same period. Its two-term sibling is DEMA = 2 x EMA1 - EMA2.

Every source agrees on those two lines, and every source says the point of them is less lag. What almost none of them say is how the lag gets removed: by giving older bars negative weight. A line built that way can print above every price it was built from, and the size of that overshoot is measurable.

What is the triple exponential moving average (TEMA)?

One line built from three EMAs of the same period, combined so that most of the smoothing delay cancels out.

Patrick Mulloy created it and published it in 1994, in an article titled "Smoothing Data With Faster Moving Averages" in Technical Analysis of Stocks & Commodities magazine. Bajaj Broking and TMGM both carry that attribution, worded almost identically. The same article introduced DEMA.

The name collides with another one. This TEMA is a moving average, and TEMA is also the Tubular Exchanger Manufacturers Association, a heat-exchanger standard, so searches for things like a TEMA pressure gauge land on industrial parts and have nothing to do with charts.

What is the TEMA formula?

TEMA = 3 x EMA1 - 3 x EMA2 + EMA3

where:

  • EMA1 is the exponential moving average of price over n periods.
  • EMA2 is the exponential moving average of EMA1, over the same n.
  • EMA3 is the exponential moving average of EMA2, over the same n.

The same period at every step is the condition people break. TMGM states it plainly: "Using the same period at every step is the part people most often get wrong. For example, a 20 period EMA1 followed by a 9 period EMA2 does not give you a TEMA. It gives you a different line that lags by a different amount."

Implementation references print the same thing in their own notation, under different names for the same three lines. Tulip Indicators sets it as an equation, 3 · ema(in) - 3 · ema(ema(in)) + ema(ema(ema(in))), and a GNU chart manual gives "TEMA = 3EMA[N] - 3EMAofEMA[N] + EMAofEMAofEMA[N]".

What is the double exponential moving average (DEMA), and its formula?

DEMA = 2 x EMA1 - EMA2

Same two ingredients as the first half of TEMA: an EMA of price, and an EMA of that EMA. Double the first, subtract the second.

A worked example with round numbers. Say today EMA1 is 1.2000 and EMA2 is 1.1950. Then:

DEMA = 2 x 1.2000 - 1.1950 = 2.4000 - 1.1950 = 1.2050

The result sits above both inputs, which is the intention. EMA2 lags more than EMA1 does, so the gap between them is a measure of the lag, and adding that gap back on top cancels it. Emaindicator puts the mechanism in plain words: "By computing an EMA, then computing an EMA of that EMA (which lags even more), then subtracting the second from twice the first, you produce a series whose lag is approximately the negative of the original EMA's lag".

A line that can sit above both of its inputs can also sit above every price that went into it.

Are DEMA and TEMA in ChartLabs?

Both are, as two separate entries in the chart's Indicators menu, in the Standard list under Moving Averages.

Triple Exponential Moving Average is the three-term line. It draws on the price pane, on top of the candles, and opens at Length 9 with the close as its source.

Double Exponential Moving Average is the two-term line. It draws on the price pane as well, and it also opens at Length 9 on the close.

Each computes its formula exactly as written above, and the 9 they share is TradingView's default. The open-source TA-Lib library starts both at 30. One neighbour in the menu is easy to pick by mistake: Triple Exponential Average is TRIX, a different indicator, and it sits under Momentum & Oscillators in a pane of its own.

Is TEMA just an EMA of an EMA of an EMA?

No. EMA(EMA(EMA)) is EMA3 on its own, which is the slowest of the three lines, not the fastest. Plotting it alone lags more than a plain EMA, not less. TEMA subtracts and adds those three lines so their delays cancel.

Bajaj Broking gets it backwards in its own comparison table. It describes TEMA as "The EMA calculation is applied thrice. Essentially, it is EMA(EMA(EMA))" and DEMA as "The EMA calculation is applied twice and it is EMA(EMA)". Both descriptions name the slow nested line as if it were the indicator. The same page prints the correct formula twice, once in its body and again in its FAQ, so its table contradicts its own arithmetic. Its explanation of the speed then says TEMA is faster because "the EMA2 is subtracted thrice from 3 x EMA1", which leaves out the + EMA3 term the formula on the same page carries.

That page also renders the author's name four different ways: Patrick Mulloy, Patrik Muloy, Muloy and Mullay. The spelling is Mulloy.

DEMA vs TEMA: what is the difference?

One more smoothing term and one more round of cancellation. TEMA turns sooner than DEMA, and it overshoots further when it turns.

Both effects come from the same place. DEMA cancels one layer of EMA lag; TEMA cancels two.

What do you give up for the lower lag?

The line stops being an average. It can print above every price it was built from, and below every price it was built from.

Every guide claims the lower lag. None of them puts a number on what it costs. A GNU software manual comes closest, saying both lines are "overweight" on recent points "so the moving average can actually get ahead of recent prices in some unusual price patterns", without saying how far or how unusual.

The figures below are ours, derived from the formulas above with the standard EMA smoothing constant of 2/(n+1).

Expand DEMA and TEMA back into the individual bars they weight, and the weights on older bars turn negative. Both weight sets still add up to exactly 1, so the lines are normalised averages in that narrow sense. A weighted sum with negative weights is not bounded by its inputs, and that is the trade-off:

  • For a 14-period DEMA, every bar older than 14 back carries a negative weight. One sign change. The negative weights add up to -0.1169, about 11.7 per cent of the total weight.
  • For a 14-period TEMA, the weights go negative sooner and come back. Positive for the most recent nine bars, negative from lag 9 to lag 33, positive again beyond that. The negative weights add up to -0.1849.

What that does on a chart, from a clean test. Hold price flat at 100 for 200 bars, then flat at 101 for 200 bars, with every line fully warmed up. The highest price anywhere in that series is 101.000000:

  • a 14-period EMA peaks at exactly 101.000000;
  • a 14-period DEMA peaks at 101.116891;
  • a 14-period TEMA peaks at 101.165508.

Both overshoot the highest price in the series, by 11.7 and 16.6 per cent of the step. The same thing happens in the other direction: let one bar spike up to 101 and price return to 100, and the 14-period DEMA dips to 99.993836 and TEMA to 99.984415, both below the lowest price in the series, after an upward move.

It is not a quirk of the period either. At every period these sources name, same step, same method:

nWhere that period comes fromDEMA first negative lagDEMA peakTEMA first negative lagTEMA peak
5tulipindicators.org, in a worked example6101.0877914101.109739
10emaindicator.com, in a worked example11101.1099897101.152133
14Our own illustration15101.1168919101.165508
20tmgm.com, "the common default"21101.12224213101.177170
21tmgm.com, same line22101.12284614101.178456

Lags are counted with the current bar as lag 0, so "first negative lag 15" means the sixteenth bar back is the first one weighted against the average. Every row's weights sum to exactly 1.000000000, and a plain EMA peaks at exactly 101.000000 at all five periods. The overshoot grows slightly as the period grows, so no choice of period escapes it.

The practical consequence: a DEMA or TEMA crossing a price level can be reporting a level the price never reached, and that is what the speed costs.

What are the best DEMA and TEMA settings?

No vendor publishes a default, so treat any number you are given as somebody's preference rather than a setting with authority behind it.

MetaTrader's reference lists the two as:

int iDEMA(string symbol, ENUM_TIMEFRAMES period, int ma_period, int ma_shift, ENUM_APPLIED_PRICE applied_price);
int iTEMA(string symbol, ENUM_TIMEFRAMES period, int ma_period, int ma_shift, ENUM_APPLIED_PRICE applied_price);

Identical shapes, and both pages note the indicator "has only one buffer". The averaging period is an argument you must supply, and neither page suggests a value for it.

What is published, with its sources:

  • TMGM gives the only recommendations anywhere in the research: "A 20 or 21 period TEMA is the common default, with 9 periods for fast intraday trading and 50 or 200 periods for slower swing and position trading." It frames the choice as advice, in its own voice: "The best TEMA setting depends on how you trade."
  • Tulip Indicators uses period 5 in its worked example, as an illustration rather than a recommendation.
  • Emaindicator works through "DEMA(10) on NIFTY 50", again as an illustration.

The trade-off runs in one direction: shorter periods turn faster and overshoot by a smaller absolute amount, while longer periods are smoother and overshoot a clean step by slightly more.

Neither ChartLabs entry opens on any of those numbers, so set the period yourself if you want TMGM's 20 or 21.

Who created DEMA and TEMA, and when?

Patrick Mulloy, in 1994, in "Smoothing Data With Faster Moving Averages" in Technical Analysis of Stocks & Commodities. One article introduced both lines.

How do you test them?

The question these lines raise is narrow enough to settle by counting two things: how often the faster line turned before a plain EMA of the same period, and how often that earlier turn pointed somewhere price actually went. None of the published guides reports either number.

Plot the DEMA or TEMA against a plain EMA of the same period, so the construction is the only difference between them, and step the chart forward one bar at a time so the next move is hidden. Log every turn the faster line takes ahead of the EMA, and log where price went afterwards. Then log the turns that led nowhere, because those are what the speed cost you, and they are the ones that do not get written down.

The overshoot gives you a second thing worth logging on this pair of indicators specifically. When your rule fires on a cross, note the price the line crossed at and the highest or lowest price actually traded in that stretch. On a sharp move the line can cross a level no bar reached, and a rule that triggers there is triggering on arithmetic rather than on price.

Exponential Moving Average is its own entry under the same menu heading, so the plain line can sit on the price pane beside either of the faster two. Telling the lines apart at a glance helps, and every moving average can be given its own colour and line style, with one indicator instance edited without changing the others.

The counting needs a trade log you can filter rather than a folder of screenshots. Manual bar-by-bar testing in the trading simulator keeps a snapshot of the chart state with every trade you place, and lets you tag trades and filter the analytics by tag. For the mechanics end to end, see our beginner's guide to backtesting a strategy, and for the pair-specific parts, forex backtesting.

KAMA, FrAMA and VIDyA make a different claim from these two: they change their own smoothing as conditions change, rather than cancelling lag arithmetically, so the overshoot described here is not the trade-off they make.

Next step

Weigh the overshoot against the earlier turn, on your own instrument and timeframe, with both lines on the same chart. Start a free trial and run them side by side.

Related Topics

temademamoving-averagesindicatorsbacktesting