Dual EMA Multi-Target Trading Strategy

EMA SMA TP SL 移动平均线 止损 多目标策略 交叉信号
Created on: 2025-08-21 09:01:39 Modified on: 2025-08-21 09:01:39
Copy: 0 Number of hits: 212
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 Dual EMA Multi-Target Trading Strategy  Dual EMA Multi-Target Trading Strategy

Overview

The Dual EMA Multi-Target Trading Strategy is a quantitative trading system based on crossover signals between short-term and long-term Exponential Moving Averages (EMA). This strategy utilizes the crossover of 9-period and 21-period EMAs as entry signals, while simultaneously setting up to 10 profit targets and a stop loss point to achieve risk management and profit maximization. The strategy supports both long and short trading: entering long positions when the short-term EMA crosses above the long-term EMA, entering short positions when the short-term EMA crosses below the long-term EMA, and exiting on reverse crossovers.

Strategy Principles

The core principle of this strategy is based on an EMA crossover system, implemented as follows: 1. Calculate two EMAs: a fast EMA (9-period) and a slow EMA (21-period) 2. Generate a long signal when the fast EMA crosses above the slow EMA 3. Generate a short signal when the fast EMA crosses below the slow EMA 4. After entry, the strategy automatically calculates 10 tiered target levels (TP1-TP10) and a stop loss level based on entry price 5. The strategy applies the same percentage settings for both long and short positions, but in opposite directions 6. For long positions, stop loss is set 0.5% below entry price, with profit targets ranging from 0.5% to 5.0% above entry price 7. For short positions, stop loss is set 0.5% above entry price, with profit targets ranging from 0.5% to 5.0% below entry price 8. The strategy also exits positions when a reverse crossover signal occurs

The strategy employs a systematic risk management approach, using 10% of account equity for each trade by default, with an initial capital of 100,000, and prohibits pyramiding.

Strategy Advantages

  1. Simple and Effective Entry Signals: EMA crossovers are widely used and validated trading signals that are easy to understand and implement. The 921 period parameter setting effectively captures medium to short-term trends.
  2. Multi-Target Profit Management: Setting 10 tiered profit targets allows traders to secure profits at different price levels, both locking in partial profits and allowing profits to extend as far as possible.
  3. Strict Risk Control: Each trade has a clearly defined stop loss point, limiting the maximum loss percentage per trade and effectively controlling risk.
  4. Visual Assistance: The strategy clearly marks all entry signals, stop loss levels, and target levels on the chart, helping traders intuitively understand market conditions.
  5. Bidirectional Trading Capability: The strategy supports both long and short trading, enabling opportunity seeking in various market environments.
  6. Parameter Adjustability: All key parameters (including EMA periods, stop loss percentage, profit targets) can be customized through inputs, increasing the strategy’s flexibility.
  7. Full Automation: Strategy execution is fully automated, from signal identification to entry, setting stop losses and profit targets, to exit, requiring no manual intervention.

Strategy Risks

  1. False Breakout Risk: EMA crossover systems are prone to false signals in oscillating markets, potentially leading to frequent trades and losses. The strategy lacks filters to distinguish between strong and weak signals.
  2. Tight Stop Loss: The default stop loss setting of 0.5% may be too tight in more volatile markets or instruments, easily triggered by market noise.
  3. Single Indicator Dependence: The strategy relies solely on EMA crossovers as entry signals, without combining other technical indicators or market conditions for confirmation, increasing the risk of misjudgment.
  4. Fixed Capital Management: Each trade uses a fixed 10% of account equity, without dynamically adjusting based on market volatility or signal strength, which may not be optimal.
  5. Lack of Market Environment Recognition: The strategy does not distinguish between trending and oscillating markets, generating signals even in market environments not suitable for EMA crossover systems.
  6. Limited Exit Strategy: Although multiple profit targets are set, the strategy actually only closes positions at the first target level (TP1) or exits on reverse crossovers, not implementing true partial profit-taking.

