VALYNOX
VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Indicators and signals

TEMA indicator: formula, lag vs EMA and DEMA, and an NQ backtest

TEMA turns several bars sooner than an EMA or SMA of the same length because it subtracts an estimate of its own lag. The earlier turn also brings more false turns, so the speed gain is judged by trade count and average trade after costs, not by how the line looks on the chart.

By · Published · updated · Editorial policy

Contents
  1. Is the TEMA indicator really faster than a normal moving average?
  2. How is TEMA calculated, and where does the lag go?
  3. TEMA vs DEMA, EMA and SMA: what is the difference?
  4. What length should you set for TEMA?
  5. Why does less lag mean more signals and more whipsaws?
  6. How much do costs and slippage eat from a TEMA strategy?
  7. How should you test a TEMA strategy before trading it?
  8. Frequently asked questions
  9. References

Is the TEMA indicator really faster than a normal moving average?

Yes. The TEMA indicator (triple exponential moving average) turns several bars sooner than an EMA or SMA of the same length, because it subtracts an estimate of its own lag. The price of that speed is more false turns, so judge the gain by trade count and average trade after costs, not by how the line looks on the chart.

TEMA is a moving average built from three chained exponential moving averages and combined so that most of the delay of the smoothing cancels out. Lag is the number of bars by which a smoothed line arrives at a turn after price has already turned. Every moving average has lag, because it averages old bars with new ones. On a chart, a 20-period TEMA visibly hugs price more closely than a 20-period EMA and turns up earlier at a V-shaped bottom. That part of the claim is true and easy to see.

The part that is not visible on the chart is what the earlier turn costs. A line that reacts faster also reacts to noise faster, so it turns up at bottoms that were not bottoms. Among the technical analysis tools and indicators you can test, moving averages are the clearest case of this trade: less lag always comes with more signals, and more signals always come with more round trips of commission and slippage. The sections below show where the lag goes, how TEMA compares with its relatives, and how to read a backtest of a fast rule after costs.

After an illustrative price low, four 20-period averages turn up in order: TEMA after 2 bars, DEMA after 4, EMA after 7 and SMA after 10. TEMA then overshoots a little. TEMA turns up first Bars from price low to turn, illustration TEMA 2 bars DEMA 4 bars EMA 7 bars SMA 10 bars TEMA turns first, then overshoots. So: judge it by trades, not looks.
At one price turn, four 20-period averages turn up in a fixed order: TEMA first, then DEMA, EMA and SMA. The TEMA line also overshoots a little after the turn.

How is TEMA calculated, and where does the lag go?

TEMA is built from three chained EMAs combined as 3×EMA1 − 3×EMA2 + EMA3, and the subtraction cancels most of the delay that each smoothing step adds. An EMA (exponential moving average) is an average that gives recent bars more weight than older bars, so it follows price more closely than a simple average of the same length. Chain three of them and you get three lines, each smoother and later than the one before it.

The idea behind the subtraction is like owning a clock that you know runs about five minutes slow. You cannot make the clock faster, but you can add five minutes every time you read it. The difference between EMA1 and EMA2 is an estimate of how far one layer of smoothing lags price. Adding that difference back to EMA1 gives a line that sits closer to price. Doing the correction twice, with a third EMA to estimate the lag of the correction itself, gives TEMA.

The one formula to remember:

TEMA = 3 × EMA1 − 3 × EMA2 + EMA3

Here EMA1 is the EMA of price over the chosen length, EMA2 is the EMA of EMA1 over the same length, and EMA3 is the EMA of EMA2 over the same length. The weights 3, −3 and 1 are fixed; the only setting you choose is the length. Because EMA2 and EMA3 are estimates of lag rather than measurements of it, the correction is not exact. At a sharp turn the estimate is too large for a few bars and the line overshoots price before settling back. The same lag problem is approached from another direction by cycle tools such as the Hilbert oscillator, which try to measure the market's cycle length instead of correcting an average after the fact.

Price feeds EMA1, EMA1 feeds EMA2 and EMA2 feeds EMA3, each adding lag. The combination 3×EMA1 − 3×EMA2 + EMA3 gives TEMA and cancels two of those lag layers. TEMA cancels two lag layers Three chained EMAs, one formula Price EMA1 EMA2 EMA3 + lag + lag + lag 3×EMA1 − 3×EMA2 + EMA3 = TEMA The minus terms take lag out. So: expect overshoot at sharp turns.
Three chained EMAs each add a layer of lag. The combination 3×EMA1 − 3×EMA2 + EMA3 pulls the result back toward price by cancelling two of those layers.

