
Chiến lược này giao dịch dựa trên mối quan hệ chéo giữa chỉ số VWAP (giá trị trung bình khối lượng giao dịch) và giá. Khi giá vượt qua VWAP lên, mở nhiều vị trí, và khi nó vượt qua VWAP xuống, mở trống. Đồng thời, sử dụng chỉ số ATR (trung bình độ biến động thực tế) để tính toán mức dừng và dừng động để kiểm soát rủi ro và khóa lợi nhuận.
Chiến lược này dựa trên VWAP, tạo ra tín hiệu giao dịch bằng cách giao chéo với giá cả, đồng thời kết hợp với ATR để thực hiện dừng lỗ động, kiểm soát rủi ro rút lui trong khi nắm bắt xu hướng, tư duy tổng thể đơn giản và dễ hiểu. Tuy nhiên, chiến lược còn có không gian tối ưu hóa hơn nữa, có thể thích ứng tốt hơn với môi trường thị trường thay đổi bằng cách giới thiệu các chỉ số phụ trợ, tối ưu hóa logic dừng lỗ và quản lý vốn.
/*backtest
start: 2023-03-26 00:00:00
end: 2024-03-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Hannah Strategy Stop Loss and Take Profit", overlay=true)
// Inputs
cumulativePeriod = input(40, "VWAP Period")
atrPeriod = input(14, "ATR Period")
multiplier = input(1.5, "ATR Multiplier for Stop Loss")
targetMultiplier = input(3, "ATR Multiplier for Take Profit")
// Calculations for VWAP
typicalPrice = (high + low + close) / 3
typicalPriceVolume = typicalPrice * volume
cumulativeTypicalPriceVolume = sum(typicalPriceVolume, cumulativePeriod)
cumulativeVolume = sum(volume, cumulativePeriod)
vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume
// Plot VWAP on the chart
plot(vwapValue, color=color.blue, title="VWAP")
// Entry Conditions based on price crossing over/under VWAP
longCondition = crossover(close, vwapValue)
shortCondition = crossunder(close, vwapValue)
// ATR Calculation for setting dynamic stop loss and take profit
atr = atr(atrPeriod)
// Execute Trades with Dynamic Stop Loss and Take Profit based on ATR
if (longCondition)
strategy.entry("Long", strategy.long)
// Setting stop loss and take profit for long positions
strategy.exit("Long Exit", "Long", stop=close - atr * multiplier, limit=close + atr * targetMultiplier)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Setting stop loss and take profit for short positions
strategy.exit("Short Exit", "Short", stop=close + atr * multiplier, limit=close - atr * targetMultiplier)