
이 전략은 MACD 지표와 이동 평균을 기반으로 한 다시간대 거래 시스템이다. 1분과 3분 두 개의 시간 주기 MACD 지표를 결합하고, 200주기 EMA를 트렌드 필터로 사용하여 시장 추세의 지속성을 포착하여 거래한다. 이 전략에는 손해 중지 설정 및 기본 지점으로 이동하는 동적 조정 기능 등 위험 관리 장치가 포함되어 있다.
전략의 핵심 논리는 다음과 같은 핵심 요소에 기초합니다.
구체적인 거래 신호 생성 규칙은 다음과 같습니다:
위험 관리 제안:
이 전략은 다중 시간 주기의 MACD 지표와 EMA 트렌드 필터를 결합하여 비교적 완벽한 거래 시스템을 구축한다. 그것의 장점은 다중 확인 메커니즘과 위험 관리의 무결성이지만, 동시에 다양한 시장 환경에서 적응성에 대한 문제를 주의해야 한다. 제안된 최적화 방향을 통해, 전략은 안정성을 유지하면서 수익 능력을 더욱 향상시킬 것으로 보인다.
/*backtest
start: 2025-02-13 00:00:00
end: 2025-02-15 02:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("NQ MACD Continuation Backtest", overlay=true)
// MACD Settings
fastLength = 12
slowLength = 26
signalLength = 9
// 1-minute MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalLength)
// 3-minute MACD for trend filter
[htfMacd, htfSignal, _] = request.security(syminfo.tickerid, "3", ta.macd(close, fastLength, slowLength, signalLength), lookahead=barmerge.lookahead_on)
// 200 EMA
ema200 = ta.ema(close, 200)
// Time Filters
inSession = (hour(time, "America/New_York") >= 9 and (hour(time, "America/New_York") > 9 or minute(time, "America/New_York") >= 45)) and (hour(time, "America/New_York") < 22 or (hour(time, "America/New_York") == 22 and minute(time, "America/New_York") == 30))
notRestricted = (hour(time, "America/New_York") >= 6 and hour(time, "America/New_York") < 22)
// Track Previous MACD Crosses
var bool bullishCrossed = false
var bool bearishCrossed = false
if (ta.crossover(macdLine, signalLine) and macdLine > 0)
bullishCrossed := true
if (ta.crossunder(macdLine, signalLine) and macdLine < 0)
bearishCrossed := true
// Define Continuation Signals with EMA and 3-Min MACD Filter
bullishContinuation = (ta.crossover(macdLine, signalLine) and macdLine > 0 and signalLine > 0 and htfMacd > htfSignal and bullishCrossed and close > ema200)
bearishContinuation = (ta.crossunder(macdLine, signalLine) and macdLine < 0 and signalLine < 0 and htfMacd < htfSignal and bearishCrossed and close < ema200)
// Entry Conditions with SL and 10 Contracts
if (bullishContinuation and inSession and notRestricted)
strategy.entry("Long", strategy.long, qty=10, stop=close - 7 * syminfo.mintick)
if (bearishContinuation and inSession and notRestricted)
strategy.entry("Short", strategy.short, qty=10, stop=close + 7 * syminfo.mintick)
// Break-Even Adjustment
if (strategy.position_size > 0 and close >= strategy.position_avg_price + 5 * syminfo.mintick)
strategy.exit("BreakEvenLong", from_entry="Long", stop=strategy.position_avg_price)
if (strategy.position_size < 0 and close <= strategy.position_avg_price - 5 * syminfo.mintick)
strategy.exit("BreakEvenShort", from_entry="Short", stop=strategy.position_avg_price)
// Display Indicators on Chart
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
plot(ema200, color=color.red, title="200 EMA")