Multi-Exponential Moving Average with Directional Trend Filter Trading System
FMZQuant

FMZQuant @fmzquant

Joined:
Apr 25, 2024

Multi-Exponential Moving Average with Directional Trend Filter Trading System

Publish Date: Apr 15
1 1

Image description

Image description

Overview
The Multi-Exponential Moving Average with Directional Trend Filter Trading System is a quantitative trading strategy that combines short-term, medium-term, and long-term Exponential Moving Averages (EMAs) with the Average Directional Index (ADX). This strategy primarily utilizes the crossover points between the 5-period and 8-period EMAs to determine entry signals, while using the 13-period EMA as a stop loss point, and optionally employs the ADX indicator as a trend strength filter to improve the quality of trading signals. This combination approach can capture short-term price movements in the market while confirming trend strength through the ADX indicator, thereby reducing false signals and improving trading win rates.

Strategy Principles
The core logic of this strategy is based on the crossover relationships of multiple-period EMA lines and trend strength confirmation from the ADX indicator:

Entry Conditions:

  • Long Entry: A long signal is generated when the 5-period EMA crosses above the 8-period EMA.
  • Short Entry: A short signal is generated when the 5-period EMA crosses below the 8-period EMA.
  • If the ADX filter is enabled, the above trading signals are only executed when the ADX value is higher than a set threshold (default is 20), indicating that the market has sufficient trend strength.

Exit Conditions:

  • Long Exit: The system closes the long position when the price falls below the 13-period EMA.
  • Short Exit: The system closes the short position when the price rises above the 13-period EMA.

Technical Indicator Calculations:

  • The strategy uses the ta.ema function to calculate exponential moving averages for three different periods (5, 8, and 13).
  • The ta.dmi function is used to calculate the 14-period ADX indicator, including +DI, -DI, and ADX values.
  • The ta.crossover and ta.crossunder functions are used to detect moving average crossovers.

The operating mechanism of this strategy demonstrates a simple yet effective trend-following logic: the crossover of the short-term moving average (5-period EMA) with the medium-term moving average (8-period EMA) provides entry signals, the long-term moving average (13-period EMA) provides stop-loss criteria, and the ADX indicator serves as an additional filtering condition to help identify strong trend environments and reduce false signals in sideways markets.

Strategy Advantages
Through an in-depth analysis of the strategy's code implementation, the following significant advantages can be summarized:

  1. High Flexibility: The strategy design allows users to independently choose whether to enable long trades, short trades, and the ADX filter, with easy adjustment through input.bool parameters. This flexibility enables the strategy to adapt to different market environments and trader preferences.

  2. Multiple Confirmation Mechanisms: By combining EMAs of different periods and the ADX indicator, the strategy establishes multiple confirmation mechanisms, reducing the risk of false signals that might arise from a single indicator.

  3. Clear Entry and Exit Rules: The code defines clear entry conditions (moving average crossovers) and exit conditions (price relationship with moving averages), eliminating subjective factors in trading decisions.

  4. Trend Strength Filtering: The optional ADX filter helps identify trends with sufficient momentum, avoiding frequent trading in weak trend or sideways markets, thereby reducing trading costs and risks.

  5. Intuitive Visualization: The strategy plots all key indicators on the chart (three EMA lines, ADX value, and ADX threshold line), allowing traders to intuitively understand and verify trading signals.

  6. Integrated Money Management: The strategy adopts a position size calculation method based on account equity percentage (default_qty_type=strategy.percent_of_equity), which is a healthy risk management practice.

Strategy Risks
Despite its many advantages, the following potential risks can be identified through code analysis:

  1. Lag Issues: All strategies based on moving averages have inherent lag, which may lead to late entries or exits in rapidly changing markets, missing optimal price points. The solution is to consider adding other leading indicators as supplements or adjusting EMA periods to reduce lag.

  2. Overtrading Risk: In oscillating markets, short-period EMAs (such as 5-period) may frequently cross medium-period EMAs (such as 8-period), resulting in excessive trading signals and unnecessary commission expenses. This issue can be mitigated by increasing the ADX threshold or adding additional filtering conditions.

  3. Single Exit Mechanism: The strategy relies solely on the relationship between price and the 13-period EMA as the exit condition, lacking a take-profit mechanism and dynamic stop-loss adjustment. This may lead to premature exits in strongly trending markets or excessive profit loss in reversal markets. It is recommended to add other exit criteria, such as fixed take-profit levels or trailing stops.

  4. Parameter Sensitivity: Strategy performance may be highly sensitive to parameter settings such as EMA periods and ADX thresholds. Different markets and timeframes may require different parameter settings, making thorough historical backtesting and parameter optimization crucial.

  5. Lack of Volatility Consideration: The strategy does not directly consider market volatility factors, which may lead to more false signals during periods of high volatility. Consider integrating the ATR (Average True Range) indicator to adjust trading size or set dynamic stop-loss levels.

