该策略是一个基于MACD柱状图动量背离的趋势反转交易系统。它通过分析K线形态变化与MACD柱状图的动量变化之间的关系来捕捉市场反转信号。策略的核心思想是在市场出现动量衰减迹象时进行反向交易,从而在趋势即将反转时提前布局。
策略的交易逻辑分为做空和做多两个方向: 做空条件:当出现较大的阳线(收盘价高于开盘价),且其实体大于前一根K线,同时MACD柱状图连续3个周期呈现下降趋势时,表明上涨动能在减弱,系统发出做空信号。 做多条件:当出现较大的阴线(收盘价低于开盘价),且其实体大于前一根K线,同时MACD柱状图连续3个周期呈现上升趋势时,表明下跌动能在减弱,系统发出做多信号。 持仓管理采用对手信号平仓机制,即当出现相反方向的交易信号时,平掉当前持仓。策略不设置止损和止盈,完全依靠信号来管理仓位。
该策略通过结合K线形态和MACD柱状图动量变化来捕捉市场反转机会,具有操作简单、信号明确的特点。虽然存在一定的风险,但通过合理的优化和风险管理措施,可以显著提升策略的稳定性和盈利能力。策略特别适合趋势明显的市场环境,可以作为交易系统的重要组成部分。
/*backtest
start: 2024-11-10 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("MACD Momentum Reversal Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === MACD Calculation ===
fastLength = input.int(12, "MACD Fast Length")
slowLength = input.int(26, "MACD Slow Length")
signalLength = input.int(9, "MACD Signal Length")
[macdLine, signalLine, histLine] = ta.macd(close, fastLength, slowLength, signalLength)
// === Candle Properties ===
bodySize = math.abs(close - open)
prevBodySize = math.abs(close[1] - open[1])
candleBigger = bodySize > prevBodySize
bullishCandle = close > open
bearishCandle = close < open
// === MACD Momentum Conditions ===
// For bullish candles: if the MACD histogram (normally positive) is decreasing over the last 3 bars,
// then the bullish momentum is fading – a potential short signal.
macdLossBullish = (histLine[2] > histLine[1]) and (histLine[1] > histLine[0])
// For bearish candles: if the MACD histogram (normally negative) is increasing (moving closer to zero)
// over the last 3 bars, then the bearish momentum is fading – a potential long signal.
macdLossBearish = (histLine[2] < histLine[1]) and (histLine[1] < histLine[0])
// === Entry Conditions ===
// Short entry: Occurs when the current candle is bullish and larger than the previous candle,
// while the MACD histogram shows fading bullish momentum.
enterShort = bullishCandle and candleBigger and macdLossBullish
// Long entry: Occurs when the current candle is bearish and larger than the previous candle,
// while the MACD histogram shows fading bearish momentum.
enterLong = bearishCandle and candleBigger and macdLossBearish
// === Plot the MACD Histogram for Reference ===
plot(histLine, title="MACD Histogram", color=color.blue, style=plot.style_histogram)
// === Strategy Execution ===
// Enter positions based on conditions. There is no stop loss or take profit defined;
// positions remain open until an opposite signal occurs.
if (enterShort)
strategy.entry("Short", strategy.short)
if (enterLong)
strategy.entry("Long", strategy.long)
// Exit conditions: close an existing position when the opposite signal appears.
if (strategy.position_size > 0 and enterShort)
strategy.close("Long")
if (strategy.position_size < 0 and enterLong)
strategy.close("Short")