To mitigate these risks, it is recommended to introduce additional filtering conditions, such as trend strength indicators, and consider dynamically adjusting stop loss and target level settings based on market volatility.

Strategy Optimization Directions

  1. Add Filters: Introduce additional technical indicators as filters, such as ADX (Average Directional Index) to confirm trend strength, or RSI (Relative Strength Index) to avoid trading in overbought/oversold areas.
  2. Dynamic Stop Loss: Change the fixed percentage stop loss to a volatility-based dynamic stop loss, such as using ATR (Average True Range) multiplied by a coefficient to set the stop loss distance.
  3. Implement True Multi-Target Profit-Taking: Modify the strategy code to implement partial position closing at different target levels, rather than closing the entire position at the first target level. This requires breaking each trade into multiple smaller positions.
  4. Add Trend Recognition Mechanism: Add trend recognition logic to only open positions when the trend direction is clear, avoiding frequent trading in oscillating markets.
  5. Optimize Capital Management: Dynamically adjust the percentage of funds used for each trade based on signal strength, market volatility, or drawdown situations, rather than using a fixed 10%.
  6. Add Time Filters: Avoid trading during high volatility periods at market open and close, or avoid important economic data release periods.
  7. Introduce Trailing Stops: Move the stop loss point to breakeven or a more favorable position after price moves a certain distance in the favorable direction, protecting existing profits.
  8. Add Counter-Trend Protection: In extreme market conditions, add contrary indicators as warning signals to avoid continuing to hold positions during severe market reversals.

Through these optimizations, the strategy’s robustness and profitability can be significantly improved, reducing the frequency of drawdowns and losing trades.

Conclusion

The Dual EMA Multi-Target Trading Strategy is a clearly structured, logically simple quantitative trading system based on classic EMA crossover signals, supplemented with multi-target profit management and stop loss settings. The strategy is suitable for medium to short-term trend trading and performs well in clearly trending markets.

Although relatively simple in design, the strategy contains the core elements of trading strategies: entry signals, exit conditions, stop loss management, and profit targets. The main advantages of the strategy lie in its clear operation, ease of understanding and execution, as well as good visualization support.

However, the strategy also has limitations such as reliance on a single indicator, lack of market environment recognition, and inflexible capital management. There is considerable room for optimization by adding trend filters, improving stop loss mechanisms, implementing true partial profit-taking, and enhancing capital management methods.

For traders, this strategy can serve as a basic framework that can be personalized and optimized according to individual risk preferences and trading instrument characteristics to achieve better trading results.

Strategy source code
/*backtest
start: 2024-08-21 00:00:00
end: 2025-08-20 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_OKX","currency":"BNB_USDT","balance":5000}]
*/

//@version=5
strategy("9/21 EMA with 10 Targets + Stoploss", 
     overlay = true,
     initial_capital = 100000,
     default_qty_type = strategy.percent_of_equity,
     default_qty_value = 10,
     pyramiding = 0)

// === Inputs ===
emaFastLen = input.int(9, "Fast EMA Length")
emaSlowLen = input.int(21, "Slow EMA Length")
slPercent  = input.float(0.5, "Stoploss %", step=0.1)

// 10 Targets
tp1Percent = input.float(0.5, "Target 1 %", step=0.1)
tp2Percent = input.float(1.0, "Target 2 %", step=0.1)
tp3Percent = input.float(1.5, "Target 3 %", step=0.1)
tp4Percent = input.float(2.0, "Target 4 %", step=0.1)
tp5Percent = input.float(2.5, "Target 5 %", step=0.1)
tp6Percent = input.float(3.0, "Target 6 %", step=0.1)
tp7Percent = input.float(3.5, "Target 7 %", step=0.1)
tp8Percent = input.float(4.0, "Target 8 %", step=0.1)
tp9Percent = input.float(4.5, "Target 9 %", step=0.1)
tp10Percent = input.float(5.0, "Target 10 %", step=0.1)