Strategy Optimization Directions
Based on code analysis, the following are potential optimization directions for this strategy:

  1. Dynamic Parameter Adjustment: Implement a dynamic adjustment mechanism for EMA periods and ADX thresholds, automatically optimizing parameters based on market volatility and trading timeframes. This optimization is valuable because different market environments may require different parameter settings for optimal performance.

  2. Add Take-Profit Mechanism: The current strategy only has stop-loss exits without a clear take-profit mechanism. Adding take-profit conditions based on fixed ratios, ATR multiples, or key resistance/support levels can lock in profits in favorable market conditions.

  3. Integrate Volume Confirmation: Using volume indicators as additional confirmation conditions can improve signal quality. For example, requiring moving average crossovers to occur in environments with above-average trading volume to confirm the validity of price breakouts.

  4. Market Environment Filtering: Develop a market environment classification system (trending, oscillating, or transitioning) and adjust strategy behavior according to different environments. For example, it might be more appropriate to disable the strategy or adjust it to a mean-reversion strategy in oscillating markets.

  5. Multi-Timeframe Analysis: Integrate trend direction judgments from higher timeframes, only trading in directions consistent with higher timeframe trends to improve the reliability of trend following.

  6. Optimize ADX Application: The current ADX application only considers its absolute value. It can be further refined to consider the change trend of ADX and the relative relationship between +DI and -DI for a more comprehensive assessment of trend strength and direction.

  7. Introduce Machine Learning Models: Use machine learning techniques to analyze historical data, predict the reliability of EMA crossover signals, or dynamically optimize ADX thresholds to improve the strategy's adaptability.

Summary
The Multi-Exponential Moving Average with Directional Trend Filter Trading System is a comprehensive trading system that combines the classic moving average crossover strategy with trend strength indicators in technical analysis. Through the gradient combination of 5-8-13 period EMAs and the ADX filter, this strategy can identify market trends while filtering low-quality signals through trend strength confirmation, achieving more precise timing for trades.

The strategy's advantages lie in its flexibility, clear trading rules, and multiple confirmation mechanisms, making it suitable for most traders to use. However, it also faces inherent lag in moving averages and the risk of overtrading in oscillating markets. By introducing dynamic parameter adjustments, adding take-profit mechanisms, integrating volume confirmation, and multi-timeframe analysis, this strategy has the potential to further improve its performance and adaptability.

For investors seeking to use technical indicators for trend-following trading, this strategy provides a good starting point that is both simple to understand and has sufficient depth for further optimization. Both beginners and experienced traders can gain insights from the implementation of this strategy and make personalized adjustments according to their risk preferences and market views.

Strategy source code

/*backtest
start: 2025-01-01 00:00:00
end: 2025-04-07 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sebamarghella

//@version=5
strategy("[SM-042] EMA 5-8-13 with ADX Filter", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, currency=currency.USD, commission_type=strategy.commission.percent)

// === INPUTS ===
enableLong     = input.bool(true,  title="Enable Long Trades")
enableShort    = input.bool(true,  title="Enable Short Trades")
useAdxFilter   = input.bool(false,  title="Use ADX Filter")
adxThreshold   = input.int(20,     title="ADX Threshold")

// === EMA CALCULATIONS ===
ema5  = ta.ema(close, 5)
ema8  = ta.ema(close, 8)
ema13 = ta.ema(close, 13)

// === ADX FILTER ===
[plusDI, minusDI, adxValue] = ta.dmi(14, 14)
adxCondition = adxValue > adxThreshold

// === ENTRY CONDITIONS ===
longCondition  = ta.crossover(ema5, ema8)  and enableLong  and (not useAdxFilter or adxCondition)
shortCondition = ta.crossunder(ema5, ema8) and enableShort and (not useAdxFilter or adxCondition)

// === EXIT CONDITIONS ===
longExit  = close < ema13
shortExit = close > ema13

// === STRATEGY EXECUTION ===
if (longCondition)
    strategy.entry("Long", strategy.long)

if (shortCondition)
    strategy.entry("Short", strategy.short)

if (strategy.position_size > 0 and longExit)
    strategy.close("Long")

if (strategy.position_size < 0 and shortExit)
    strategy.close("Short")

// === PLOTTING ===
plot(ema5,  title="EMA 5",  color=color.blue)
plot(ema8,  title="EMA 8",  color=color.yellow)
plot(ema13, title="EMA 13", color=color.purple)

hline(adxThreshold, "ADX Threshold", color=color.gray, linestyle=hline.style_dotted)
plot(adxValue, title="ADX", color=color.orange)
Enter fullscreen mode Exit fullscreen mode

Strategy parameters

Image description

The original address: Multi-Exponential Moving Average with Directional Trend Filter Trading System

Comments 1 total

  • Rebecca Chow
    Rebecca ChowJun 26, 2025

    Nice use of multi-EMA layers with directional filtering! The phased confirmation approach seems effective for trend-following, but how does it handle sudden volatility spikes? Have you tested different EMA combinations for various asset classes? Also curious about the trade duration—does it automatically adjust to changing market conditions? Clean strategy design overall. Would love to see how it performs in different macro environments!

Add comment