
Chiến lược này kết hợp hai chỉ số kỹ thuật quan trọng là trung bình di chuyển và khối lượng giao dịch, thiết kế các quy tắc nhập và thoát cho các vị trí dài và ngắn, tạo thành một chiến lược giao dịch định lượng hoàn chỉnh.
Điều kiện nhập cảnh của nhà đầu tư:
Điều kiện để tham gia giao dịch:
Đi qua đường trung bình di chuyển chậm
Bắt đầu từ:Làm nhiều hơn khi đáp ứng các điều kiện nhập cảnh của nhà đầu tư
Tiền đầu tư ngắn hạn:Làm trống khi đáp ứng điều kiện nhập cảnh ngắn
Hạn chế và dừng: Hiển thị điểm dừng và điểm dừng sau khi làm nhiều hơn
Phương pháp cải tiến:
Chiến lược này tích hợp các chỉ số trung bình di chuyển và các chỉ số khối lượng giao dịch, thiết kế một chiến lược giao dịch định lượng hoàn chỉnh thông qua cơ chế xác nhận kép. Có các ưu điểm về điều kiện nhập cảnh rõ ràng, có dừng lỗ và dễ dàng sử dụng. Đồng thời, cũng cần ngăn chặn các vấn đề giao dịch thường xuyên của chiến lược hai đường, chú ý đến chất lượng dữ liệu khối lượng giao dịch và ngăn chặn các tham số được tối ưu hóa quá mức.
/*backtest
start: 2023-01-25 00:00:00
end: 2024-01-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MA and Volume Strategy", overlay=true)
// Input parameters
fastLength = input(9, title="Fast MA Length")
slowLength = input(21, title="Slow MA Length")
volumePercentageThreshold = input(50, title="Volume Percentage Threshold")
// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Calculate 24-hour volume and weekly volume average
dailyVolume = request.security(syminfo.tickerid, "D", volume)
weeklyVolumeAvg = ta.sma(request.security(syminfo.tickerid, "W", volume), 7)
// Strategy conditions
longCondition = ta.crossover(fastMA, slowMA) and dailyVolume < (weeklyVolumeAvg * volumePercentageThreshold / 100)
shortCondition = ta.crossunder(fastMA, slowMA)
// Set take profit and stop loss levels
takeProfitLong = close * 1.50
stopLossLong = close * 0.90
// Strategy orders
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
// Plot moving averages
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.red, title="Slow MA")
// Plot 24-hour volume and weekly volume average
plot(dailyVolume, color=color.purple, title="24-Hour Volume", transp=0)
plot(weeklyVolumeAvg, color=color.orange, title="Weekly Volume Average")
// Plot entry signals
plotshape(series=longCondition, title="Buy Signal", color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=shortCondition, title="Sell Signal", color=color.red, style=shape.triangledown, size=size.small)
// Plot take profit and stop loss levels only when a valid trade is active
plotshape(series=longCondition, title="Take Profit Long", color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=longCondition, title="Stop Loss Long", color=color.red, style=shape.triangledown, size=size.small)