
이 전략은 지수 이동 평균(EMA)과 평균 방향 지수(ADX)를 결합한 추세 추종 거래 시스템입니다. 이 전략은 EMA50과 가격의 교차점에 따라 거래 방향을 결정하고, ADX 지표를 사용하여 시장 추세 강도를 걸러내는 동시에, 지속적으로 수익성 있는 K-라인을 기반으로 하는 동적 손절매 방식을 채택하여 수익을 보호합니다. 이 방법은 시장의 주요 추세를 포착할 수 있을 뿐만 아니라, 추세가 약해질 때 빠져나올 수도 있습니다.
전략의 핵심 논리는 다음과 같은 핵심 요소에 기초합니다.
이는 EMA와 ADX의 장점을 결합하여 위험을 통제하면서 추세를 효과적으로 포착하는 잘 설계된 추세 추종 전략입니다. 이 전략의 역동적인 손절매 메커니즘은 특히 혁신적이며, 수익 보호와 추세 포착 사이에서 좋은 균형을 이룰 수 있습니다. 최적화의 여지가 있지만, 전반적인 프레임워크는 완벽하고 논리는 명확합니다. 실제 거래에서 검증할 만한 전략 시스템입니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Simple EMA 50 Strategy with ADX Filter", overlay=true)
// Input parameters
emaLength = input.int(50, title="EMA Length")
adxThreshold = input.float(20, title="ADX Threshold", minval=0)
// Calculate EMA and ADX
ema50 = ta.ema(close, emaLength)
adxSmoothing = input.int(20, title="ADX Smoothing")
[diPlus, diMinus, adx] = ta.dmi(20, adxSmoothing)
// Conditions for long and short entries
adxCondition = adx > adxThreshold
longCondition = adxCondition and close > ema50 // Check if candle closes above EMA
shortCondition = adxCondition and close < ema50 // Check if candle closes below EMA
// Exit conditions based on 4 consecutive profitable candles
var float longSL = na
var float shortSL = na
var longCandleCounter = 0
var shortCandleCounter = 0
// Increment counters if positions are open and profitable
if (strategy.position_size > 0 and close > strategy.position_avg_price)
longCandleCounter += 1
if (longCandleCounter >= 4)
longSL := na(longSL) ? close : math.max(longSL, close) // Update SL dynamically
else
longCandleCounter := 0
longSL := na
if (strategy.position_size < 0 and close < strategy.position_avg_price)
shortCandleCounter += 1
if (shortCandleCounter >= 4)
shortSL := na(shortSL) ? close : math.min(shortSL, close) // Update SL dynamically
else
shortCandleCounter := 0
shortSL := na
// Exit based on trailing SL
if (strategy.position_size > 0 and not na(longSL) and close < longSL)
strategy.close("Buy", comment="Candle-based SL")
if (strategy.position_size < 0 and not na(shortSL) and close > shortSL)
strategy.close("Sell", comment="Candle-based SL")
// Entry logic: Check every candle for new positions
if (longCondition)
strategy.entry("Buy", strategy.long)
if (shortCondition)
strategy.entry("Sell", strategy.short)
// Plot EMA and ADX for reference
plot(ema50, color=color.blue, title="EMA 50")
plot(adx, color=color.orange, title="ADX", style=plot.style_stepline, linewidth=1)
plot(longSL, color=color.green, title="Long SL", style=plot.style_cross, linewidth=1)
plot(shortSL, color=color.red, title="Short SL", style=plot.style_cross, linewidth=1)
// Plot signals
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")