This strategy combines trend following with a time-based exit mechanism. The core concept is to capture market trends by monitoring price relationships with the 60-day moving average while incorporating a year-end forced liquidation mechanism for risk control. Long positions are entered when the closing price breaks above the 60-day MA with a positive slope, and all positions are closed on the last trading day of each year.
The strategy is based on several core elements: 1. Trend Determination: Uses a 60-day Simple Moving Average (SMA) as a medium-term trend indicator, with a 14-day slope calculation to confirm trend direction. 2. Entry Signal: Buy signals are generated when price breaks above the 60-day MA with a positive slope, indicating a potential uptrend. 3. Exit Mechanism: Implements a fixed time-based exit, closing all positions on the last trading day of each year to avoid cross-year position risks. 4. Trading Time Management: Incorporates date range control and trading day validation to ensure operations only occur on valid trading days.
This strategy creates a relatively robust trading system by combining trend following with time management. Its simple and clear logic makes it easy to understand and implement, offering good practical utility. With appropriate parameter optimization and supplementary risk control measures, the strategy shows potential for generating stable returns in real trading conditions.
/*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")