
Chiến lược này là một hệ thống theo dõi xu hướng dựa trên chéo hai đường ngang, nắm bắt xu hướng thị trường thông qua chéo của đường trung bình di chuyển ngắn hạn và dài hạn và quản lý rủi ro giao dịch với tỷ lệ lợi nhuận rủi ro 1: 3. Chiến lược sử dụng mục tiêu dừng lỗ và lợi nhuận cố định, đồng thời kết hợp với cơ chế dừng lỗ di động để bảo vệ lợi nhuận.
Chiến lược sử dụng trung bình di chuyển ngắn hạn 74 chu kỳ (SMA ngắn) và trung bình di chuyển dài hạn 70 chu kỳ (SMA dài hạn) làm chỉ số chính. Hệ thống tạo ra nhiều tín hiệu khi trung bình ngắn hạn đi lên vượt qua trung bình dài hạn; hệ thống tạo ra tín hiệu dừng khi trung bình ngắn hạn đi xuống vượt qua trung bình dài hạn.
Đây là một chiến lược theo dõi xu hướng có cấu trúc, logic rõ ràng. Bằng cách nắm bắt xu hướng ngang qua đường thẳng, sử dụng quản lý rủi ro và kiểm soát vị trí nghiêm ngặt, phù hợp cho giao dịch trung và dài hạn. Mặc dù có những sai sót vốn có, chẳng hạn như trễ đường thẳng, nhưng bằng hướng tối ưu hóa được đề xuất, đặc biệt là đưa ra điều chỉnh tham số động và lọc môi trường thị trường, sự ổn định và lợi nhuận của chiến lược có thể được nâng cao hơn nữa.
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-17 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bitcoin Strategy by Jag", overlay=true)
// Input Parameters
shortSMALength = input.int(74, title="Short SMA Length")
longSMALength = input.int(70, title="Long SMA Length")
trailStopOffset = input.float(353, title="Trailing Stop Offset (USD)") // Trailing Stop Loss Offset in USD
tradeSize = input.float(1, title="Trade Size")
// Automatically set Take Profit as 3 times Stop Loss
fixedTakeProfit = trailStopOffset * 3
// Backtesting Date Range
startDate = timestamp(2025, 02,13, 0, 0)
endDate = timestamp(2025, 03, 31, 23, 59)
withinDateRange = true
// Indicators
shortSMA = ta.sma(close, shortSMALength)
longSMA = ta.sma(close, longSMALength)
// Crossover Conditions
longCondition = withinDateRange and ta.crossover(shortSMA, longSMA)
shortCondition = withinDateRange and ta.crossunder(shortSMA, longSMA)
// Entry Logic
if (strategy.position_size == 0) // Only allow new trades if no position is open
if (longCondition)
strategy.entry("Long", strategy.long, tradeSize)
if (shortCondition)
strategy.entry("Short", strategy.short, tradeSize)
// Exit Logic for Long Position
if (strategy.position_size > 0)
strategy.exit("Long exit", "Long", stop=strategy.position_avg_price - trailStopOffset, limit=strategy.position_avg_price + fixedTakeProfit) // Using stop and limit
// Exit Logic for Short Position
if (strategy.position_size < 0)
strategy.exit("Short Exit", "Short", stop=strategy.position_avg_price + trailStopOffset, limit=strategy.position_avg_price - fixedTakeProfit) // Using stop and limit
// Plot Moving Averages
plot(shortSMA, color=color.blue, title="Short SMA")
plot(longSMA, color=color.black, title="Long SMA")
// Visual Signals
plotshape(series=longCondition and strategy.position_size == 0, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=shortCondition and strategy.position_size == 0, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)