TradingView indicators

TEMA on TradingView: formula and limits

The TEMA indicator combines three EMA stages to reduce smoothing delay: 3 × EMA1 − 3 × EMA2 + EMA3. It remains a line in price units. The subtraction matters: a triple-smoothed EMA alone is not TEMA, and the combined line can overshoot price.

E1 = EMA(source, N)

E2 = EMA(E1, N)

E3 = EMA(E2, N)

TEMA = 3 × E1 − 3 × E2 + E3

Formula: TradingView Triple EMA documentation. The worked example below checks what that formula does after a price step.

Copy the TEMA code

A price step exposes the overshoot

This is a synthetic calculation, not market data or a backtest. Set N = 3, so α = 2/(N + 1) = 0.5. Seed all three stages at 100 on bar 0. Price jumps to 108 on bar 1 and then stays there. Each stage uses its current input and its own previous value; retain full precision until display.

E1[t] = 0.5 × price[t] + 0.5 × E1[t−1]

E2[t] = 0.5 × E1[t] + 0.5 × E2[t−1]

E3[t] = 0.5 × E2[t] + 0.5 × E3[t−1]

Demonstration: N = 3; every output is in source price units.
BarPriceE1 (EMA)E2E3DEMATEMA
0 (seed)100100100100100100
1 (step)108104102101106107
2 (flat)108106104102.5108108.5
3 (flat)108107105.5104108.5108.5
4 (flat)108107.5106.5105.25108.5108.25
5 (flat)108107.75107.125106.1875108.375108.0625

Check bar 2 by hand: E1 = 106, E2 = 104 and E3 = 102.5. Then TEMA = 318 − 312 + 102.5 = 108.5. The source has never exceeded 108. The negative coefficient on E2 means TEMA is not constrained to the source range as a positive-weight average would be.

At bar 1, price is above TEMA (108 versus 107). At bar 2, price is below TEMA (108 versus 108.5), even though price has not fallen. By bar 4, TEMA is declining while price remains flat. A crossing or slope change describes the filter output; it does not by itself establish a market reversal.

DEMA reaches the same 108.5 peak one bar later in this particular sequence. That is a property of this input and seed, not a universal one-bar advantage for TEMA.

TEMA Pine Script v6

The example keeps the three EMA stages separate so the calculation can be inspected. The expression 3 × (E1 − E2) + E3 is algebraically identical to the formula. Length 9 and close are editable defaults, not recommended settings.

Pine Script v6
//@version=6
indicator(title="Triple EMA", overlay=true, max_labels_count=500)

// Inputs
length = input.int(9, "Length", minval=1)
src = input.source(close, "Source")

// TEMA Calculation
e1 = ta.ema(src, length)
e2 = ta.ema(e1, length)
e3 = ta.ema(e2, length)
tema = 3 * (e1 - e2) + e3

// Plot
plot(tema, "TEMA", color.rgb(41, 98, 255, 0), 2)
  1. Paste the complete code into the TradingView Pine Editor, save it and add it to the chart.
  2. Set the same source and length on any comparison indicator. A 9-bar setting means nine chart bars, not necessarily nine days.
  3. Inspect closed-bar values before interpreting crossings. The script plots one line and contains no alerts or orders.

For N = 1 and a defined source, α = 1: all three EMA stages equal the source and TEMA equals it too. This is a useful boundary check; it leaves no smoothing. Changing the source to hl2 changes the input series and does not guarantee fewer crossings.

Initialization and warm-up checks

An EMA is recursive. Its previous value carries older observations beyond the nominal N bars. The table explicitly seeds every stage at 100; that assumption is part of the example, not a claim that every chart or library starts that way.

For a single EMA with identical later inputs, an initial difference δ shrinks to δ × (1 − α)^k after k updates. In TEMA, differences also propagate from E1 into E2 and E3. A first nonmissing output is not proof of convergence, and exactly 3 × N bars is not a universal warm-up guarantee.

  1. Match symbol, chart timeframe, source, session and price adjustments before comparing values.
  2. Compare the intermediate stages. If E1 agrees but E2 does not, inspect the second-stage seed and history instead of changing the final coefficients.
  3. Repeat the calculation with an earlier history start. On the overlapping bars, record the maximum absolute TEMA difference and compare it with an explicit tolerance suitable for the intended use.
  4. Keep missing values visible during diagnosis. Replacing unavailable prices with zero creates a new input sequence and may create an artificial jump.

