
이 전략은 지수 이동 평균 (EMA) 과 간단한 이동 평균 (SMA) 을 결합한 트렌드 추적 거래 시스템이다. 이 전략은 주로 EMA50와 EMA150의 교차를 사용하여 거래 신호를 생성하며, SMA150을 중지 라인으로 사용하고, 중단 후 재입장 메커니즘을 포함합니다. 이 디자인은 중장기 트렌드를 포착하는 동시에 위험을 효과적으로 제어 할 수 있습니다.
전략의 핵심 논리에는 다음과 같은 핵심 요소가 포함됩니다.
이것은 합리적으로 설계된 트렌드 추적 전략으로, 평선 교차로 트렌드를 포착하고, 완벽한 위험 제어 장치가 장착되어 있다. 전략의 주요 장점은 시스템의 트렌드 추적 능력과 위험 관리 설계에 있다. 그러나 실제 적용에서는 전략의 성능에 대한 시장 환경의 영향을 주의해야 한다. 제안된 최적화 방향에 의해 전략은 더 향상될 여지가 있다.
/*backtest
start: 2024-02-22 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=6
strategy("EMA 50 and EMA 150 with SMA150 Stop-loss and Re-Entry #ganges", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)
// EMA and SMA Calculations
ema50 = ta.ema(close, 50)
ema150 = ta.ema(close, 150)
sma150 = ta.sma(close, 150)
// Conditions for Buy, Sell, and Stop-Loss
ema50CrossAboveEMA150 = ta.crossover(ema50, ema150) // Buy signal
ema50CrossBelowEMA150 = ta.crossunder(ema50, ema150) // Sell signal
priceCrossAboveEMA150 = ta.crossover(close, ema150) // Price crosses EMA 150 from below
priceCloseBelowSMA150 = close < sma150 // Stop-loss for long positions
// Track stop-loss hit state
var bool stopLossHit = false
// Strategy Logic
// Buy Logic: EMA 50 crosses EMA 150 from below
if ema50CrossAboveEMA150
strategy.entry("Buy Signal", strategy.long, qty=1)
stopLossHit := false // Reset stop-loss state when a new buy position is opened
// Sell Logic: EMA 50 crosses EMA 150 from above
if ema50CrossBelowEMA150
strategy.entry("Sell Signal", strategy.short, qty=1)
stopLossHit := false // Reset stop-loss state when a new sell position is opened
// Stop-Loss for Long Positions: Close if price falls below SMA 150
if strategy.position_size > 0 and priceCloseBelowSMA150
strategy.close("Buy Signal")
stopLossHit := true // Mark stop-loss hit
// Re-Entry Logic After Stop-Loss
if stopLossHit
if priceCrossAboveEMA150 // Re-buy logic: PRICE crosses EMA 150 from below
strategy.entry("Re-Buy Signal", strategy.long, qty=1)
stopLossHit := false // Reset stop-loss state after re-entry
if ema50CrossBelowEMA150 // Re-sell logic: EMA 50 crosses EMA 150 from above
strategy.entry("Re-Sell Signal", strategy.short, qty=1)
stopLossHit := false // Reset stop-loss state after re-entry
// Plot EMA and SMA Lines
plot(ema50, color=color.blue, title="EMA 50")
plot(ema150, color=color.red, title="EMA 150")
plot(sma150, color=color.orange, title="SMA 150")
// // Calculate Recent All-Time High
// highestHigh = ta.highest(high, 500) // Lookback period of 500 bars
// percentageFall = ((highestHigh - close) / highestHigh) * 100
// // Display Percentage Fall on the Most Recent Candle Only
// isLastBar = bar_index == ta.max(bar_index)
// if isLastBar
// labelText = str.tostring(percentageFall, "#.##") + "% Fall from ATH"
// labelPosition = high + ta.atr(14) * 2 // Positioning label above the candle
// label.new(bar_index, labelPosition, labelText, color=color.red, textcolor=color.white, size=size.small, style=label.style_label_down)