TEMA vs DEMA, EMA and SMA: what is the difference?

The four averages form a ladder of less lag and less smoothing: SMA weighs all bars equally, EMA weighs recent bars more, DEMA removes one layer of lag with two EMAs, and TEMA removes a second layer with three, at the price of overshooting at sharp turns. An SMA (simple moving average) is the plain arithmetic mean of the last N closes. The basics of SMA and EMA are on the moving averages indicator page, so this section only compares behaviour.

DEMA (double exponential moving average) is the one-step version of the same trick: 2×EMA1 − EMA2. It sits between EMA and TEMA on every row of the table below. The DEMA indicator and its crossover test covers that step in detail; TEMA simply applies the correction once more.

AverageHow it is builtLag at a turnBehaviour at a sharp turnWhere traders use it
SMAEqual weight on every bar in the windowHighestSmooth, no overshootLong trend filters, reference levels
EMARecent bars weigh moreHighSmooth, no overshootGeneral-purpose trend line
DEMATwo EMAs, lag subtracted onceLowerSome overshootFaster trend line, crossovers
TEMAThree EMAs, lag subtracted twiceLowestMost overshootFast signal lines on short lengths

The practical reading of the ladder: pick the rung by what the average is for. A trend filter that only decides long or short can afford lag, because a few late bars at a turn cost little over a position held for weeks. A signal line that triggers entries wants less lag, and that is where TEMA is usually placed. Moving one rung down the ladder always buys speed with smoothness, never for free.

Comparison of four averages of the same length: SMA uses 0 EMAs, highest lag, no overshoot; EMA 1, high lag, none; DEMA 2, lower lag, some overshoot; TEMA 3, lowest lag, most overshoot Less lag buys overshoot Same length, four averages EMAs Lag Overshoot SMA 0 Highest None EMA 1 High None DEMA 2 Lower Some TEMA 3 Lowest Most Each step trades smoothness for speed. So: pick the average by its job.
From SMA to TEMA each step removes lag and removes smoothness at the same time. Overshoot appears as soon as lag is subtracted rather than accepted.

What length should you set for TEMA?

Common settings are short lengths such as 9 to 21 for signal lines and 50 or more for trend filters, but a length is only meaningful together with the bar size, so test a range of neighbouring lengths and keep one that sits on a plateau rather than the single best value. A 20-period TEMA on 5-minute bars covers 100 minutes of price; a 20-period TEMA on daily bars covers four weeks. The number is the same; the behaviour is not.

Length rangeTypical roleWhat to expect
9 to 21Signal line: price cross or fast line of a pairMany trades, early turns, most whipsaws
34 to 55Slow line of a crossover pairFewer trades, turns a few bars later
50 and aboveTrend filter: direction onlyRare changes of direction; TEMA's speed advantage matters least here

A plateau is a stretch of neighbouring settings that all give a similar result in a backtest. If length 20 does well and 18 and 22 do about as well, the result is likely to describe the market. If 20 does well and 18 and 22 are poor, the result most likely describes noise that lined up with one history. Pardo (2008) describes this as the first thing to look for on an optimization surface: a broad hill, not a spike. Run every length from about 9 to 55 in steps of one or two, plot trades per year and average trade after costs, and pick from the middle of the widest flat region.

Illustrative trades per year for TEMA lengths 9, 14, 21, 34 and 50: 120, 70, 62, 56 and 24. Lengths 14 to 34 behave alike and form the plateau to choose from. Pick a plateau, not a spike Trades per year by length, illustration Plateau 120 70 62 56 24 9 14 21 34 50 Choose from the plateau, not the peak. So: test every length from 9 to 55.
Longer TEMA lengths trade less and turn later. The band of neighbouring lengths that behave alike is the region to choose from, not the single highest bar.

Why does less lag mean more signals and more whipsaws?

A line that follows price closely crosses price and other averages more often, so a TEMA crossover produces more trades than an EMA crossover on the same data, and in a sideways market most of the extra trades are false starts that reverse within a few bars. A whipsaw is a signal that is reversed by the opposite signal shortly after, so that the trade is closed for a small loss plus costs before any move develops.

