
이 전략은 그랜빌 트렌드 반전 이론과 MACD 지표의 여러 신호를 결합한 거래 확인 시스템이다. 전략의 핵심 아이디어는 가격과 평균선의 관계를 통해 잠재적인 트렌드 반전을 판단하고 MACD 지표의 여러 신호 검증을 사용하여 거래의 신뢰성을 보장하는 것이다. 이 방법은 트렌드의 시작점을 효과적으로 식별할 수 있을 뿐만 아니라 여러 확인 메커니즘을 통해 가짜 신호의 위험을 줄일 수 있다.
이 전략의 실행 과정은 4가지 핵심 단계로 구성되어 있습니다.
정지 손실 설정은 역전 K선 진폭에 기반한 동적 조정 방법을 사용하여, 정지 손실을 역전 K선 진폭의 1.618배로 역전 K선 진폭에 설정합니다. 이것은 피보나치 확장 원칙에 부합합니다.
이 전략은 고전적인 기술 분석 이론과 현대적인 양적 거래 방법을 결합하여 비교적 완전한 거래 시스템을 구축한다. 다중 신호 확인 메커니즘은 거래 신뢰성을 제공하며, 동적 위험 관리 방법은 전략에 대한 좋은 적응력을 제공합니다. 약간의 뒤떨어진 문제가 있지만, 지속적인 최적화 및 매개 변수 조정으로 전략은 여전히 좋은 실용적 가치와 발전 잠재력을 가지고 있다.
/*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")