🪙
 Get student discount & enjoy best sellers ~$7/week

Triple Exponential Average (TEMA)

The Triple Exponential Moving Average (TEMA) is a sophisticated technical indicator designed to help traders identify trends with greater speed and accuracy than traditional moving averages. By combining three exponential moving averages into a single, responsive line, TEMA reduces lag and filters out market noise, making it a favorite among trend-followers and algorithmic traders alike. In this comprehensive guide, you'll learn everything about TEMA: from its mathematical foundation to real-world trading strategies, code implementations, and advanced usage scenarios.

1. Hook & Introduction

Imagine you're a trader frustrated by the slow signals of simple moving averages. You miss early entries and get whipsawed in choppy markets. Enter the Triple Exponential Moving Average (TEMA). TEMA promises faster trend detection and less noise, giving you a sharper edge in volatile markets. In this article, you'll master TEMA's logic, see real code, and learn how to use it for smarter trades.

2. What is Triple Exponential Moving Average (TEMA)?

TEMA is a trend-following indicator invented by Patrick Mulloy in 1994. Unlike the Simple Moving Average (SMA) or Exponential Moving Average (EMA), TEMA combines three EMAs to create a line that reacts quickly to price changes but remains smooth. This unique construction helps traders spot trends earlier and avoid false signals caused by market noise. TEMA is especially useful for active traders who need timely signals without sacrificing reliability.

3. Mathematical Formula & Calculation

The TEMA formula is designed to minimize lag while maintaining smoothness. The calculation involves three EMAs:

TEMA = (3 × EMA1) - (3 × EMA2) + EMA3
  • EMA1: EMA of the price (short period, e.g., 9)
  • EMA2: EMA of EMA1 (medium period, e.g., 13)
  • EMA3: EMA of EMA2 (long period, e.g., 21)

By combining these EMAs, TEMA reduces the lag found in traditional moving averages. The result is a line that closely tracks price action but remains smooth enough to filter out random fluctuations.

4. Step-by-Step Calculation Example

Let's walk through a TEMA calculation using sample closing prices: [10, 12, 14, 13, 15].

  • Step 1: Calculate EMA1 (period 9) on the price series.
  • Step 2: Calculate EMA2 (period 13) on EMA1 values.
  • Step 3: Calculate EMA3 (period 21) on EMA2 values.
  • Step 4: Plug the results into the TEMA formula: (3 × EMA1) - (3 × EMA2) + EMA3.

This process can be automated in any programming language. See the code section below for real-world implementations.

5. How Does TEMA Work in Practice?

TEMA acts as a dynamic trend filter. When the TEMA line crosses above the price, it may signal a bullish trend. When it crosses below, it may indicate a bearish trend. Unlike SMA or EMA, TEMA responds faster to price changes, allowing traders to enter and exit positions with less delay. However, in sideways markets, TEMA can still produce false signals, so it's best used in trending environments.

6. Comparison: TEMA vs. Other Moving Averages

How does TEMA stack up against other popular moving averages?

IndicatorLagSmoothnessBest Use
SMAHighMediumLong-term trends
EMAMediumMediumShort/medium trends
DEMALowHighFaster signals
TEMALowestHighFast, smooth trend signals

TEMA offers the lowest lag and high smoothness, making it ideal for traders who want quick, reliable trend signals.

7. Real-World Trading Scenarios

Consider a swing trader monitoring a volatile tech stock. Using SMA, they often enter trades late and exit after the trend has reversed. Switching to TEMA, they notice earlier entries and exits, capturing more profit from each move. In another scenario, a day trader uses TEMA to filter out noise during high-volume sessions, avoiding whipsaws that plague other indicators.

8. Combining TEMA with Other Indicators

TEMA works best when combined with momentum indicators like RSI or MACD. For example, a bullish TEMA crossover confirmed by RSI above 50 can be a strong buy signal. Avoid pairing TEMA with other moving averages to prevent redundant signals. Instead, use it alongside volume or volatility filters for more robust strategies.

9. Code Implementations: TEMA in Multiple Languages

Below are real-world code examples for calculating TEMA in C++, Python, Node.js, Pine Script, and MetaTrader 5. Use these snippets to integrate TEMA into your trading systems.