// === EMA Calculation ===
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)

// === Entry Conditions ===
longCond  = ta.crossover(emaFast, emaSlow)
shortCond = ta.crossunder(emaFast, emaSlow)

// === Entry ===
if (longCond and strategy.position_size <= 0)
    strategy.entry("BUY", strategy.long)

if (shortCond and strategy.position_size >= 0)
    strategy.entry("SELL", strategy.short)

// === Series Variables for Targets ===
var float tp1 = na
var float tp2 = na
var float tp3 = na
var float tp4 = na
var float tp5 = na
var float tp6 = na
var float tp7 = na
var float tp8 = na
var float tp9 = na
var float tp10 = na
var float stopLevel = na

// === Long Positions ===
if strategy.position_size > 0
    stopLevel := strategy.position_avg_price * (1 - slPercent/100)
    tp1 := strategy.position_avg_price * (1 + tp1Percent/100)
    tp2 := strategy.position_avg_price * (1 + tp2Percent/100)
    tp3 := strategy.position_avg_price * (1 + tp3Percent/100)
    tp4 := strategy.position_avg_price * (1 + tp4Percent/100)
    tp5 := strategy.position_avg_price * (1 + tp5Percent/100)
    tp6 := strategy.position_avg_price * (1 + tp6Percent/100)
    tp7 := strategy.position_avg_price * (1 + tp7Percent/100)
    tp8 := strategy.position_avg_price * (1 + tp8Percent/100)
    tp9 := strategy.position_avg_price * (1 + tp9Percent/100)
    tp10 := strategy.position_avg_price * (1 + tp10Percent/100)

    strategy.exit("Exit Long", "BUY", stop=stopLevel, limit=tp1)

// === Short Positions ===
if strategy.position_size < 0
    stopLevel := strategy.position_avg_price * (1 + slPercent/100)
    tp1 := strategy.position_avg_price * (1 - tp1Percent/100)
    tp2 := strategy.position_avg_price * (1 - tp2Percent/100)
    tp3 := strategy.position_avg_price * (1 - tp3Percent/100)
    tp4 := strategy.position_avg_price * (1 - tp4Percent/100)
    tp5 := strategy.position_avg_price * (1 - tp5Percent/100)
    tp6 := strategy.position_avg_price * (1 - tp6Percent/100)
    tp7 := strategy.position_avg_price * (1 - tp7Percent/100)
    tp8 := strategy.position_avg_price * (1 - tp8Percent/100)
    tp9 := strategy.position_avg_price * (1 - tp9Percent/100)
    tp10 := strategy.position_avg_price * (1 - tp10Percent/100)

    strategy.exit("Exit Short", "SELL", stop=stopLevel, limit=tp1)

// === Plotting ===
plot(emaFast, "EMA 9", color=color.yellow, linewidth=2)
plot(emaSlow, "EMA 21", color=color.orange, linewidth=2)

// Global plots (avoid local scope error)
plot(tp1,  "TP1",  color=color.new(color.green, 0))
plot(tp2,  "TP2",  color=color.new(color.green, 10))
plot(tp3,  "TP3",  color=color.new(color.green, 20))
plot(tp4,  "TP4",  color=color.new(color.green, 30))
plot(tp5,  "TP5",  color=color.new(color.green, 40))
plot(tp6,  "TP6",  color=color.new(color.green, 50))
plot(tp7,  "TP7",  color=color.new(color.green, 60))
plot(tp8,  "TP8",  color=color.new(color.green, 70))
plot(tp9,  "TP9",  color=color.new(color.green, 80))
plot(tp10, "TP10", color=color.new(color.green, 90))
plot(stopLevel, "Stoploss", color=color.red, linewidth=2)

// Entry Signals
plotshape(longCond, title="BUY Signal", style=shape.labelup, color=color.green, text="BUY")
plotshape(shortCond, title="SELL Signal", style=shape.labeldown, color=color.red, text="SELL")