
이 전략은 트렌드 추적과 기계 학습을 결합한 정량 거래 방법이며, 시장 트렌드를 포착하고 동적 스톱 및 트렌드 확인 신호를 통해 위험을 줄이기 위해 고안되었습니다. 전략은 단기 및 장기 간단한 이동 평균 (SMA) 을 사용하여 잠재적인 트렌드 방향을 식별하고 상대적으로 강한 지수 (RSI) 를 사용하여 거래 신호를 확인하기 위해 기계 학습 신뢰의 대리인으로 사용했습니다.
동적 트렌드 추적 전략과 기계 학습 강화 위험 관리는 트렌드 추적, 신호 확인 및 동적 위험 관리를 결합하여 거래자에게 강력한 도구를 제공하는 종합적인 정량 거래 방법입니다. 전략에는 잠재적인 위험이 있지만 지속적인 최적화 및 개선으로 인해 성능과 적응력을 더욱 향상시킬 수 있습니다.
/*backtest
start: 2024-09-18 00:00:00
end: 2024-09-25 00:00:00
period: 15m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Enhanced Trend Following with ML", overlay=true)
// User Inputs
shortLength = input.int(20, minval=1, title="Short Moving Average Length")
longLength = input.int(50, minval=1, title="Long Moving Average Length")
atrPeriod = input.int(14, title="ATR Period")
stopLossMultiplier = input.float(2.0, title="Stop Loss Multiplier")
mlConfidenceThreshold = input.float(0.5, title="ML Confidence Threshold")
// Calculate Moving Averages
shortMA = ta.sma(close, shortLength)
longMA = ta.sma(close, longLength)
// Plot Moving Averages
plot(shortMA, title="Short MA", color=color.red)
plot(longMA, title="Long MA", color=color.blue)
// Trend Strength Indicator (using RSI as a proxy for ML confidence)
mlSignal = math.round(ta.rsi(close, 14) / 100)
// Conditions for entering trades
longCondition = ta.crossover(shortMA, longMA) and mlSignal > mlConfidenceThreshold
shortCondition = ta.crossunder(shortMA, longMA) and mlSignal < (1 - mlConfidenceThreshold)
// ATR for dynamic stop loss
atrValue = ta.atr(atrPeriod)
stopLoss = atrValue * stopLossMultiplier
// Trade Entry
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("SLLong", "Long", stop=strategy.position_avg_price - stopLoss)
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("SLShort", "Short", stop=strategy.position_avg_price + stopLoss)
// Trade Management
longCrossover = ta.crossover(shortMA, longMA)
shortCrossunder = ta.crossunder(shortMA, longMA)
if (strategy.position_size > 0)
if (longCrossover)
strategy.close("Long")
if (strategy.position_size < 0)
if (shortCrossunder)
strategy.close("Short")
// Trailing Stop for existing positions
var float trailStopLong = strategy.position_avg_price
var float trailStopShort = strategy.position_avg_price
if (strategy.position_size > 0)
trailStopLong := math.min(trailStopLong, close)
strategy.exit("TrailLong", "Long", stop=trailStopLong)
if (strategy.position_size < 0)
trailStopShort := math.max(trailStopShort, close)
strategy.exit("TrailShort", "Short", stop=trailStopShort)
// Additional alert for trend changes
alertcondition(longCrossover, title="Bullish Trend Change", message="Bullish trend change detected")
alertcondition(shortCrossunder, title="Bearish Trend Change", message="Bearish trend change detected")