On a live bar, close and the plotted TEMA can update together. A temporary crossing may disappear by the close. If a later script adds signals, define whether it requires barstate.isconfirmed. Confirmation timing does not establish profitability or specify when a strategy order fills.

References: EMA recursion and Pine execution on realtime bars.

TEMA, DEMA and TRIX measure different things

OutputCalculationMeaning
EMAE1One smoothing stage; source units
DEMA2 × E1 − E2Two-stage combination; source units
TEMA3 × E1 − 3 × E2 + E3Three-stage combination; source units
TRIX (percent)100 × (E3[t] / E3[t−1] − 1)One-bar rate of change; percent

DEMA uses stages through E2; TEMA adds E3 and changes the coefficients. Calling either one merely a double- or triple-smoothed average omits its subtraction. TradingView documents the DEMA formula.

For percentage TRIX on bar 2 of the example, 100 × (102.5 / 101 − 1) is about 1.48515%. That number describes the change in E3, while TEMA is 108.5 price units. A TRIX implementation using log-price changes has a different definition and scale. The percentage form requires a nonzero prior E3. TradingView describes TRIX as a one-period percentage change.

Turn the calculation into a checkable script

Use the Pine Script AI Coding Agent to describe the inputs and observation rules you need. Ask for inspectable intermediate values before adding trading logic.

Create a TEMA indicator with editable length and source. Use three EMA stages with the same length and combine them as 3 × E1 − 3 × E2 + E3. Expose all stages for inspection. Add optional close-confirmed price-cross markers. Document initialization and missing-value handling. Keep orders out of this indicator.

Compare the resulting values bar by bar, including a flat interval after a price step. If you later create a strategy, define exits, position sizing, commissions, slippage and execution timing separately. Syntax validation cannot verify those assumptions or trading results.

Open Pine Script AI Coding Agent

Educational calculations, not investment advice. The examples provide no evidence of expected returns.

TEMA questions

TEMA combines three successive EMA stages as 3 × E1 − 3 × E2 + E3. Each stage uses the same length, and the result stays in the source units. Plotting E3 alone produces a different line. TEMA is not a forecast of the next price.

No. The formula compensates for smoothing delay, but it does not remove every form of delay. In the synthetic example, the first step to 108 produces TEMA of 107; later it overshoots to 108.5 while price stays at 108. Neither response establishes a fixed number of bars of lead.

TEMA combines EMA levels and can be plotted on the price chart. Percentage TRIX measures the one-bar percentage change of the third EMA, so it is an oscillator. Even with the same source and length, their values and zero crossings answer different questions.

This page establishes no best length or timeframe. The code starts at 9 bars with close as the source. The arithmetic example uses 3 bars for readable numbers. Compare several settings on the same data, keeping the source and confirmation timing fixed; a default is not evidence of profitability.

The EMA stages keep adjusting after a price step. Their weighted combination can exceed every observed price in the example. At bar 2, TEMA is 108.5 while price is still 108. A price-below-TEMA condition can therefore appear without a new price decline.

A numeric output does not prove that its initial values no longer matter. Check convergence by recalculating the same overlapping bars with a longer history and comparing the differences against a stated tolerance. Three EMA stages do not imply a universal warm-up of exactly three times the length.

The example plots continuously and contains no signals, alerts or orders. With close as its source, the current TEMA value can change before the bar closes. If you add a crossing rule, state whether it requires barstate.isconfirmed, and keep order execution rules separate from indicator confirmation.

Paste the code into the Pine Editor, save it and add it to the chart. Match length, source, symbol, timeframe and price adjustments when comparing another implementation. If values disagree, compare E1, E2 and E3 before the final combination, then check history and initialization.

Sources and related indicators

Documentation checked October 17, 2026. The numeric table is an original demonstration with stated assumptions.

Continue with EMA, DEMA or TRIX, or browse the TradingView indicators category.