
The EMA Crossover Momentum Confirmation with Partial Stop-Loss Strategy is an advanced quantitative trading approach that combines exponential moving average (EMA) crossover signals, momentum confirmation, and market structure analysis. This strategy places special emphasis on trading safety through an innovative partial stop-loss mechanism to protect investment capital. Its core design philosophy is to wait for an EMA crossover to establish the initial trend direction, then look for the first “trend continuation” momentum signal as an entry point, while using market structure breakdown as a partial stop-loss trigger condition, effectively controlling risk while preserving upside potential.
The strategy operates based on a multi-layered confirmation mechanism:
Trend Identification: Uses the crossover of a fast EMA (8-period) and slow EMA (21-period) to determine the overall trend direction. When the 8 EMA crosses above the 21 EMA, an uptrend is identified; when the 8 EMA crosses below the 21 EMA, a downtrend is identified.
Entry Signal: The strategy doesn’t enter immediately at the initial EMA crossover but waits for the “first continuation” signal. This means:
Risk Management: The strategy introduces a partial stop-loss mechanism based on market structure analysis:
Exit Strategy: The final complete exit signal is a bearish EMA crossover, i.e., when the 8 EMA crosses below the 21 EMA, at which point all remaining positions are closed.
The strategy uses state management variables to track trading status, types of signals triggered, and market structure transition points, ensuring consistency and accuracy in logic execution.
A deep analysis of the strategy code reveals the following significant advantages:
Multiple Confirmation Mechanism: By combining EMA crossover, momentum threshold, and trend continuation signals, the strategy significantly reduces the risk of false breakouts and erroneous signals. This multi-layer filtering design greatly improves the quality and reliability of trades.
Intelligent Capital Management: The partial stop-loss mechanism (50% position reduction) is a highlight of this strategy, allowing traders to protect a portion of profits when market structure deteriorates while retaining the remaining position to capture potential trend recovery, achieving a balance between risk and reward.
Market Structure Adaptability: By dynamically tracking the formation of swing highs and lows, the strategy can identify changes in market structure, making it perform consistently across different market environments.
Flexible Parameterization: The strategy provides multiple adjustable parameters, including EMA lengths, sensitivity multiplier, and pivot lookback settings, allowing traders to optimize according to different market conditions and personal risk preferences.
Trend Respect Principle: The strategy design follows the “trend is your friend” principle, only going long in confirmed uptrends, avoiding the high risks associated with counter-trend trading.
Despite its sophisticated design, the strategy still has some potential risks and limitations:
Delayed Entry Risk: Due to waiting for the “first continuation” signal, the strategy may miss part of the early trend movement, potentially resulting in higher entry prices in rapid breakout scenarios.
Market Structure Misjudgment: In high-volatility environments, the formation of swing highs and lows may not be clear enough, leading to erroneous market structure judgments and unnecessary partial stop-losses.
Parameter Sensitivity: Strategy performance is highly dependent on parameters such as EMA length and ATR sensitivity multiplier. Inappropriate parameter settings may lead to overtrading or missing effective signals.
Lack of Re-entry After Stop-Loss: When partial stop-loss is triggered, the strategy doesn’t define a clear re-entry mechanism, potentially missing opportunities after trend recovery.
Based on code analysis, the strategy can be optimized in the following directions:
Dynamic Parameter Adjustment: Current EMA lengths and sensitivity multiplier are fixed; consider automatically adjusting these parameters based on market volatility. For example, use smaller sensitivity multipliers in low-volatility environments and larger values in high-volatility environments. This allows the strategy to better adapt to different market conditions.
Enhanced Quantitative Market Structure Scoring: The current market structure analysis is relatively simple. Develop a more complex market structure scoring system that considers the relative positions, formation speed, and magnitude of multiple swing highs and lows to more accurately judge trend strength and potential reversals.
Volume Confirmation Integration: The current strategy is based solely on price action. Add volume analysis as an additional confirmation factor. For example, require increased volume when triggering buy signals or amplified volume during market structure breakdown as a stronger warning signal.
Optimized Post-Partial-Stop-Loss Management: Introduce smarter capital management mechanisms, such as:
Multi-Timeframe Analysis: Improve strategy robustness by integrating longer-term trend analysis. For example, only allow long positions on smaller timeframes when the daily trend is up, thereby reducing the risk of trading against the major trend.
The EMA Crossover Momentum Confirmation with Partial Stop-Loss Strategy is an advanced quantitative trading system combining technical analysis and risk management. Its core strengths lie in its multi-layered confirmation mechanism and innovative partial stop-loss design, effectively controlling risk while capturing trends. By waiting for the “first continuation” signal to enter, the strategy greatly reduces the possibility of false breakout trades, while the market structure-based partial stop-loss provides a flexible capital protection mechanism.
This strategy is particularly suitable for markets with moderate volatility and clear trends, offering high reference value for quantitative traders looking to introduce more refined risk control in trend trading. Through further optimization of market structure analysis methods, dynamic parameter adjustment, and multi-timeframe integration, the strategy still has significant room for development and improvement.
Ultimately, successful application of this strategy requires traders to have a deep understanding of markets and the ability to appropriately adjust parameter settings according to different market environments, improving adaptability and robustness while maintaining the core strategy logic.
/*backtest
start: 2024-06-30 00:00:00
end: 2025-06-28 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":50000000}]
*/
//@version=5
// This strategy buys on the 'First Continuation' signal and adds a
// partial stop-loss that triggers on a lower-low and lower-high market structure break.
// This version corrects the 'strategy.close' argument error.
strategy("First Continuation Strategy w/ Partial SL (Corrected)",
overlay=true,
default_qty_type=strategy.percent_of_equity,
default_qty_value=10,
commission_type=strategy.commission.percent,
commission_value=0.1)
// --- INPUTS ---
emaLength = input.int(21, "Slow EMA Length")
shortEmaLength = input.int(8, "Fast EMA Length")
sensitivityMultiplier = input.float(1.5, title="Sensitivity Multiplier")
pivotLeft = input.int(5, title="Pivot Lookback Left")
pivotRight = input.int(5, title="Pivot Lookback Right")
// --- CALCULATIONS ---
ema21 = ta.ema(close, emaLength)
ema8 = ta.ema(close, shortEmaLength)
atr = ta.atr(14)
distance = close - ema21
threshold = atr * sensitivityMultiplier
// --- STATE MANAGEMENT ---
var bool inEmaUptrend = false, var bool inEmaDowntrend = false
var bool firstBuySignalFired = false, var bool firstSellSignalFired = false
var bool firstContinuationBuyFired = false, var bool firstContinuationSellFired = false
// State management for the new stop-loss logic
var float lastHigh = na, var float secondLastHigh = na
var float lastLow = na, var float secondLastLow = na
var bool partialStopTriggered = false
bool bullishCross = ta.crossover(ema8, ema21)
bool bearishCross = ta.crossunder(ema8, ema21)
// Reset state on trend changes
if (bullishCross)
inEmaUptrend := true, inEmaDowntrend := false
firstBuySignalFired := false, firstContinuationBuyFired := false
if (bearishCross)
inEmaUptrend := false, inEmaDowntrend := true
firstSellSignalFired := false, firstContinuationSellFired := false
// --- PIVOT & TRIGGER LOGIC ---
// Detect new swing points
float newPivotHigh = ta.pivothigh(high, pivotLeft, pivotRight)
float newPivotLow = ta.pivotlow(low, pivotLeft, pivotRight)
// If in a trade, track the last two swing points
if (strategy.position_size > 0)
if not na(newPivotHigh)
secondLastHigh := lastHigh
lastHigh := newPivotHigh
if not na(newPivotLow)
secondLastLow := lastLow
lastLow := newPivotLow
// Stop-Loss Condition: A confirmed lower high AND lower low have formed
bool marketStructureBreak = not na(lastHigh) and not na(secondLastHigh) and not na(lastLow) and not na(secondLastLow) and lastHigh < secondLastHigh and lastLow < secondLastLow
// Reset pivot history and stop-loss flag when position is closed
if (strategy.position_size == 0 and strategy.position_size[1] != 0)
lastHigh := na, secondLastHigh := na
lastLow := na, secondLastLow := na
partialStopTriggered := false
// Standard V8 Trigger Logic
bool isMomentumBar = math.abs(distance) >= (threshold / 1.5)
bool isPositiveMomentumBar = isMomentumBar and distance > 0
bool buySignal = inEmaUptrend and isPositiveMomentumBar
bool buyTrigger = buySignal and not buySignal[1]
bool initialBuyTrigger = buyTrigger and not firstBuySignalFired
bool firstContinuationBuy = buyTrigger and firstBuySignalFired and not firstContinuationBuyFired
if (initialBuyTrigger)
firstBuySignalFired := true
if (firstContinuationBuy)
firstContinuationBuyFired := true
// --- STRATEGY EXECUTION ---
// ENTRY: Buy only on the first continuation 'b' signal and when flat.
if (firstContinuationBuy and strategy.position_size == 0)
strategy.entry("Long", strategy.long)
// PARTIAL EXIT (NEW): Close 50% of the position if market structure breaks down.
if (strategy.position_size > 0 and marketStructureBreak and not partialStopTriggered)
qtyToClose = strategy.position_size * 0.5
strategy.close(id="Long", qty=qtyToClose, comment="SL 50% on Structure Break") // CORRECTED ARGUMENT
partialStopTriggered := true // Ensure this only triggers once per trade
// FULL EXIT: Close any remaining position on a bearish cross.
if (strategy.position_size > 0 and bearishCross)
strategy.close("Long", comment="Exit on Bearish Cross")
// --- PLOTTING ---
plot(ema8, "Fast EMA", color=color.new(color.blue, 0), linewidth=2)
plot(ema21, "Slow EMA", color=color.new(color.orange, 0), linewidth=2)
// Plot pivots to visualize the market structure
plot(newPivotHigh, "Pivot High", color=color.new(color.red, 50), style=plot.style_circles, offset=-pivotRight)
plot(newPivotLow, "Pivot Low", color=color.new(color.green, 50), style=plot.style_circles, offset=-pivotRight)