
Esta estrategia es una estrategia comercial cuantitativa que combina el seguimiento de tendencias y mecanismos de salida temporal. El núcleo de la estrategia es capturar las tendencias del mercado observando la relación entre el precio y el promedio móvil de 60 días, introduciendo al mismo tiempo un mecanismo de liquidación forzada de fin de año para controlar los riesgos. Cuando el precio de cierre rompe la media móvil de 60 días y la pendiente de la media móvil es positiva, ingrese al mercado para comprar y cierre todas las posiciones el último día de negociación de cada año.
La estrategia se basa en los siguientes elementos centrales:
Esta estrategia construye un sistema comercial relativamente sólido al combinar el seguimiento de tendencias y la gestión del tiempo. La lógica de la estrategia es simple y clara, fácil de entender e implementar y tiene buena practicidad. Se espera que mediante una optimización razonable de parámetros y la complementación de medidas de control de riesgos, esta estrategia logre rendimientos estables en las transacciones reales.
/*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")