
이 전략은 지수 이동 평균 (EMA) 과 이동 평균 동향/방향 (MACD) 지표를 결합한 정량화 거래 시스템입니다. 단기 및 장기 EMA의 교차 신호를 통합하고 MACD 동력을 확인함으로써 거래자에게 포괄적인 트렌드 추적 솔루션을 제공합니다. 이 전략에는 동적 스톱 및 스톱 메커니즘이 포함되어 있으며 위험을 효과적으로 제어하면서 수익을 극대화합니다.
전략의 핵심 논리는 두 가지 기술 지표의 상호 작용에 기반한다. 첫째, 12주기 및 26주기 EMA를 사용하여 시장의 트렌드를 식별하고, 단기 EMA 상에서 장기 EMA를 통과하면 다중 신호가 발생하고, 하단 EMA를 통과하면 마이너스 신호가 발생한다. 둘째, MACD 지표 ((12,26,9 설정) 를 사용하여 트렌드 동력을 확인하고, MACD 라인과 라인의 위치 관계가 EMA에서 생성된 거래 신호를 지원하도록 요구한다.
이것은 합리적이고 논리적으로 명확한 트렌드 추적 전략을 설계했다. 전략이 간단하고 이해하기 쉽게 유지되는 동시에 EMA와 MACD의 장점을 결합하여 신뢰할 수있는 거래 신호 생성 장치를 달성했다. 전략의 사용자 정의가 강하고 위험 관리 장치가 개선되어 중장기 트렌드 거래의 기본 프레임 워크로 적합하다. 거래자가 실장에 사용하기 전에 매개 변수 설정을 충분히 테스트하고 특정 거래 품종과 시장 환경에 따라 타겟팅 최적화를 수행하는 것이 좋습니다.
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-03 15:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("EMA + MACD Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === Inputs ===
shortEmaLength = input.int(12, title="Short EMA Period", minval=1)
longEmaLength = input.int(26, title="Long EMA Period", minval=1)
macdFastLength = input.int(12, title="MACD Fast EMA Period", minval=1)
macdSlowLength = input.int(26, title="MACD Slow EMA Period", minval=1)
macdSignalLength = input.int(9, title="MACD Signal Period", minval=1)
stopLossPerc = input.float(2.0, title="Stop-Loss (%)", minval=0.1, step=0.1)
takeProfitPerc = input.float(5.0, title="Take-Profit (%)", minval=0.1, step=0.1)
// === Indicator Calculations ===
// Exponential Moving Averages (EMA)
shortEMA = ta.ema(close, shortEmaLength)
longEMA = ta.ema(close, longEmaLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
// === Entry Conditions ===
// Buy signal: Short EMA crosses above Long EMA and MACD > Signal Line
longCondition = ta.crossover(shortEMA, longEMA) and (macdLine > signalLine)
// Sell signal: Short EMA crosses below Long EMA and MACD < Signal Line
shortCondition = ta.crossunder(shortEMA, longEMA) and (macdLine < signalLine)
// === Entry Signals with Stop-Loss and Take-Profit ===
if (longCondition)
strategy.entry("Long", strategy.long)
// Calculate Stop-Loss and Take-Profit
stopPrice = close * (1 - stopLossPerc / 100)
takePrice = close * (1 + takeProfitPerc / 100)
strategy.exit("Long Exit", from_entry="Long", stop=stopPrice, limit=takePrice)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Calculate Stop-Loss and Take-Profit
stopPrice = close * (1 + stopLossPerc / 100)
takePrice = close * (1 - takeProfitPerc / 100)
strategy.exit("Short Exit", from_entry="Short", stop=stopPrice, limit=takePrice)
// === Exit Conditions ===
// Alternative exit conditions based on crossovers
exitLongCondition = ta.crossunder(shortEMA, longEMA) or (macdLine < signalLine)
exitShortCondition = ta.crossover(shortEMA, longEMA) or (macdLine > signalLine)
if (exitLongCondition)
strategy.close("Long")
if (exitShortCondition)
strategy.close("Short")
// === Indicator Plotting ===
// EMA
plot(shortEMA, color=color.blue, title="Short EMA")
plot(longEMA, color=color.red, title="Long EMA")
// MACD Indicator in separate window
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)
plot(macdLine - signalLine, color=(macdLine - signalLine) >= 0 ? color.green : color.red, title="MACD Histogram", style=plot.style_histogram)
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// === Signal Visualization ===
// Markers for Long and Short entries
plotshape(series=longCondition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="Long")
plotshape(series=shortCondition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")
// Markers for Long and Short exits
plotshape(series=exitLongCondition, title="Long Exit", location=location.abovebar, color=color.red, style=shape.labeldown, text="Exit Long")
plotshape(series=exitShortCondition, title="Short Exit", location=location.belowbar, color=color.green, style=shape.labelup, text="Exit Short")