The mechanism is simple. An EMA sits some distance away from price during a range, so small wobbles do not reach it. A TEMA of the same length sits almost on top of price, so the same wobbles cross it again and again. Each cross is an entry or an exit. The TEMA has not found more opportunities; it has found more noise. In a trend the picture reverses: TEMA stays close to price and gives back less at the turn, while the EMA lags further and exits later.

Many traders try to remove the range whipsaws with a filter, for example a momentum reading or the KD stochastic indicator to confirm direction. A filter can help, but it adds its own length settings and its own lag, so test it as a separate step and compare trade count and average trade before and after it is added. A filter that removes half the trades and keeps most of the profit is doing real work; one that removes half the trades and half the profit is only reducing activity.

Over the same illustrative sideways price stretch, a 20-period EMA is crossed twice and a 20-period TEMA six times; each cross is a round trip that pays costs Faster line, more crosses Same sideways price, 20-period lines EMA 2 crosses TEMA 6 crosses Extra crosses pay costs, go nowhere. So: count crosses per year first.
Over the same sideways stretch, a 20-period EMA is crossed twice and a 20-period TEMA six times. The extra crosses are round trips that pay costs and go nowhere.

How much do costs and slippage eat from a TEMA strategy?

Every extra trade pays a full round trip of commission and slippage, so the per-trade edge of a fast TEMA rule must be measured against that cost, and the measurement only means something when the costs were inside the backtest from the start. A rule with a large gross edge per trade keeps most of it; a rule with a small gross edge per trade and many trades can end below zero even when its gross curve looks the smoothest of all.

Hypothetical example

Two NQ rules, both charged $20 commission and $10 slippage per trade, $30 in all. A slow rule makes 40 trades a year with a gross average trade of $200; after $30 it keeps $170 per trade, about $6,800 a year. A fast rule makes 400 trades a year with a gross average trade of $25; its gross total of $10,000 a year is larger than the slow rule's $8,000, but after $30 per trade it ends at −$5 per trade, about −$2,000 a year. The fast rule looked better before costs and worse after them.

Hypothetical per-trade result with the same 30 dollar cost: a slow rule goes from 200 dollars gross to 170 net, a fast rule goes from 25 dollars gross to minus 5 net Small edges lose to costs Same $30 cost per trade, hypothetical Slow gross +$200 Slow net +$170 Fast gross +$25 Fast net −$5 $30 is small next to $200, not $25. So: compare average trade to cost.
The same $30 of cost per trade is small next to a $200 gross trade and larger than a $25 gross trade. Trade frequency decides which rule you are testing.

The run below shows how to read a real report against that $30. It is not a TEMA test: AlphaPrime (Valynox) ran a stand-in rule built from a standard indicator, a Volume rule as its only entry and exit, with no stop, no target and no filters. It tested NQ daily bars from 2019-01-02 to 2025-06-30, long and short, one contract, with $20 commission and $10 slippage charged on every trade. The candidate shown is the one the search kept out of about a thousand it tried (1,024 in this run), kept for its return against its drawdown. Picking the kept candidate after the fact flatters the result, because the best of a thousand tries always looks better than the typical try; Bailey, Borwein, López de Prado and Zhu (2014) show how large that effect becomes as the number of tries grows.

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)$145,380
Max drawdown$71,785
Trades107
Win rate53.27%
Profit factor1.515
Average trade$1,358.69
Time in market57.95%
Read the average trade next to the $30 charged per trade, then the trade count next to the length of the period, then the max drawdown next to the net profit.
Read the average trade next to the $30 charged per trade, then the trade count next to the length of the period, then the max drawdown next to the net profit. NQ · daily · 2019-01-02 to 2025-06-30 · CPU engine backtest

How to read it. The average trade of $1,358.69 is about 45 times the $30 charged per trade, so on daily bars the cost is a small share of each trade. That is the daily-bar effect: 107 trades over about six and a half years is roughly 16 trades a year, and each trade had weeks to develop. A fast TEMA rule on intraday bars would make many times as many trades, each paying the same $30, and its average trade would need to be judged against the cost in exactly this way. The max drawdown of $71,785 is about half the net profit of $145,380, which is the other number to carry forward: it tells you the account size this candidate would have needed. None of this says the rule earned that money or that a reader can expect it; it is one kept candidate out of a thousand, on one history. AlphaPrime charges the commission and slippage you set inside every candidate's backtesting, with fills on the next bar, so the average trade in the report is already the after-cost figure rather than a gross number you must adjust by hand.

