The Triple EMA strategy identifies trends by requiring three Exponential Moving Averages (EMA) to align in a specific hierarchy. This reduces false signals by ensuring momentum is consistent across short, medium, and long timeframes.
EMA Configuration
- Fast EMA (e.g., 12): Captures short-term momentum.
- Medium EMA (e.g., 100): Filters noise and confirms the trend.
- Slow EMA (e.g., 300): Identifies the major trend direction.
Signal Logic
- Bullish (Buy) Signal:
Fast EMA > Medium EMA > Slow EMA (all aligned upward). - Bearish (Sell) Signal:
Fast EMA < Medium EMA < Slow EMA (all aligned downward).
Implementation Example
Use the pandas_ta library to append EMAs to your dataframe, then apply the conditional logic:
import pandas_ta as ta
# Setup periods
ema_short, ema_medium, ema_long = 12, 100, 300
# Calculate EMAs
df.ta.ema(length=ema_short, append=True)
df.ta.ema(length=ema_medium, append=True)
df.ta.ema(length=ema_long, append=True)
# Extract series
short_ema = df[f"EMA_{ema_short}"]
medium_ema = df[f"EMA_{ema_medium}"]
long_ema = df[f"EMA_{ema_long}"]
# Generate signals
long_condition = (short_ema > medium_ema) & (medium_ema > long_ema) & (short_ema > long_ema)
short_condition = (short_ema < medium_ema) & (medium_ema < long_ema) & (short_ema < long_ema)
df["signal"] = 0
df.loc[long_condition, "signal"] = 1
df.loc[short_condition, "signal"] = -1
import pandas_ta as ta
# Calculate EMAs
df.ta.ema(length=12, append=True)
df.ta.ema(length=100, append=True)
df.ta.ema(length=300, append=True)
# Signal logic
long_condition = (df['EMA_12'] > df['EMA_100']) & (df['EMA_100'] > df['EMA_300'])
short_condition = (df['EMA_12'] < df['EMA_100']) & (df['EMA_100'] < df['EMA_300'])
df['signal'] = 0
df.loc[long_condition, 'signal'] = 1
df.loc[short_condition, 'signal'] = -1