
이 전략은 간단한 이동 평균 ((SMA) 의 교차를 기반으로 한 공백 거래 시스템으로 시장의 하향 경향을 포착하는 데 초점을 맞추고 있습니다. 이 전략은 20주기 및 50주기의 간단한 이동 평균을 핵심 지표로 사용하여 단기 SMA ((20) 가 아래로 긴 SMA ((50) 를 통과하면 시스템이 빈 신호를 생성합니다. 단기 SMA ((20) 가 위로 긴 SMA ((50) 를 통과하면 시스템이 평점입니다.
이 전략은 기술 분석의 고전적인 이동 평균 교차 이론에 기초한다. 그것의 핵심 논리는 다음과 같다:
코드 구현에서 보면, 전략은 Pine Script 언어의 ta.crossunder () 와 ta.crossover () 함수를 사용하여 평행선 교차 사건을 정확하게 캡처하고, strategy.entry () 와 strategy.close () 함수를 통해 거래를 실행한다. 또한, 전략은 차트에 거래 신호를 직관적으로 표시하여 거래자가 거래 논리의 수행을 즉시 이해할 수 있도록 돕는다.
SMA20/50 지능형 표 거래 시스템은 간단한 이동 평균의 교차 신호를 포착하여 공상 거래를 수행하는 간결하고 효율적인 양적 거래 전략입니다. 이 전략은 하향 추세에서 우수한 성능을 발휘하며, 작동 논리는 명확하고 이해하기 쉽고 구현됩니다.
/*backtest
start: 2025-01-01 00:00:00
end: 2025-03-31 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("SMA20/50 Short-Only Strategy", overlay=true, initial_capital=5000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Input sources and calculations
src = close
sma20 = ta.sma(src, 20)
sma50 = ta.sma(src, 50)
// Generate sell signal when sma20 crosses below sma50
sellSignal = ta.crossunder(sma20, sma50)
// Generate exit signal when sma20 crosses above sma50
exitSignal = ta.crossover(sma20, sma50)
// Plot SMAs
plot(sma20, color = color.blue, title = "SMA 20")
plot(sma50, color = color.black, title = "SMA 50")
// Plot sell signal
plotshape(sellSignal, style = shape.triangledown, location = location.abovebar, color = color.red, size = size.tiny, title = "Sell Signal")
// Plot exit signal
plotshape(exitSignal, style = shape.xcross, location = location.belowbar, color = color.green, size = size.tiny, title = "Exit Signal")
// Add label for sell signals
if sellSignal
label.new(bar_index, high, text="SELL", color = color.red, style = label.style_label_down, textcolor = color.white, size = size.small)
// Add label for exit signals
if exitSignal
label.new(bar_index, low, text="EXIT", color = color.green, style = label.style_label_up, textcolor = color.white, size = size.small)
// Strategy entry and exit - SHORT ONLY
if sellSignal
strategy.entry("Short", strategy.short)
if exitSignal
strategy.close("Short")
// Strategy performance stats
var cumPnL = 0.0
if strategy.closedtrades > 0
cumPnL := strategy.netprofit