
이 전략은 쌍 지수 이동 평균 ((EMA) 의 교차를 기반으로 한 트렌드 추적 시스템으로, 단계적 탈퇴 메커니즘을 결합하여 거래 수익을 최적화합니다. 이 전략은 9주기 및 21주기 EMA를 빠른 라인 및 느린 라인으로 사용하여, 시장 추세의 변화를 식별하기 위해 그들의 교차를 통해, 위험과 수익을 균형을 맞추기 위해 두 단계의 포지션 탈퇴 프로그램을 사용합니다.
전략의 핵심 논리는 빠른 EMA ((9주기) 와 느린 EMA ((21주기) 의 교차 신호에 기반한다. 빠른 선에서 느린 선을 통과할 때, 시스템은 0.02로 다중 상위 포지션을 열고, 빠른 선에서 느린 선을 통과할 때, 시스템은 0.02로 빈 상위 포지션을 열는다. 포지션을 보유하는 동안, 전략은 두 단계의 퇴출 메커니즘을 사용합니다.
이것은 고전적인 평선 교차 전략과 현대적인 포지션 관리를 결합한 완전한 거래 시스템이다. 전략은 단계적 퇴출 메커니즘을 통해 전통적인 평선 교차 전략의 수익성을 향상시키지만, 여전히 거래자가 특정 시장 환경과 자신의 위험 수용 능력에 따라 적절한 조정을 해야 한다. 미래 최적화 방향은 주로 신호 필터링과 동적 위험 관리 두 가지 측면에 집중한다.
/*backtest
start: 2024-02-25 00:00:00
end: 2025-02-22 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("EMA Crossover with Partial Exit", overlay=true, default_qty_type=strategy.cash, default_qty_value=50)
// Define lot sizes
lotSize = 0.02 // Initial trade size
partialLot = 0.01 // Half quantity to close at 20 pips profit
profitTarget = 200 // 20 pips = 200 points (for Forex, adjust accordingly)
// Define EMA lengths
fastLength = 9
slowLength = 21
// Compute EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
// Define crossover conditions
longEntry = ta.crossover(fastEMA, slowEMA) // Buy when 9 EMA crosses above 21 EMA
shortEntry = ta.crossunder(fastEMA, slowEMA) // Sell when 9 EMA crosses below 21 EMA
// Track trade state
var float entryPrice = na
var bool inTrade = false
var bool isLong = false
// Entry Logic (Enter with 0.02 lot size)
if (longEntry and not inTrade)
strategy.entry("Long", strategy.long, qty=lotSize)
entryPrice := close
inTrade := true
isLong := true
if (shortEntry and not inTrade)
strategy.entry("Short", strategy.short, qty=lotSize)
entryPrice := close
inTrade := true
isLong := false
// Partial Exit Logic (Close 0.01 lot after 20 pips profit)
if (isLong and inTrade and close >= entryPrice + profitTarget * syminfo.mintick)
strategy.close("Long", qty=partialLot)
if (not isLong and inTrade and close <= entryPrice - profitTarget * syminfo.mintick)
strategy.close("Short", qty=partialLot)
// Full Exit (Close remaining 0.01 lot at the next major crossover)
if (isLong and shortEntry)
strategy.close("Long") // Close remaining position
inTrade := false
if (not isLong and longEntry)
strategy.close("Short") // Close remaining position
inTrade := false
// Plot EMAs
plot(fastEMA, color=color.blue, title="9 EMA")
plot(slowEMA, color=color.red, title="21 EMA")
// Mark Buy/Sell Signals
plotshape(series=longEntry, location=location.belowbar, color=color.green, style=shape.labelup, title="BUY Signal")
plotshape(series=shortEntry, location=location.abovebar, color=color.red, style=shape.labeldown, title="SELL Signal")