EMA Divergence Mean Reversion Strategy

EMA 均值回归 背离 底部买入 价格波动
Created on: 2025-03-26 15:34:19 Modified on: 2025-03-26 15:34:19
Copy: 1 Number of hits: 411
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 EMA Divergence Mean Reversion Strategy  EMA Divergence Mean Reversion Strategy

Overview

This is a mean reversion trading strategy that capitalizes on significant deviations between price and the 50-period Exponential Moving Average (EMA). Specifically designed for volatile markets, the strategy aims to profit by buying when prices fall substantially below the EMA and selling when they recover above it. The strategy primarily tracks the percentage difference between price and EMA, triggering trading signals when this difference exceeds specific thresholds.

Strategy Principle

The core logic is based on the mean reversion theory, which suggests that while prices may deviate from their mean in the short term, they tend to revert to it over time. The strategy uses a 50-period EMA as a reference point for the mean price. When the price falls significantly below this average (over 10%), it’s considered a buying opportunity. When the price recovers above the EMA and shows a profit, it triggers a sell signal. The calculation is as follows: 1. Uses a 50-period EMA as the baseline 2. Calculates the percentage deviation of price from EMA: diff_perct = ((ema20 - close) / ema20) * 100 3. Calculates the percentage deviation of high price from EMA: diff_perct2 = ((high - ema20) / ema20) * 100 4. When diff_perct > 10 (i.e., price is more than 10% below EMA), a buy signal is triggered 5. When diff_perct2 > 0 (i.e., high price is above EMA) and the current trade is profitable (profit > 1), a sell signal is triggered

Strategy Advantages

  1. Clear Entry Conditions: The strategy sets a specific price deviation threshold (10%), providing clear entry signals and reducing subjective judgment interference.
  2. Capitalizes on Market Overreactions: The strategy aims to capture opportunities during excessive market panic or downturns when asset prices are often undervalued.
  3. Automated Execution: The strategy can be fully automated, eliminating the need for constant monitoring and reducing emotional interference.
  4. Flexible Capital Management: The strategy uses cash allocation rather than fixed units, allowing for more flexible capital utilization.
  5. Simplicity: Compared to complex multi-indicator strategies, this strategy is straightforward, easy to understand, and adjust.
  6. Risk Control: The sell signal is only triggered when there is already a profit, helping to protect realized gains.

Strategy Risks

  1. Trend Risk: In strong downtrend markets, prices may continuously deviate from the EMA without reverting, leading to the “catching falling knives” phenomenon and sustained losses.
  2. Parameter Sensitivity: The 10% deviation threshold may not be suitable for all market conditions, potentially failing to trigger in low-volatility environments or triggering too frequently in high-volatility ones.
  3. Lack of Stop-Loss Mechanism: The code doesn’t include explicit stop-loss settings, which could lead to significant losses if the market deteriorates continuously.
  4. Dependence on EMA Accuracy: The strategy assumes the EMA is an effective reference for price, which may not hold true under certain market conditions.
  5. Liquidity Risk: In less liquid markets, buy or sell orders may face slippage or incomplete execution.
  6. Fixed Profit Threshold: The profit threshold is set at a fixed value of 1, without considering adaptive adjustments based on different market volatilities.

Optimization Directions

  1. Dynamic Deviation Threshold: Replace the fixed 10% deviation threshold with a dynamic one based on recent volatility, perhaps using the Average True Range (ATR) indicator.
  2. Add Stop-Loss Mechanism: Introduce time-based or price-based stop-loss conditions, such as maximum holding time or maximum allowable loss percentage.
  3. Multi-Timeframe Confirmation: Incorporate trend judgments from longer timeframes (such as daily or weekly) to avoid entering positions against the primary trend.
  4. Staged Position Building and Closing: Implement graduated buying and staged selling instead of establishing or closing all positions at once to distribute risk.
  5. Additional Filtering Conditions: Add extra technical indicators (such as RSI or MACD) as filtering conditions to improve signal quality.
  6. Adaptive EMA Period: Experiment with an adaptive EMA period instead of a fixed 50-period to better adjust to changing market conditions.
  7. Backtesting Optimization: Conduct extensive backtesting under different market cycles and conditions to find optimal parameter combinations.

Summary

The 50-Period EMA Divergence Mean Reversion Strategy is an automated trading system based on technical analysis that seeks trading opportunities by capturing significant deviations between price and moving averages. The strategy is simple and intuitive, suitable for markets with higher volatility, but also carries certain risks, especially in strong trending markets. By adding stop-loss mechanisms, dynamic parameter adjustments, and multi-indicator confirmations, the strategy’s robustness and profitability can be significantly enhanced. Ideally, this strategy would serve as part of a more comprehensive trading system rather than being used in isolation.

Strategy source code
/*backtest
start: 2024-03-26 00:00:00
end: 2025-03-25 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("SUIBTC 2H - EMA dip public",overlay=true,initial_capital=100,default_qty_value=100, default_qty_type = strategy.cash,process_orders_on_close=false,calc_on_every_tick=false)


BuyTrigger = input.bool(false)
SellTrigger = input.bool(false)

src = input(open, title="Source")
offset = input.int(title="Offset", defval=5, minval=-500, maxval=500)

ema20 = ta.ema(close, 50)
plot(ema20, title="ema20", color=color.yellow, linewidth=3)




diff_perct = ((ema20 - close) / ema20) * 100
diff_perct2 = ((high -  ema20) / ema20) * 100





if ( diff_perct > 10)   
    BuyTrigger := true 

if(  diff_perct2 > 0 and strategy.openprofit > 1)
    SellTrigger := true 
    

    

notInTrade = strategy.position_size <= 0
inTrade = strategy.position_size > 0


timeSinceLastTrade_ms = time - strategy.opentrades.entry_time(0)


if (BuyTrigger and notInTrade )
    strategy.order("long", strategy.long , oca_name = 'audusdt' , when = BuyTrigger ,limit = open, comment = "buy: SUIBTC EMA Dip")
 
if (SellTrigger and inTrade )
    strategy.close(id="long" , qty_percent = 100,  comment = "sell: SUIBTC EMA Dip")