
Chiến lược này là một chiến lược theo dõi xu hướng dựa trên các đợt phá vỡ lịch sử mới và lọc đường trung bình của đường trăng. Nó tìm kiếm tín hiệu mua bằng cách theo dõi liệu giá có phá vỡ các điểm cao lịch sử trước đó hay không, đồng thời sử dụng đường trăng 8 chu kỳ trung bình di chuyển đơn giản ((8 SMA) làm điều kiện lọc bán để giảm nguy cơ phá vỡ giả.
Chiến lược này bao gồm hai phần quan trọng:
Đây là một chiến lược theo dõi xu hướng được thiết kế hợp lý, logic rõ ràng. Bằng cách sử dụng kết hợp của các đột phá cao mới và đường trung bình của đường trăng, nó đảm bảo nắm bắt hiệu quả xu hướng và kiểm soát rủi ro một cách hợp lý. Mặc dù có một số rủi ro về sự chậm trễ và đột phá giả, nhưng với hướng tối ưu hóa được đề xuất, hiệu suất tổng thể của chiến lược có thể được nâng cao hơn nữa.
/*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)