
이는 SuperTrend 지표, 지수 이동 평균선(EMA), 평균 진폭 범위(ATR)를 기반으로 한 추세 추종 전략입니다. 이 전략은 초기 손절매와 이동 손절매와 함께 여러 가지 기술 지표를 사용하여 시장 동향을 동적으로 추적하고 위험을 제어합니다. 전략의 핵심은 SuperTrend 지표를 통해 추세 방향의 변화를 포착하고, 추세 확인을 위해 EMA를 사용하고, 수익을 보호하기 위해 이중 손절매 메커니즘을 설정하는 것입니다.
이 전략은 다음과 같은 핵심 구성 요소를 기반으로 운영됩니다.
SuperTrend 방향이 하락하고 종가가 EMA 위에 있는 경우, 시스템은 포지션을 유지하지 않고 롱 신호를 발행합니다. 반대로, SuperTrend 방향이 상승하고 종가가 EMA 아래에 있는 경우, 시스템은 단기 신호를 보냅니다.
이는 여러 가지 기술 지표와 위험 관리 메커니즘을 결합한 완전한 거래 전략입니다. SuperTrend 지표를 통해 추세를 파악하고, EMA를 통해 방향을 확인하며, 이중 손절매 메커니즘과 조정하여 더 나은 위험-수익 비율을 달성합니다. 전략의 최적화 공간은 주로 매개변수의 동적 조정, 시장 환경에 대한 판단, 위험 관리 시스템의 개선에 있습니다. 실제 적용에서는 충분한 과거 데이터 백테스트를 수행하고 특정 거래 상품의 특성에 따라 매개변수를 조정하는 것이 좋습니다.
/*backtest
start: 2024-01-17 00:00:00
end: 2025-01-15 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy(" nifty supertrend triton", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Input parameters
atrPeriod = input.int(16, "ATR Length", step=1)
factor = input.float(3.02, "Factor", step=0.01)
maPeriod = input.int(49, "Moving Average Period", step=1)
trailPoints = input.int(70, "Trailing Points", step=1) // Points after which trailing stop activates
initialStopLossPoints = input.int(50, "Initial Stop Loss Points", step=1) // Initial stop loss of 50 points
// Calculate Supertrend
[_, direction] = ta.supertrend(factor, atrPeriod)
// Calculate EMA
ema = ta.ema(close, maPeriod)
// Variables to track stop loss levels
var float trailStop = na
var float entryPrice = na
var float initialStopLoss = na // To track the initial stop loss
// Generate buy and sell signals
if ta.change(direction) < 0 and close > ema
if strategy.position_size == 0 // Only open a new long position if no current position
strategy.entry("Buy", strategy.long)
entryPrice := close // Record the entry price for the long position
initialStopLoss := entryPrice - initialStopLossPoints // Set initial stop loss for long position
trailStop := na // Reset trailing stop for long
if ta.change(direction) > 0 and close < ema
if strategy.position_size == 0 // Only open a new short position if no current position
strategy.entry("Sell", strategy.short)
entryPrice := close // Record the entry price for the short position
initialStopLoss := entryPrice + initialStopLossPoints // Set initial stop loss for short position
trailStop := na // Reset trailing stop for short
// Apply initial stop loss for long positions
if (strategy.position_size > 0) // Check if in a long position
if close <= initialStopLoss // If the price drops to or below the initial stop loss
strategy.close("Buy", "Initial Stop Loss Hit") // Exit the long position
// Apply trailing stop logic for long positions
if (strategy.position_size > 0) // Check if in a long position
if (close - entryPrice >= trailPoints) // If the price has moved up by the threshold
trailStop := na(trailStop) ? close - trailPoints : math.max(trailStop, close - trailPoints) // Adjust trailing stop upwards
if not na(trailStop) and close < trailStop // If the price drops below the trailing stop
strategy.close("Buy", "Trailing Stop Hit") // Exit the long position
// Apply initial stop loss for short positions
if (strategy.position_size < 0) // Check if in a short position
if close >= initialStopLoss // If the price rises to or above the initial stop loss
strategy.close("Sell", "Initial Stop Loss Hit") // Exit the short position
// Apply trailing stop logic for short positions
if (strategy.position_size < 0) // Check if in a short position
if (entryPrice - close >= trailPoints) // If the price has moved down by the threshold
trailStop := na(trailStop) ? close + trailPoints : math.min(trailStop, close + trailPoints) // Adjust trailing stop downwards
if not na(trailStop) and close > trailStop // If the price rises above the trailing stop
strategy.close("Sell", "Trailing Stop Hit") // Exit the short position