// C++ TEMA Calculation Example
#include <vector>
#include <numeric>
double ema(const std::vector<double>& data, int period) {
    double alpha = 2.0 / (period + 1);
    double ema = data[0];
    for (size_t i = 1; i < data.size(); ++i) {
        ema = alpha * data[i] + (1 - alpha) * ema;
    }
    return ema;
}
double tema(const std::vector<double>& data, int p1, int p2, int p3) {
    std::vector<double> ema1, ema2, ema3;
    for (size_t i = 0; i < data.size(); ++i) {
        ema1.push_back(ema(std::vector<double>(data.begin(), data.begin() + i + 1), p1));
    }
    for (size_t i = 0; i < ema1.size(); ++i) {
        ema2.push_back(ema(std::vector<double>(ema1.begin(), ema1.begin() + i + 1), p2));
    }
    for (size_t i = 0; i < ema2.size(); ++i) {
        ema3.push_back(ema(std::vector<double>(ema2.begin(), ema2.begin() + i + 1), p3));
    }
    return (3 * ema1.back()) - (3 * ema2.back()) + ema3.back();
}
# Python TEMA Calculation Example
def ema(data, period):
    alpha = 2 / (period + 1)
    ema_values = [data[0]]
    for price in data[1:]:
        ema_values.append(alpha * price + (1 - alpha) * ema_values[-1])
    return ema_values

def tema(data, p1=9, p2=13, p3=21):
    ema1 = ema(data, p1)
    ema2 = ema(ema1, p2)
    ema3 = ema(ema2, p3)
    return [(3 * e1) - (3 * e2) + e3 for e1, e2, e3 in zip(ema1, ema2, ema3)]

prices = [10, 12, 14, 13, 15]
tema_values = tema(prices)
// Node.js TEMA Calculation Example
function ema(data, period) {
  const alpha = 2 / (period + 1);
  let emaArr = [data[0]];
  for (let i = 1; i < data.length; i++) {
    emaArr.push(alpha * data[i] + (1 - alpha) * emaArr[i - 1]);
  }
  return emaArr;
}
function tema(data, p1 = 9, p2 = 13, p3 = 21) {
  const ema1 = ema(data, p1);
  const ema2 = ema(ema1, p2);
  const ema3 = ema(ema2, p3);
  return ema1.map((e1, i) => 3 * e1 - 3 * ema2[i] + ema3[i]);
}
const prices = [10, 12, 14, 13, 15];
const temaValues = tema(prices);
// Pine Script TEMA Example
//@version=5
indicator("Triple Exponential Moving Average (TEMA)", overlay=true)
length1 = input.int(9, title="Short EMA")
length2 = input.int(13, title="Medium EMA")
length3 = input.int(21, title="Long EMA")
ema1 = ta.ema(close, length1)
ema2 = ta.ema(ema1, length2)
ema3 = ta.ema(ema2, length3)
tema = (3 * ema1) - (3 * ema2) + ema3
plot(tema, color=color.red, title="TEMA")
// Buy: tema crosses above close
// Sell: tema crosses below close
// MetaTrader 5 TEMA Example
#property indicator_chart_window
input int length1 = 9;
input int length2 = 13;
input int length3 = 21;
double ema1[], ema2[], ema3[], tema[];
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[])
{
   ArraySetAsSeries(close, true);
   ArrayResize(ema1, rates_total);
   ArrayResize(ema2, rates_total);
   ArrayResize(ema3, rates_total);
   ArrayResize(tema, rates_total);
   for(int i=0; i<rates_total; i++) {
      ema1[i] = iMA(NULL, 0, length1, 0, MODE_EMA, PRICE_CLOSE, i);
      ema2[i] = iMAOnArray(ema1, 0, length2, 0, MODE_EMA, i);
      ema3[i] = iMAOnArray(ema2, 0, length3, 0, MODE_EMA, i);
      tema[i] = (3 * ema1[i]) - (3 * ema2[i]) + ema3[i];
   }
   return(rates_total);
}

10. Customizing TEMA for Your Strategy

You can adjust TEMA's sensitivity by changing the periods for EMA1, EMA2, and EMA3. Shorter periods make TEMA more responsive but may increase false signals. Longer periods smooth the line but add lag. Test different settings to find the optimal balance for your trading style and asset class.

11. Backtesting & Performance

Backtesting is crucial to evaluate TEMA's effectiveness. Here's a sample Python backtest setup:

