
이 전략은 추세 추적과 시간적 종료 메커니즘을 결합한 양적 거래 전략입니다. 전략의 핵심은 가격과 60일 이동평균선 간의 관계를 관찰하여 시장 동향을 파악하는 동시에, 위험을 통제하기 위해 연말 강제 청산 메커니즘을 도입하는 것입니다. 종가가 60일 이동평균선을 돌파하고 이동평균선의 기울기가 양수이면, 시장에 진입하여 롱 포지션을 취하고 각 연도의 마지막 거래일에 모든 포지션을 청산합니다.
이 전략은 다음과 같은 핵심 요소를 기반으로 합니다.
이 전략은 추세 추종과 시간 관리를 결합하여 비교적 강력한 거래 시스템을 구축합니다. 전략적 논리는 간단하고 명확하며, 이해하고 구현하기 쉽고 실용성이 좋습니다. 합리적인 매개변수 최적화와 위험 관리 조치의 보완을 통해 이 전략은 실제 거래에서 안정적인 수익을 달성할 것으로 기대됩니다.
/*backtest
start: 2025-01-09 00:00:00
end: 2025-01-16 00:00:00
period: 3m
basePeriod: 3m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("Buy above 60-day MA, Sell at year-end", overlay=true, pyramiding=1)
// Define inputs for start and end dates
startDate = input(defval=timestamp("2010-01-01"), title="Start Date")
endDate = input(defval=timestamp("2024-12-31"), title="End Date")
// Define 60-day moving average
length = input.int(defval=60, title="MA Length", minval=1)
ma = ta.sma(close, length)
slope = ta.sma(ma, 14) - ta.sma(ma, 14)[1]
// Check if current bar is within the specified date range
withinDateRange = true
// Function to check if a day is a trading day (Monday to Friday)
isTradingDay(day) => true
// Check if current bar is the last trading day of the year
// Check if current bar is the last trading day of the year
isLastTradingDayOfYear = false
yearNow = year(time)
if (month == 12 and dayofmonth == 31)
isLastTradingDayOfYear := isTradingDay(time)
else if (month == 12 and dayofmonth == 30)
isLastTradingDayOfYear := isTradingDay(time) and not isTradingDay(time + 86400000)
else if (month == 12 and dayofmonth == 29)
isLastTradingDayOfYear := isTradingDay(time) and not isTradingDay(time + 86400000) and not isTradingDay(time + 86400000 * 2)
// Plot moving average
plot(ma, color=color.blue, linewidth=2)
// Buy when closing price crosses above 60-day MA and up trend
if (withinDateRange and ta.crossover(close, ma) and slope > 0)
strategy.entry("Buy", strategy.long)
// Sell all positions at the last trading day of the year
if (isLastTradingDayOfYear)
strategy.close_all(comment="Sell at year-end")
// Plot buy and sell signals
//plotshape(series=ta.crossover(close, ma), location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
//plotshape(series=isLastTradingDayOfYear, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")