
Chiến lược này là chiến lược giao dịch định lượng kết hợp theo dõi xu hướng và cơ chế thoát lệnh theo thời gian. Cốt lõi của chiến lược này là nắm bắt xu hướng thị trường bằng cách quan sát mối quan hệ giữa giá và đường trung bình động 60 ngày, đồng thời áp dụng cơ chế thanh lý bắt buộc vào cuối năm để kiểm soát rủi ro. Khi giá đóng cửa vượt qua đường trung bình động 60 ngày và độ dốc của đường trung bình động là dương, hãy vào thị trường để mua vào và đóng tất cả các vị thế vào ngày giao dịch cuối cùng của mỗi năm.
Chiến lược này dựa trên các yếu tố cốt lõi sau:
Chiến lược này xây dựng một hệ thống giao dịch tương đối mạnh mẽ bằng cách kết hợp việc theo dõi xu hướng và quản lý thời gian. Logic chiến lược đơn giản và rõ ràng, dễ hiểu và dễ triển khai, có tính thực tiễn cao. Thông qua việc tối ưu hóa các thông số hợp lý và bổ sung các biện pháp kiểm soát rủi ro, chiến lược này dự kiến sẽ đạt được lợi nhuận ổn định trong các giao dịch thực tế.
/*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")