
이 전략은 전통적인 기술 분석과 현대 인공지능 방법을 결합한 트렌드 추적 시스템이다. 그것은 주로 지수 이동 평균 (EMA) 과 간단한 이동 평균 (SMA) 을 트렌드 필터로 사용하며, 입시 시기를 최적화하기 위해 예측 모델을 도입한다. 전략은 특히 일선 레벨에 최적화되어 중·장기 시장 트렌드를 포착하기 위해 고안되었다.
전략의 핵심 논리는 세 가지 주요 구성 요소로 구성됩니다.
거래 신호의 생성에는 트렌드 방향과 예측 신호의 일관성을 동시에 충족해야 합니다.
이 전략은 전통적인 기술 분석과 현대적인 예측 방법을 결합하여 안정적인 트렌드 추적 시스템을 구축한다. 주요 장점은 논리 명확성, 위험 제어 가능성과 강력한 확장성이다. 전략 최적화, 특히 예측 모델과 위험 제어의 개선으로 전략의 안정성과 수익성을 더욱 향상시킬 것으로 기대된다. 전략은 중·장기적으로 안정적인 수익을 추구하는 투자자에게 적합하다.
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("My Strategy", overlay=true)
// Parameters (adjust as needed)
neighborsCount = 8
maxBarsBack = 2000
featureCount = 5
useDynamicExits = true
useEmaFilter = true
emaPeriod = 200
useSmaFilter = true
smaPeriod = 200
// Moving Average Calculations
ema = ta.ema(close, emaPeriod)
sma = ta.sma(close, smaPeriod)
// Trend Conditions
isEmaUptrend = close > ema
isEmaDowntrend = close < ema
isSmaUptrend = close > sma
isSmaDowntrend = close < sma
// Model Prediction (Replace with your real model)
// Here a simulation is used, replace it with real predictions
prediction = math.random() * 2 - 1 // Random value between -1 and 1
// Entry Signals
isNewBuySignal = prediction > 0 and isEmaUptrend and isSmaUptrend
isNewSellSignal = prediction < 0 and isEmaDowntrend and isSmaDowntrend
// Exit Signals
var int barsHeld = 0
var bool in_position = false
var int entry_bar = 0
if isNewBuySignal and not in_position
in_position := true
entry_bar := bar_index
barsHeld := 1
else if isNewSellSignal and not in_position
in_position := true
entry_bar := bar_index
barsHeld := 1
else if in_position
barsHeld := barsHeld + 1
if barsHeld == 4
in_position := false
endLongTradeStrict = barsHeld == 4 and isNewBuySignal[1]
endShortTradeStrict = barsHeld == 4 and isNewSellSignal[1]
// Backtest Logic
var float totalProfit = 0
var float entryPrice = na
var int tradeDirection = 0
if isNewBuySignal and tradeDirection <= 0
entryPrice := close
tradeDirection := 1
strategy.entry("Long", strategy.long)
if isNewSellSignal and tradeDirection >= 0
entryPrice := close
tradeDirection := -1
strategy.entry("Short", strategy.short)
if (endLongTradeStrict and tradeDirection == 1) or (endShortTradeStrict and tradeDirection == -1)
exitPrice = close
profit = (exitPrice - entryPrice) / entryPrice
if tradeDirection == -1
profit := (entryPrice - exitPrice) / entryPrice
totalProfit := totalProfit + profit
tradeDirection := 0
strategy.close_all()
plot(close, color=color.blue)
plot(ema, color=color.orange)
plot(sma, color=color.purple)