该策略是一个基于历史新高突破和月线均线过滤的趋势跟踪策略。它通过监控价格是否突破之前的历史最高点来寻找买入信号,同时利用月线8周期简单移动平均线(8 SMA)作为卖出过滤条件,以此降低假突破带来的风险。这种策略设计理念符合”趋势延续性”这一市场特征,特别适合在强势上涨趋势中捕捉大级别行情。
策略的核心逻辑包含两个关键部分: 1. 买入信号:当最新收盘价突破前期历史最高点(不包含当前K线的最高价)时,系统产生买入信号。这个条件确保只在明确的上升趋势中入场。 2. 卖出信号:当月线收盘价跌破8周期简单移动平均线时,系统触发卖出信号。这个条件帮助及时止损,防止趋势反转造成更大损失。 策略还设计了信号状态跟踪机制,避免在同一状态下重复产生信号,提高了策略的稳定性。
这是一个设计合理、逻辑清晰的趋势跟踪策略。通过历史新高突破和月线均线的配合使用,既保证了对趋势的有效把握,又实现了风险的合理控制。虽然存在一定的滞后性和假突破风险,但通过建议的优化方向,策略的整体表现有望得到进一步提升。该策略特别适合在明确趋势的市场环境中应用,可以作为中长期投资的重要参考工具。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-11 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Buy Signal on Close Greater Than Previous All-Time High Strategy", overlay=true)
// Initialize the previous all-time high
var float prevAllTimeHigh = na
// Update the all-time high, excluding the current bar's high (use previous bar's high)
if (na(prevAllTimeHigh) or high[1] > prevAllTimeHigh)
prevAllTimeHigh := high[1]
// Monthly closing price and 8 SMA on monthly time frame
monthlyClose = request.security(syminfo.tickerid, "M", close)
monthlySMA = ta.sma(monthlyClose, 8)
// Variables to track the last signal type
var int lastSignal = 0 // 0 = None, 1 = Buy, 2 = Sell
// Debugging output to check the all-time high and conditions
plot(prevAllTimeHigh, color=color.blue, linewidth=1, title="Previous All-Time High")
plot(monthlySMA, color=color.green, linewidth=1, title="8 SMA (Monthly)")
// Buy signal: when the latest close is greater than the previous all-time high
buySignal = close > prevAllTimeHigh and lastSignal != 1
// Sell signal: when the monthly close is below the 8 SMA
sellSignal = monthlyClose < monthlySMA and lastSignal != 2
// Update the last signal type after triggering a signal
if (buySignal)
lastSignal := 1
if (sellSignal)
lastSignal := 2
// Execute the strategy orders
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.close("Buy")
// Optional: Plot buy and sell signals on the chart for visual reference
plotshape(series=buySignal, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=sellSignal, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)