
이 전략은 슈퍼트렌드와 이중 지수 이동 평균 (DEMA) 을 기반으로 한 트렌드 추적 거래 시스템이다. 이 전략은 슈퍼트렌드 지표의 트렌드 방향 식별 능력과 DEMA의 트렌드 확인 기능을 결합하여 신뢰할 수 있는 거래 의사 결정 프레임워크를 구축한다. 이 시스템은 양방향 거래를 지원하며, 포지션 동적 조정 메커니즘을 갖추고 있으며, 시장 환경에 따라 다중 허공 방향을 유연하게 전환할 수 있다.
전략의 핵심 논리는 다음과 같은 핵심 구성 요소를 기반으로 합니다.
이 전략은 Supertrend와 DEMA 지표를 능숙하게 결합하여 안정적인 트렌드 추적 시스템을 구축한다. 이 전략의 장점은 신호 신뢰도가 높고 위험 관리가 완벽하지만 여전히 거래자가 특정 시장 특성에 따라 매개 변수를 최적화해야 한다는 것이다. 제안된 최적화 방향으로 전략의 적응성과 안정성이 더욱 향상될 것으로 보인다.
/*backtest
start: 2025-02-16 00:00:00
end: 2025-02-23 00:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=6
strategy("Supertrend with DEMA Strategy (Reversal Enabled)", overlay=true)
// ===== Parameters for Supertrend =====
atrPeriod = input.int(10, "ATR Length", minval=1)
factor = input.float(3.0, "Factor", minval=0.01, step=0.01)
// ===== Parameters for Allowing Trade Directions =====
allowLong = input.bool(true, "Allow LONG")
allowShort = input.bool(true, "Allow SHORT")
// Supertrend Calculation
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
// Set the value to na for the first bar to avoid false signals
supertrend := barstate.isfirst ? na : supertrend
// Plot Supertrend Lines
plot(direction < 0 ? supertrend : na, "Up Trend", color=color.green, style=plot.style_linebr)
plot(direction < 0 ? na : supertrend, "Down Trend", color=color.red, style=plot.style_linebr)
// ===== Parameters and Calculation for DEMA =====
demaLength = input.int(100, "DEMA Length", minval=1)
e1 = ta.ema(close, demaLength)
e2 = ta.ema(e1, demaLength)
dema = 2 * e1 - e2
// Plot DEMA
plot(dema, "DEMA", color=#43A047)
// ===== Signal Definitions =====
// Basic Supertrend Trend Change Signals
trendUp = ta.crossover(close, supertrend)
trendDown = ta.crossunder(close, supertrend)
// Entry Signals considering DEMA
longSignal = trendUp and (close > dema)
shortSignal = trendDown and (close < dema)
// ===== Entry/Exit Logic =====
// LONG Signal
if (longSignal)
// If there is an open SHORT position – reverse it to LONG if allowed
if (strategy.position_size < 0)
if (allowLong)
strategy.close("Short")
strategy.entry("Long", strategy.long)
else
// If reversal to LONG is not allowed – just close SHORT
strategy.close("Short")
// If there is no position – open LONG if allowed
else if (strategy.position_size == 0)
if (allowLong)
strategy.entry("Long", strategy.long)
// SHORT Signal
if (shortSignal)
// If there is an open LONG position – reverse it to SHORT if allowed
if (strategy.position_size > 0)
if (allowShort)
strategy.close("Long")
strategy.entry("Short", strategy.short)
else
// If reversal to SHORT is not allowed – just close LONG
strategy.close("Long")
// If there is no position – open SHORT if allowed
else if (strategy.position_size == 0)
if (allowShort)
strategy.entry("Short", strategy.short)
// ===== Additional Position Closure on Trend Change without Entry =====
// If Supertrend crosses (trend change) but DEMA conditions are not met,
// close the opposite position if open.
if (trendUp and not longSignal and strategy.position_size < 0)
strategy.close("Short")
if (trendDown and not shortSignal and strategy.position_size > 0)
strategy.close("Long")