Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-tema

$ Pinescript Triple EMA (TEMA)

Master this ultra-responsive and virtually lag-free moving average in TradingView's Pinescript for razor-sharp trend identification and powerful reversal signals.

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

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 Pinescript, 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.

02

Components and Calculation

The calculation of TEMA involves three EMAs of the same specified `length`:

  1. EMA1: Calculate a standard Exponential Moving Average of the `source` (typically `close`) over a specified `length`.
  2. EMA2: Calculate an EMA of `EMA1` (the first EMA) over the *same* `length`.
  3. EMA3: Calculate an EMA of `EMA2` (the second EMA) over the *same* `length`.
  4. TEMA Formula: `TEMA = (3 * EMA1) - (3 * EMA2) + EMA3`
03

Basic TEMA Implementation in Pinescript

pine-script@terminal
//@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)
$ ✓ Compiled successfully
04

Ultra-Responsive

Ultra-Responsive

TEMA is celebrated for its ability to reduce lag significantly, making it one of the most responsive moving averages available.

05

Practical TEMA Strategies

06

1. TEMA as a Trend Direction Filter (Color Change)

pine-script@terminal
//@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)
$ ✓ Compiled successfully
07

2. TEMA Crossover Strategy (with Price or another TEMA)

pine-script@terminal
//@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)
$ ✓ Compiled successfully
08

3. TEMA for Dynamic Support and Resistance

pine-script@terminal
//@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)
$ ✓ Compiled successfully
09

Optimizing TEMA Performance

To get the most from the Triple Exponential Moving Average in Pinescript:

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

Speed vs. Noise

Speed vs. Noise

TEMA is designed for speed. This means it might still produce more signals than a heavily smoothed average. Always confirm signals to avoid overtrading.

11

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

Conclusion

Conclusion

The Triple Exponential Moving Average (TEMA) represents a significant leap forward in reducing lag in moving averages within Pinescript 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 Pinescript 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.

Get Pinescript Strategy