דלגו לתוכן
פתיחת RaamTrade

TEMA — Triple EMA

תוכן זה אינו זמין עדיין בשפה שלך.

Mulloy’s second-order lag correction: three chained EMAs combined so both first- and second-order lag mostly cancel. Faster than DEMA, noisier again.

Signature

TEMA(period, on=<source>)
Argument Type Required Notes
period int Param or literal Yes EMA length. Default 20, bounds 1–400.
on= symbol, OHLCV field, or indicator No Source. Defaults to the trade symbol’s close.

Formula

$$ \text{TEMA} = 3e_1 - 3e_2 + e_3, \quad e_1 = \text{EMA}(C,n),\ e_2 = \text{EMA}(e_1,n),\ e_3 = \text{EMA}(e_2,n) $$

Warmup

The chain seeds from the first value and converges over roughly 3n bars.

Reading the value

tema.value
tema.crossed_above(other)

Example

class TemaPullback(Strategy):
"""Buy the close reclaiming a fast TEMA in an uptrend."""
fast = Param(9, min=1, max=400)
slow = Param(50, min=1, max=400)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
f = TEMA(self.fast, on=self.trade)
s = SMA(self.slow, on=self.trade)
if self.trade.close > s.value and self.trade.close > f.value and self.trade.is_flat:
self.buy(self.trade, reason="Reclaimed TEMA in uptrend")
if self.trade.close < s.value and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Trend gone")

Notes

  • Patrick Mulloy, TASC (1994).
  • Proven by an assert-via-trade run on SPY daily (converged to an independent strategy-side triple-EMA replication within 0.05 after 40 bars; zero alarm trades).
  • Not “an EMA of an EMA of an EMA” — the combination is what removes the lag.
  • The recursion seeds from the first bar rather than from a warm-up window, so early values are not comparable with TA-Lib TEMA(20), which seeds from an average of the first n; measured on a 300-bar tape the two agree to 1e-6 from bar 138 onward.