# Python Backtest Example
import pandas as pd
import numpy as np
def ema(data, period):
    alpha = 2 / (period + 1)
    ema_values = [data[0]]
    for price in data[1:]:
        ema_values.append(alpha * price + (1 - alpha) * ema_values[-1])
    return ema_values
def tema(data, p1=9, p2=13, p3=21):
    ema1 = ema(data, p1)
    ema2 = ema(ema1, p2)
    ema3 = ema(ema2, p3)
    return [(3 * e1) - (3 * e2) + e3 for e1, e2, e3 in zip(ema1, ema2, ema3)]
data = pd.read_csv('prices.csv')
data['tema'] = tema(data['close'].tolist())
data['signal'] = np.where(data['tema'] > data['close'], 1, -1)
# Calculate returns, win rate, risk/reward, etc.

In trending markets, TEMA often delivers higher win rates and better risk/reward than SMA or EMA. In sideways markets, however, it can produce whipsaws. Always test TEMA on multiple assets and timeframes before live trading.

12. Advanced Variations

Advanced traders may experiment with alternative periods, volume-weighted TEMA, or combining TEMA with volatility filters. Institutions sometimes use TEMA as part of multi-indicator systems for high-frequency trading or options strategies. For scalping, use shorter periods; for swing trading, use longer periods and confirm with other indicators.

13. Common Pitfalls & Myths

  • Myth: TEMA eliminates lag entirely. Reality: It reduces lag but does not remove it.
  • Pitfall: Using TEMA in isolation. Solution: Always confirm with price action or other indicators.
  • Pitfall: Assuming TEMA works in all market conditions. Solution: Use TEMA primarily in trending markets.
  • Pitfall: Over-optimizing periods. Solution: Test on out-of-sample data to avoid curve fitting.

14. Conclusion & Summary

The Triple Exponential Moving Average (TEMA) is a powerful tool for traders seeking faster, smoother trend signals. Its unique formula reduces lag and filters noise, making it ideal for active trading in trending markets. However, like all indicators, TEMA is not foolproof. Combine it with other tools, backtest thoroughly, and use it as part of a disciplined trading plan. For related indicators, explore the Exponential Moving Average (EMA) and Double Exponential Moving Average (DEMA) to expand your technical analysis toolkit.

Frequently Asked Questions about Triple Exponential Average (TEMA)

What is the purpose of using Triple Exponential Moving Average (TEMA)?

The purpose of using TEMA is to provide a more accurate representation of market trends by smoothing out short-term fluctuations and providing a longer-term perspective.

How is TEMA different from other moving average indicators?

TEMA is different from other moving average indicators because it uses three exponential periods (9, 13, and 21 days) instead of one. This reduces the impact of short-term price fluctuations and provides a longer-term perspective.

What are some advantages of using TEMA in technical analysis?

The use of TEMA offers several advantages in technical analysis, including providing a more accurate representation of market trends, smoothing out short-term fluctuations, and providing a longer-term perspective.

Can I use TEMA for day trading?

While TEMA can be used for day trading, it is generally recommended to use it for longer-term analysis. The three exponential periods of TEMA are designed to provide a more accurate representation of market trends over the long term.

How do I calculate TEMA?

To calculate TEMA, you need to take the average of three exponential moving averages with different time periods: 9, 13, and 21 days. The formula is as follows: TEMA = (A + B + C) / 3.

What are some common buy and sell signals using TEMA?

The TEMA line acts as a moving average, showing the trend direction and strength over a longer period. When the TEMA line crosses above or below the price data, it indicates a potential buy or sell signal.



How to post a request?

Posting a request is easy. Get Matched with experts within 5 minutes

  • 1:1 Live Session: $60/hour
  • MVP Development / Code Reviews: $200 budget
  • Bot Development: $400 per bot
  • Portfolio Optimization: $300 per portfolio
  • Custom Trading Strategy: $99 per strategy
  • Custom AI Agents: Starting at $100 per agent
Professional Services: Trading Debugging $60/hr, MVP Development $200, AI Trading Bot $400, Portfolio Optimization $300, Trading Strategy $99, Custom AI Agent $100. Contact for expert help.
⭐⭐⭐ 500+ Clients Helped | 💯 100% Satisfaction Rate


Was this content helpful?

Help us improve this article