What is the Triple Exponential Moving Average (TEMA)?
The Triple Exponential Moving Average (TEMA), introduced by Patrick Mulloy, is an advanced moving average that builds upon the concept of DEMA to reduce lag even further. It's designed to provide an even faster and smoother response to price changes than traditional EMAs and even DEMAs, aiming to get closer to the current price without sacrificing too much smoothing.
In Pine Script, TEMA is a powerful tool for traders who demand highly responsive trend-following indicators for quick market analysis and agile trade execution, especially in fast-moving markets.
Components and Calculation
The calculation of TEMA involves three EMAs of the same specified `length`:
- EMA1: Calculate a standard Exponential Moving Average of the `source` (typically `close`) over a specified `length`.
- EMA2: Calculate an EMA of `EMA1` (the first EMA) over the *same* `length`.
- EMA3: Calculate an EMA of `EMA2` (the second EMA) over the *same* `length`.
- TEMA Formula: `TEMA = (3 * EMA1) - (3 * EMA2) + EMA3`
This formula cleverly combines the three EMAs to effectively remove even more lag than DEMA, providing an extremely smooth and responsive moving average. It attempts to project the current trend more accurately by minimizing the distorting effect of lag.
Basic TEMA Implementation in Pine Script
Pine Script v5 provides a convenient built-in function `ta.tema()` that greatly simplifies its implementation.
//@version=5
indicator("My Triple EMA Indicator", overlay=true)
// Input for TEMA length
length = input.int(20, title="TEMA Length", minval=1)
// Calculate TEMA using the built-in function
temaValue = ta.tema(close, length)
// Plot the TEMA line
plot(temaValue, title="TEMA", color=color.blue, linewidth=2)
Practical TEMA Strategies
1. TEMA as a Trend Direction Filter (Color Change)
TEMA's superior responsiveness makes it an excellent indicator for quickly identifying and staying with the prevailing trend direction. Coloring the TEMA based on its slope is a highly effective visual strategy.
- Uptrend: TEMA is rising (current TEMA > previous TEMA).
- Downtrend: TEMA is falling (current TEMA < previous TEMA).
//@version=5
strategy("TEMA Trend Color Strategy", overlay=true)
// Input for TEMA length
length = input.int(20, title="TEMA Length", minval=1)
// Calculate TEMA
temaValue = ta.tema(close, length)
// Determine TEMA color based on its direction
temaColor = temaValue > temaValue[1] ? color.green : color.red
// Plot the TEMA line with dynamic color
plot(temaValue, title="TEMA", color=temaColor, linewidth=2)
// Example entry logic: buy when TEMA turns green, sell when TEMA turns red
longCondition = temaValue > temaValue[1] and temaValue[1] <= temaValue[2] // TEMA turns up
shortCondition = temaValue < temaValue[1] and temaValue[1] >= temaValue[2] // TEMA turns down
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
2. TEMA Crossover Strategy (with Price or another TEMA)
Crossovers involving TEMA generate extremely fast signals due to its minimal lag. This can be price crossing TEMA, or two TEMAs of different lengths crossing each other for a more refined signal.
//@version=5
strategy("TEMA Crossover Strategy", overlay=true)
// Inputs for TEMA lengths
fastTemaLength = input.int(10, title="Fast TEMA Length", minval=1)
slowTemaLength = input.int(30, title="Slow TEMA Length", minval=1)
// Calculate TEMAs
fastTema = ta.tema(close, fastTemaLength)
slowTema = ta.tema(close, slowTemaLength)
// Plot the TEMAs
plot(fastTema, title="Fast TEMA", color=color.blue, linewidth=2)
plot(slowTema, title="Slow TEMA", color=color.orange, linewidth=2)
// Crossover conditions (Fast TEMA crossing Slow TEMA)
longCondition = ta.crossover(fastTema, slowTema)
shortCondition = ta.crossunder(fastTema, slowTema)
// Strategy entries/exits
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
3. TEMA for Dynamic Support and Resistance
TEMA's ability to hug price closely makes it an excellent candidate for identifying dynamic support in uptrends and dynamic resistance in downtrends. Interactions between price and the TEMA line can offer insights into trend strength and potential areas of interest.
//@version=5
indicator("TEMA Support/Resistance", overlay=true)
length = input.int(20, title="TEMA Length", minval=1)
temaValue = ta.tema(close, length)
plot(temaValue, title="TEMA", color=color.blue, linewidth=2)
// Highlight potential support/resistance interactions (conceptual - adjust thresholds)
// These conditions check for price being very close to TEMA, implying a touch or test
isSupportTouch = close > temaValue * 0.995 and close < temaValue * 1.005 and temaValue[1] < close[1] // Price touches TEMA from below or just above
isResistanceTouch = close < temaValue * 1.005 and close > temaValue * 0.995 and temaValue[1] > close[1] // Price touches TEMA from above or just below
plotshape(isSupportTouch, title="Potential Support", location=location.belowbar, color=color.green, style=shape.circle, size=size.tiny)
plotshape(isResistanceTouch, title="Potential Resistance", location=location.abovebar, color=color.red, style=shape.circle, size=size.tiny)
Optimizing TEMA Performance
To get the most from the Triple Exponential Moving Average in Pine Script:
- Parameter Tuning: The `length` parameter is crucial. While TEMA is inherently low-lag, adjusting the length can fine-tune its responsiveness to different market conditions. Shorter lengths for very aggressive trading, longer lengths for smoother signals.
- Multi-Timeframe Analysis: Despite its speed, always confirm TEMA signals with a higher timeframe's trend. This helps filter out noise and ensures you're trading in the direction of the larger market movement.
- Combine with Other Indicators: TEMA excels at trend following and identifying reversals, but it's not a standalone indicator. Pair it with volume indicators, momentum oscillators (e.g., RSI for overbought/oversold confirmation), or price action analysis for stronger confluence.
- Avoid Choppy Markets: While TEMA's smoothing is superior, no moving average can eliminate all whipsaws in prolonged sideways or non-trending markets. Use a trend strength indicator (e.g., ADX) to confirm a clear trend before relying heavily on TEMA signals.
Common TEMA Pitfalls
- Whipsaws in Extreme Consolidation: Even with triple smoothing, TEMA can still generate false signals in very flat or extremely volatile, non-trending markets.
- Requires Strong Trend: TEMA performs optimally in clear, trending markets. Its signals become less reliable in choppy or range-bound conditions.
- Over-Optimization: As with any indicator, excessive tuning of TEMA's `length` to past data can lead to curve-fitting, where the strategy performs well historically but fails in live trading.
- Not an Overbought/Oversold Indicator: TEMA is a trend-following tool. It does not provide insights into overbought or oversold conditions, which should be assessed using dedicated oscillators.
Conclusion
The Triple Exponential Moving Average (TEMA) represents a significant leap forward in reducing lag in moving averages within Pine Script for TradingView. Its sophisticated calculation provides an exceptionally responsive and smooth line, making it ideal for traders who prioritize timely trend identification and dynamic signal generation. By understanding TEMA's unique characteristics, intelligently tuning its parameters, and integrating it strategically with other analytical tools, you can leverage its power to gain a sharper perspective on market movements and enhance your trading decisions.
Enhance Your Trading
Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Subscribe now @ $99/month