本策略是一个结合了Granville趋势反转理论与MACD指标的多重信号确认交易系统。策略的核心思想是通过价格与均线的关系判断潜在的趋势反转,并使用MACD指标的多重信号验证来确保交易的可靠性。这种方法不仅能够有效地识别趋势的起点,还能通过多重确认机制来降低虚假信号的风险。
策略的执行流程分为四个关键步骤: 1. Granville反转信号确认:监测价格是否从EMA均线下方突破到上方,这表明可能出现趋势反转。 2. MACD首次金叉确认:在Granville反转信号出现后,等待MACD指标出现金叉,这是趋势转向的第二重确认。 3. MACD突破验证:确认MACD线突破首次金叉时的高点,这表明上升动能在持续增强。 4. MACD二次回踩:等待MACD在突破后回踩并再次上穿信号线,这是最终的入场信号。
止盈止损设置采用了基于反转K线波幅的动态调整方法,将止损设置在反转K线低点,止盈设置为反转K线波幅的1.618倍,这符合斐波那契扩展原理。
该策略通过结合经典的技术分析理论和现代量化交易方法,构建了一个相对完整的交易系统。多重信号确认机制提供了较好的交易可靠性,动态的风险管理方法也使策略具有良好的适应性。虽然存在一定的滞后性问题,但通过持续优化和参数调整,策略仍具有较好的实用价值和发展潜力。
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Granville + MACD Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ■ Parameter Settings
emaPeriod = input.int(20, "EMA Period for Granville", minval=1)
fastLen = input.int(12, "MACD Fast Period", minval=1)
slowLen = input.int(26, "MACD Slow Period", minval=1)
signalLen = input.int(9, "MACD Signal Period", minval=1)
// ■ Calculate EMA (for Granville reversal detection)
ema_val = ta.ema(close, emaPeriod)
// ■ Granville Reversal Detection (e.g., price crosses above EMA from below)
granvilleReversal = ta.crossover(close, ema_val)
// ■ Calculate MACD
[macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, signalLen)
// ■ State management variables (to manage state transitions)
var bool granvilleDone = false // Reversal bar confirmed flag
var float granvilleLow = na // Low of the reversal bar (used for SL)
var float granvilleRange = na // Range of the reversal bar (used for TP calculation)
var bool macdGC_done = false // First MACD Golden Cross confirmed
var int goldenCrossBar = na // Bar index of the first MACD Golden Cross
var float initialMacdHigh = na // MACD value at the Golden Cross (used for break detection)
var bool breakoutDone = false // MACD line breaks the initial Golden Cross MACD value
// ■ (1) Granville Reversal Detection
if granvilleReversal
granvilleDone := true
granvilleLow := low // Low of the reversal bar (SL)
granvilleRange := high - low // Range of the reversal bar (used for TP calculation)
// Reset MACD-related states
macdGC_done := false
breakoutDone := false
initialMacdHigh := na
goldenCrossBar := na
// ■ (2) MACD Golden Cross (first signal) detection
if granvilleDone and (not macdGC_done) and ta.crossover(macdLine, signalLine)
macdGC_done := true
goldenCrossBar := bar_index
initialMacdHigh:= macdLine
// ■ (3) Check if MACD line breaks the initial MACD value at the Golden Cross
if macdGC_done and (not breakoutDone) and (macdLine > initialMacdHigh)
breakoutDone := true
// ■ (4) When MACD retests and crosses above the signal line again, it's the entry timing
// ※ Check for a crossover after the first Golden Cross bar
entryCondition = granvilleDone and macdGC_done and breakoutDone and (bar_index > goldenCrossBar) and ta.crossover(macdLine, signalLine)
// ■ TP and SL settings at entry
if entryCondition
entryPrice = close
tpPrice = entryPrice + granvilleRange * 1.618
slPrice = granvilleLow
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry="Long", stop=slPrice, limit=tpPrice)
// Reset states after entry (for the next entry)
granvilleDone := false
macdGC_done := false
breakoutDone := false
initialMacdHigh := na
goldenCrossBar := na
// ■ Plotting (for reference)
// Display the EMA on the price chart (with fixed title)
plot(ema_val, color=color.orange, title="EMA (20)")
// Plot MACD and Signal in a separate window (with fixed titles)
plot(macdLine, color=color.blue, title="MACD")
plot(signalLine, color=color.red, title="Signal")