
이 전략은 복합적인 트렌드 추적 거래 시스템으로, 여러 시간 프레임 분석, 평균선 시스템, 동력 지표 및 변동률 지표가 결합되어 있다. 시스템은 단기 및 장기 지수 이동 평균 (EMA) 의 교차를 통해 트렌드 방향을 식별하고, 상대적으로 강한 지표 (RSI) 를 사용하여 과매매 판단을 하고, MACD와 결합하여 동력을 확인하고, 더 높은 시간 프레임 (EMA) 을 트렌드 필터 시스템으로 활용한다. ATR 기반의 동적 중지 및 수익 프로그램을 채택하여 시장의 변동성에 따라 적응할 수 있다.
이 전략은 거래 결정에 대해 다단계 인증 메커니즘을 사용합니다.
이 시스템은 EMA가 교차하고, RSI가 극한에 도달하지 않고, MACD 방향이 정확하고, 높은 시간 프레임 트렌드가 확인된 후 포지션을 열 수 있습니다.
이 전략은 전체적인 트렌드 추적 거래 시스템으로, 다중 기술 지표의 조합과 엄격한 위험 관리 제도를 통해 트렌드 시장에서 안정적인 수익을 얻을 수 있습니다. 시스템의 확장성은 강하며, 최적화함으로써 다양한 시장 환경에 적응할 수 있습니다. 실물 거래 전에 충분한 회귀와 변수 최적화가 권장됩니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-24 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Trend Following with ATR, MTF Confirmation, and MACD", overlay=true)
// Parameters
emaShortPeriod = input.int(9, title="Short EMA Period", minval=1)
emaLongPeriod = input.int(21, title="Long EMA Period", minval=1)
rsiPeriod = input.int(14, title="RSI Period", minval=1)
rsiOverbought = input.int(70, title="RSI Overbought", minval=50)
rsiOversold = input.int(30, title="RSI Oversold", minval=1)
atrPeriod = input.int(14, title="ATR Period", minval=1)
atrMultiplier = input.float(1.5, title="ATR Multiplier", minval=0.1)
takeProfitATRMultiplier = input.float(2.0, title="Take Profit ATR Multiplier", minval=0.1)
// Multi-timeframe settings
htfEMAEnabled = input.bool(true, title="Use Higher Timeframe EMA Confirmation?", inline="htf")
htfEMATimeframe = input.timeframe("D", title="Higher Timeframe", inline="htf")
// MACD Parameters
macdShortPeriod = input.int(12, title="MACD Short Period", minval=1)
macdLongPeriod = input.int(26, title="MACD Long Period", minval=1)
macdSignalPeriod = input.int(9, title="MACD Signal Period", minval=1)
// Select trade direction
tradeDirection = input.string("Both", title="Trade Direction", options=["Both", "Long", "Short"])
// Calculating indicators
emaShort = ta.ema(close, emaShortPeriod)
emaLong = ta.ema(close, emaLongPeriod)
rsiValue = ta.rsi(close, rsiPeriod)
atrValue = ta.atr(atrPeriod)
// Calculate MACD
[macdLine, macdSignalLine, _] = ta.macd(close, macdShortPeriod, macdLongPeriod, macdSignalPeriod)
// Higher timeframe EMA confirmation
htfEMALong = request.security(syminfo.tickerid, htfEMATimeframe, ta.ema(close, emaLongPeriod))
// Trading conditions
longCondition = ta.crossover(emaShort, emaLong) and rsiValue < rsiOverbought and (not htfEMAEnabled or close > htfEMALong) and macdLine > macdSignalLine
shortCondition = ta.crossunder(emaShort, emaLong) and rsiValue > rsiOversold and (not htfEMAEnabled or close < htfEMALong) and macdLine < macdSignalLine
// Plotting EMAs
plot(emaShort, title="EMA Short", color=color.green)
plot(emaLong, title="EMA Long", color=color.red)
// Plotting MACD
hline(0, "Zero Line", color=color.gray)
plot(macdLine - macdSignalLine, title="MACD Histogram", color=color.green, style=plot.style_histogram)
plot(macdLine, title="MACD Line", color=color.blue)
plot(macdSignalLine, title="MACD Signal Line", color=color.red)
// Trailing Stop-Loss and Take-Profit levels
var float trailStopLoss = na
var float trailTakeProfit = na
if (strategy.position_size > 0) // Long Position
trailStopLoss := na(trailStopLoss) ? close - atrValue * atrMultiplier : math.max(trailStopLoss, close - atrValue * atrMultiplier)
trailTakeProfit := close + atrValue * takeProfitATRMultiplier
strategy.exit("Exit Long", "Long", stop=trailStopLoss, limit=trailTakeProfit, when=shortCondition)
if (strategy.position_size < 0) // Short Position
trailStopLoss := na(trailStopLoss) ? close + atrValue * atrMultiplier : math.min(trailStopLoss, close + atrValue * atrMultiplier)
trailTakeProfit := close - atrValue * takeProfitATRMultiplier
strategy.exit("Exit Short", "Short", stop=trailStopLoss, limit=trailTakeProfit, when=longCondition)
// Strategy Entry
if (longCondition and (tradeDirection == "Both" or tradeDirection == "Long"))
strategy.entry("Long", strategy.long)
if (shortCondition and (tradeDirection == "Both" or tradeDirection == "Short"))
strategy.entry("Short", strategy.short)
// Plotting Buy/Sell signals
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Plotting Trailing Stop-Loss and Take-Profit levels
plot(strategy.position_size > 0 ? trailStopLoss : na, title="Long Trailing Stop Loss", color=color.red, linewidth=2, style=plot.style_line)
plot(strategy.position_size < 0 ? trailStopLoss : na, title="Short Trailing Stop Loss", color=color.green, linewidth=2, style=plot.style_line)
plot(strategy.position_size > 0 ? trailTakeProfit : na, title="Long Take Profit", color=color.blue, linewidth=2, style=plot.style_line)
plot(strategy.position_size < 0 ? trailTakeProfit : na, title="Short Take Profit", color=color.orange, linewidth=2, style=plot.style_line)