> "Patrick Mulloy looked at the lag of an EMA and took it personally. TEMA is what happens when you apply algebra to impatience."
The Triple Exponential Moving Average (TEMA) is a lag-reducing filter that combines a single, double, and triple EMA. Unlike a simple triple smoothing (which would be incredibly slow), TEMA uses a weighted combination of the three to cancel out the lag, resulting in an indicator that hugs price action tighter than a spandex cycling short.
## Historical Context
Introduced by Patrick Mulloy in *Technical Analysis of Stocks & Commodities* (Jan 1994), "Smoothing Data With Less Lag." Mulloy's goal was to replace the standard moving averages in MACD and other indicators to reduce the delay in signal generation.
## Architecture & Physics
TEMA is not just "EMA applied three times." That would be $EMA(EMA(EMA(x)))$. TEMA is a composite:
This formula effectively projects the trend forward to compensate for the delay inherent in smoothing.
### Convergence Speed
Because of the aggressive weighting, TEMA converges (warms up) faster than a standard EMA. While an EMA takes $\approx 3.45(N+1)$ steps to converge to 99.9%, TEMA stabilizes quicker due to the subtraction terms canceling out the initial error.
TEMA requires 3 cascaded EMA updates plus the combination formula:
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| EMA update (×3) | 3 | 7 | 21 |
| MUL (3×e1, 3×e2) | 2 | 3 | 6 |
| SUB (3×e1 - 3×e2) | 1 | 1 | 1 |
| ADD (+ e3) | 1 | 1 | 1 |
| **Total (hot)** | **7** | — | **~29 cycles** |
During warmup, each EMA stage has additional compensator overhead (~21 cycles × 3 = ~63 cycles).
**Total during warmup:** ~92 cycles/bar; **Post-warmup:** ~29 cycles/bar.
### Batch Mode (SIMD Analysis)
TEMA is inherently recursive due to cascaded EMAs. SIMD parallelization across bars is not possible. Each EMA stage must complete before feeding the next:
| Optimization | Operations | Cycles Saved |
| :--- | :---: | :---: |
| FMA in each EMA stage | 3 FMA vs 3×(MUL+ADD) | ~6 cycles |
The `E` field tracks bias compensation factor for each EMA stage independently. Each state auto-transitions via `IsCompensated` flag when bias becomes negligible.
### Precomputed Constants
Constructor calculates smoothing constants once:
```csharp
_alpha=2.0/(period+1);
_decay=1-_alpha;
```
These constants are reused across all three EMA stages, avoiding repeated division.
### FMA Usage
Each EMA update uses FusedMultiplyAdd for the standard EMA formula:
The final TEMA combination `3*e1 - 3*e2 + e3` could use FMA but the coefficients (3, -3, 1) make chained FMA marginal; current implementation uses direct arithmetic.
### Bar Correction Pattern
TEMA's cascaded structure requires coordinated state rollback:
```csharp
if(isNew)
{
_p_state1=_state1;
_p_state2=_state2;
_p_state3=_state3;
}
else
{
_state1=_p_state1;
_state2=_p_state2;
_state3=_p_state3;
}
```
All three stages rollback atomically, ensuring consistent cascade state when `isNew=false`.