
The Adaptive EMA Momentum Crossover Strategy with Dynamic Stop-Loss is a trend-following approach that combines Exponential Moving Average (EMA) and Bollinger Bands (BB). This strategy focuses on upward market trends, determining entry points and stop-loss levels through the relationship between price and EMA, along with dynamic support levels provided by Bollinger Bands. Key features include a fixed risk-reward ratio, dynamic stop-loss adjustment when price shows strength, and a mechanism to prevent immediate re-entry after taking profits, thereby enhancing strategy stability and profitability.
The core principles of this strategy are based on several key components:
Trend Confirmation: Uses a 40-period EMA as a trend indicator. When price is above the EMA, it’s considered to be in an uptrend.
Entry Conditions: Only enters a long position when all three conditions are met:
Dynamic Stop-Loss Setting:
Risk Management:
Re-entry Restriction Mechanism:
Based on code analysis, this strategy has several distinct advantages:
Trend-Following Benefit: Confirms trend direction with EMA and only goes long in uptrends, avoiding counter-trend trading.
Dynamic Risk Management: Compared to fixed stop-losses, using Bollinger Bands as the initial stop-loss automatically adjusts the stop-loss distance based on market volatility, providing more flexibility to adapt to market changes.
Profit Protection Mechanism: When price performs strongly and breaks above the upper Bollinger Band, the stop-loss is raised to the EMA position. This dynamic stop-loss effectively locks in existing profits and prevents excessive drawdowns.
Optimized Re-entry Logic: The strategy controls re-entry through the waitForNewCross variable, preventing immediate re-entry after taking profit. It requires price to cross below the EMA and then cross above it again, which helps avoid frequent trading in oscillating markets.
Fixed Risk-Reward Ratio: The 3:1 risk-reward ratio ensures that the profit-loss ratio of each trade remains within a controllable range, conducive to long-term stable profits.
Position Management: The strategy uses a percentage of equity (10%) for position management rather than fixed lot sizes, which is more beneficial for smooth growth of the equity curve.
Despite its many advantages, the strategy still has the following risk factors:
False Breakout Risk: When price briefly breaks above the EMA and then quickly falls back, it may lead to unnecessary entries and trigger stop-losses. To reduce this risk, consider adding confirmation conditions, such as requiring price to remain above the EMA for multiple consecutive periods.
Poor Performance in Oscillating Markets: In oscillating markets without clear trends, frequent price crossings of the EMA may lead to multiple stop-losses. Consider adding trend strength filtering conditions, such as using the ADX indicator to confirm trend strength.
Excessive Stop-Loss Distance Risk: In highly volatile markets, Bollinger Band width may be too large, resulting in distant stop-losses and increasing the loss amount per trade. Consider setting a maximum stop-loss percentage limit.
Over-reliance on Single Indicators: The strategy mainly relies on EMA and Bollinger Bands, which may cause the strategy to perform poorly in certain specific market environments. It’s recommended to add other independent indicators for cross-validation.
Fixed Parameter Risk: Fixed EMA period (40) and Bollinger Band standard deviation (0.7) may not be suitable for all market environments. Consider introducing adaptive parameters or setting different parameters for different market environments.
Based on in-depth analysis of the strategy, here are several possible optimization directions:
Add Trend Strength Filtering:
Optimize Entry Conditions:
Adaptive Parameter Settings:
Partial Take-Profit Mechanism:
Time-Based Exit Mechanism:
Market Environment Adaptation:
The Adaptive EMA Momentum Crossover Strategy with Dynamic Stop-Loss is a well-designed trend-following system that combines EMA and Bollinger Bands to implement dynamic entry, stop-loss, and take-profit management. Its core advantage lies in the ability to automatically adjust stop-loss positions according to market conditions and avoid frequent trading in oscillating markets through the re-entry restriction mechanism.
The strategy’s risks are mainly concentrated in fixed parameters and reliance on single indicators, which can be improved by adding trend strength filtering, optimizing entry conditions, introducing adaptive parameter settings, and adding partial take-profit mechanisms. Particularly, adding market environment determination logic allows the strategy to flexibly switch parameters in different market types, improving overall stability and profitability.
Overall, this is a strategy framework with practical application value. Through appropriate parameter optimization and risk management enhancement, it can become a stable and reliable trading system. It is particularly suitable for traders seeking to track medium to long-term trends while effectively controlling risk.
/*backtest
start: 2024-08-12 00:00:00
end: 2025-08-10 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Buy-Only: 40 EMA + BB(0.7) [with TP reset]", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === INPUTS ===
emaLength = input.int(40, title="EMA Length")
bbStdDev = input.float(0.7, title="Bollinger Bands StdDev")
rr_ratio = input.float(3.0, title="Reward-to-Risk Ratio") // 3:1 RR
// === INDICATORS ===
ema = ta.ema(close, emaLength)
dev = bbStdDev * ta.stdev(close, emaLength)
upperBB = ema + dev
lowerBB = ema - dev
plot(ema, color=color.orange, title="EMA 40")
plot(upperBB, color=color.teal, title="Upper BB")
plot(lowerBB, color=color.teal, title="Lower BB")
// === STATE VARIABLES ===
var float longSL = na
var float longTP = na
var bool waitForNewCross = false // <- Block re-entry after TP until reset
// === BUY ENTRY CONDITION ===
buyCondition = close > ema and not waitForNewCross and strategy.position_size == 0
if buyCondition
strategy.entry("Buy", strategy.long)
longSL := lowerBB
longTP := close + (close - lowerBB) * rr_ratio
// === SL SHIFT TO EMA IF PRICE CLOSES ABOVE UPPER BB ===
if (strategy.position_size > 0 and close > upperBB)
longSL := ema
// === EXIT LOGIC ===
if (strategy.position_size > 0)
if close < longSL
strategy.close("Buy", comment="SL Hit")
if close >= longTP
strategy.close("Buy", comment="TP Hit")
waitForNewCross := true // Block next trade
// === RESET ENTRY CONDITION ===
// Wait for crossover below EMA then new close above it
if waitForNewCross and ta.crossunder(close, ema)
waitForNewCross := false