
The Dual MACD Divergence with SMA Trend Resonance Strategy is a technically-oriented quantitative trading system that combines divergence signals from both fast and slow MACD indicators with a proximity filter to the 28-period Simple Moving Average (SMA28) to capture potential trend reversal points. The strategy achieves higher reliability by requiring divergence signals to appear simultaneously on two MACD timeframes, coupled with the condition that price must be near the SMA28. Designed to automatically identify both long and short trading opportunities, the strategy manages exits through a preset risk-reward ratio and is particularly suited for 15-minute timeframe trading.
The core principle of this strategy is based on the synchronous confirmation of multiple technical indicators, specifically:
Dual MACD Divergence Signal Detection:
SMA28 Proximity Filter:
Resonance Confirmation Logic:
Risk Management Mechanism:
Deep analysis of the strategy code reveals the following significant advantages:
Multiple Confirmation Mechanism: Requiring divergence signals to appear simultaneously on two differently parameterized MACDs greatly reduces the probability of false signals, improving trade quality.
Zone Filtering Design: By requiring price to be near the SMA28, the strategy ensures trades occur at technically significant locations, avoiding trades in irrelevant areas.
Automatic Bidirectional Trading: The strategy can automatically identify and execute trades in both directions, adapting to different market environments and capturing opportunities in all directions.
Preset Risk Management: Built-in fixed risk-reward ratio (1:1.5) automatically sets take-profit and stop-loss levels for each trade, ensuring consistent and standardized fund management.
Visualization of Trading Signals: Using plotshape and plot functions to intuitively display trading signals, take-profit, and stop-loss levels on the chart, making it easier for traders to monitor and understand strategy execution.
Alert Function Integration: Built-in alert condition settings facilitate integration with trading bots, enabling fully automated trade execution and reducing human intervention and emotional influence.
Parameter Optimization Capability: Various parameters of the strategy (such as MACD periods, SMA period, proximity threshold, risk-reward ratio, etc.) can be adjusted and optimized according to specific market conditions.
Despite its well-designed nature, the strategy still faces the following potential risks and challenges:
Overtrading Risk: In highly volatile but directionless markets, dual MACD divergence signals may appear frequently, leading to overtrading and fee erosion. The solution is to add additional filtering conditions, such as trend strength indicators or trading frequency limits.
Fixed Stop-Loss Risk: Using a fixed percentage stop-loss may not adequately protect capital during periods of high volatility. Consider using volatility-based dynamic stop-losses (such as ATR multiples) to make stop-loss levels more aligned with the current market environment.
False Divergence Signals: MACD divergence sometimes produces false signals, especially in strong trending markets. It is recommended to add confirmation indicators, such as RSI or volume indicators, to further validate signal validity.
Parameter Dependency: Strategy performance is highly dependent on the chosen parameter settings and may require frequent adjustments to adapt to different market environments. The solution is to conduct comprehensive parameter optimization tests to find more robust parameter combinations.
SMA Proximity Limitation: In rapidly breaking or sharply falling environments, price may quickly deviate from SMA28, causing the strategy to miss important trading opportunities. Consider adding trend recognition logic to relax proximity requirements when trend changes are confirmed.
Consecutive Loss Risk: Under certain market conditions, the strategy may produce a series of consecutive losing trades. Overall risk control mechanisms should be implemented, such as daily maximum loss limits or percentage-based risk control.
Based on in-depth analysis of the code, the following are feasible optimization directions:
Dynamic Risk Management Improvements:
Signal Quality Enhancement:
Trade Timing Optimization:
Multi-Timeframe Analysis:
Machine Learning Enhancement:
Backtesting and Validation Improvements:
The Dual MACD Divergence with SMA Trend Resonance Strategy is an elegantly designed quantitative trading system that provides a structured approach to finding potential trend reversal points by integrating confirmation from multiple technical indicators. The core strengths of the strategy lie in its multiple confirmation mechanism and built-in risk management system, making it particularly suitable for 15-minute timeframe trading. While there are potential risks such as overtrading and parameter dependency, these can be effectively mitigated through the proposed optimization directions.
By further optimizing signal quality, risk management, and timing selection, the strategy has the potential to become an even more robust and adaptive trading system. Particularly, introducing dynamic risk management mechanisms and multi-timeframe analysis could significantly enhance the overall performance of the strategy. For quantitative traders seeking technically-driven automated trading solutions, this provides a solid foundational framework that can be customized and extended according to individual risk preferences and market conditions.
/*backtest
start: 2024-04-26 00:00:00
end: 2025-04-25 08:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("BTC 雙MACD 背離策略(基礎共振 / 適用15分鐘 / 多空自動)", overlay=true, default_qty_type=strategy.fixed, default_qty_value=100)
// === 均線(SMA28) ===
sma28 = ta.sma(close, 28)
sma_touch = math.abs(close - sma28) / sma28 < 0.015
// === MACD 計算(慢速) ===
[macdSlow, signalSlow, _] = ta.macd(close, 14, 28, 9)
histSlow = macdSlow - signalSlow
bullish_div_slow = ta.lowest(low, 5) < ta.lowest(low[10], 5) and histSlow > histSlow[1]
bearish_div_slow = ta.highest(high, 5) > ta.highest(high[10], 5) and histSlow < histSlow[1]
// === MACD 計算(快速) ===
[macdFast, signalFast, _] = ta.macd(close, 10, 21, 7)
histFast = macdFast - signalFast
bullish_div_fast = ta.lowest(low, 5) < ta.lowest(low[10], 5) and histFast > histFast[1]
bearish_div_fast = ta.highest(high, 5) > ta.highest(high[10], 5) and histFast < histFast[1]
// === 基礎共振條件 ===
superLong = bullish_div_slow and bullish_div_fast and sma_touch
superShort = bearish_div_slow and bearish_div_fast and sma_touch
longEntry = superLong
shortEntry = superShort
// === 可調式風報比(改為 1:1.5) ===
risk = 0.01
reward = 0.015
long_tp = close * (1 + reward)
long_sl = close * (1 - risk)
short_tp = close * (1 - reward)
short_sl = close * (1 + risk)
if longEntry
strategy.entry("做多進場", strategy.long)
strategy.exit("做多出場", from_entry="做多進場", limit=long_tp, stop=long_sl)
if shortEntry
strategy.entry("做空進場", strategy.short)
strategy.exit("做空出場", from_entry="做空進場", limit=short_tp, stop=short_sl)
plotshape(superLong, title="共振多", location=location.belowbar, color=color.green, style=shape.labelup, size=size.tiny)
plotshape(superShort, title="共振空", location=location.abovebar, color=color.red, style=shape.labeldown, size=size.tiny)
plot(longEntry ? long_tp : na, title="多TP", color=color.green, linewidth=1)
plot(longEntry ? long_sl : na, title="多SL", color=color.red, linewidth=1)
plot(shortEntry ? short_tp : na, title="空TP", color=color.green, linewidth=1)
plot(shortEntry ? short_sl : na, title="空SL", color=color.red, linewidth=1)
// === Alert 設定 ===
alertcondition(longEntry, title="多單共振進場", message="LONG_ENTRY")
alertcondition(shortEntry, title="空單共振進場", message="SHORT_ENTRY")