
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.
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.
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.
Through these optimizations, the strategy’s robustness and profitability can be significantly improved, reducing the frequency of drawdowns and losing trades.
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.
/*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")