
이 전략은 다기간 단순 이동 평균(SMA) 교차 신호를 기반으로 하는 양적 거래 시스템입니다. 주로 장기 상승 추세 내에서 단기 하락 기회를 식별하여 거래합니다. 이 전략은 5일, 10일, 20일, 60일, 120일의 5개 기간을 갖는 SMA 지표를 사용하여 이동 평균선의 포지션 관계와 교차 신호를 통해 시장 동향과 거래 기회를 판단합니다.
전략의 핵심 논리는 다음과 같은 핵심 부분으로 구성됩니다.
이 전략은 다기간 SMA 이동 평균을 사용하여 장기 상승 추세에서 풀백 기회를 포착하는 데 중점을 둔 거래 시스템을 구축합니다. 전략 설계는 간결하고 실용적이며, 이해하기 쉽고 실행하기가 쉽습니다. 변동성 필터링, 거래량 확인과 같은 최적화 조치를 도입함으로써 전략의 견고성과 신뢰성이 더욱 향상될 것으로 기대됩니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Long-Term Growing Stock Strategy", overlay=true)
// Date Range
// STEP 1. Create inputs that configure the backtest's date range
useDateFilter = input.bool(true, title="Filter Date Range of Backtest",group="Backtest Time Period")
backtestStartDate = input(timestamp("1 Jan 2014"),title="Start Date", group="Backtest Time Period",tooltip="This start date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " +"zone of the chart or of your computer.")
backtestEndDate = input(timestamp("31 Dec 2024"), title="End Date", group="Backtest Time Period")
// STEP 2. See if current bar falls inside the date range
inTradeWindow = true
// Calculate EMAs
// ema20 = ta.ema(close, ema20_length)
// ema60 = ta.ema(close, ema60_length)
// ema120 = ta.ema(close, ema120_length)
sma5 = ta.sma(close, 5)
sma10 = ta.sma(close, 10)
sma20 = ta.sma(close, 20)
sma60 = ta.sma(close, 60)
sma120 = ta.sma(close, 120)
// Long-term growth condition: EMA 20 > EMA 60 > EMA 120
longTermGrowth = sma20 > sma60
// and ema60 > ema120
// Entry condition: Stock closes below EMA 20 and then rises back above EMA 10
// entryCondition = ta.crossover(close, ema20) or (close[1] < ema20[1] and close > ema20)
entryCondition = sma5[1] <= sma20[1] and sma5 > sma20
// ta.crossover(sma5, sma20)
// Exit condition: EMA 20 drops below EMA 60
// exitCondition = ema5 < ema60 or (year == 2024 and month == 12 and dayofmonth == 30)
exitCondition = ta.crossover(sma20, sma5)
// Execute trades
if entryCondition and inTradeWindow
strategy.entry("Long Entry", strategy.long)
if exitCondition and inTradeWindow
strategy.close("Long Entry")
// plotchar(true, char="sma5: " + str.tostring(sma5))
// plotchar(true, char="sma5: " + sma20)
// label.new(x=bar_index, y=high + 10, text="SMA 5: " + str.tostring(sma5), color=color.blue, style=label.style_label_down, textcolor=color.white, size=size.small)
// label.new(x=bar_index, y=low, text="SMA 20: " + str.tostring(sma20), color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small)
// x = time + (time - time[1]) * offset_x
// var label lab = na
// label.delete(lab)
// lab := label.new(x=x, y=0, text=txt, xloc=xloc.bar_time, yloc=yloc.belowbar, color=color.red, textcolor=color.black, size=size.normal, style=label.style_label_up)
// label.set_x(lab, x)
// Plot EMAs for visualization
// plot(ema20, color=color.red, title="EMA 20")
// plot(ema60, color=color.green, title="EMA 60")
// plot(ema120, color=color.blue, title="EMA 120")