The $10 slippage in this run equals two ticks of NQ, since the E-mini Nasdaq-100 contract is $20 per index point with a minimum tick of 0.25 points, or $5.00 per tick (CME Group contract specifications). Exchanges can change contract values, so confirm the current tick size and tick value on the exchange's contract page before you set costs, or look them up with the free futures contract calculator.

How should you test a TEMA strategy before trading it?

Run the TEMA rule and a plain EMA rule side by side with identical costs, sessions and next-bar fills, compare trade count and average trade after costs, check neighbouring lengths, and confirm the result on data the search never saw. The EMA is the baseline. If TEMA cannot beat a plain EMA of the same length after costs, its lower lag bought nothing you can trade.

  1. Write both rules with the same length. For example, price crosses above the 20-period line to go long and below it to go short, once with EMA and once with TEMA. Same bar size, same market, same dates.
  2. Set identical costs, session and execution. Charge the same commission and slippage per trade, use the same session, and fill every signal on the open of the next bar. Next-bar execution means the order is placed after the bar that produced the signal has closed, so the backtest never uses a price it could not have traded.
  3. Run both and compare trades per year and average trade after costs. Expect TEMA to show more trades. The question is whether its average trade after costs is still clearly above zero and whether its net result beats the EMA's.
  4. Run the neighbouring lengths. Repeat the TEMA rule from about 9 to 55 and look for the plateau from the length section. A single good length between two poor ones is a reason to stop.
  5. Confirm on untouched data and decide by a rule written in advance. Keep the most recent block of history out of every run. Write down, before you look, what share of the in-sample average trade must survive on that block for a pass. Then run it once and accept or reject.
Five steps to test TEMA: write the rule with an EMA baseline, set the same costs and fills, compare average trade after costs, check nearby lengths, and test once on untouched data Test TEMA in five steps Untouched data comes last, once 1 2 3 4 5 Rule plus EMA baseline Same costs and next-bar fills Compare average trade Check nearby lengths Test once on untouched data Baseline and costs come first. So: use the untouched data once.
The order matters: the EMA baseline and the cost settings are fixed before any TEMA result is read, and the untouched data is used last and once.

Steps four and five are where most fast-indicator ideas end, and that is the useful outcome: a rule rejected on old data costs nothing. If you want the thresholds for step five applied the same way to every candidate instead of by feel, strategy validation lets you set them once and runs walk-forward analysis as one of its checks. Your next move is small: take one market and one bar size you already trade, run a 20-period EMA price cross and a 20-period TEMA price cross with the same $30 of cost per trade, and write the two trade counts and the two average trades on one line. That line tells you more about TEMA than any chart overlay will.

Frequently asked questions

How is TEMA calculated?

TEMA is three chained exponential moving averages of the same length combined as 3×EMA1 − 3×EMA2 + EMA3. EMA1 is the EMA of price, EMA2 is the EMA of EMA1, and EMA3 is the EMA of EMA2. The subtraction cancels most of the lag that each smoothing step adds, which is why the line sits closer to price than a single EMA of the same length.

What is the difference between TEMA and DEMA?

DEMA uses two EMAs and subtracts the lag estimate once (2×EMA1 − EMA2). TEMA uses three EMAs and subtracts it twice. TEMA therefore turns a little earlier than DEMA of the same length, hugs price more closely, and overshoots more at sharp turns. In a crossover rule TEMA also produces somewhat more trades than DEMA on the same data.

What TEMA length should I set?

Common choices are 9 to 21 for a fast signal line and 50 or more for a trend filter, but the right length depends on the bar size and the market. Test a range of lengths on your own data with costs included and choose from a plateau of neighbouring lengths that behave alike, not the single best value. A length that only works at one value is usually describing noise.

Is TEMA better than EMA for trading?

TEMA turns earlier than an EMA of the same length, which helps in trends and hurts in ranges, where it crosses price far more often. Whether it is better for a given rule can only be settled by running both with identical costs, sessions and next-bar fills and comparing trade count and average trade after costs. On many markets the extra trades of a fast line cost more than the earlier turn earns.

Does TEMA repaint?

No. TEMA is calculated from closed bars only, so once a bar has closed its TEMA value does not change. The overshoot after a sharp turn is a property of the formula, not a redraw of past values. A backtest that fills on the next bar after a TEMA cross is therefore using values that were known at the time.

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.
  • 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