
Chiến lược này sử dụng VWAP của đường mặt trời (giá trung bình trọng lượng giao dịch) làm tín hiệu để vào và ra khỏi. Khi giá đóng cửa vượt qua VWAP, kích hoạt nhiều hơn, dừng lỗ được đặt ở mức thấp K trước của VWAP, giá mục tiêu được đặt ở mức 3 điểm trên giá mở; khi giá đóng cửa vượt qua VWAP, kích hoạt trống, dừng lỗ được đặt ở mức cao K trước của VWAP, giá mục tiêu được đặt ở mức 3 điểm dưới giá mở.
Xác định xu hướng thông qua dữ liệu VWAP xuyên chu kỳ, đồng thời sử dụng các điểm dừng động và điểm dừng cố định, có thể nắm bắt hiệu quả tình hình xu hướng, kiểm soát rủi ro rút lui và khóa lợi nhuận kịp thời.
Chiến lược này sử dụng dữ liệu VWAP xuyên chu kỳ để phán đoán xu hướng và kích hoạt tín hiệu, đồng thời kiểm soát rủi ro và khóa lợi nhuận bằng cách sử dụng dừng động và dừng số điểm cố định. Đây là một chiến lược giao dịch định lượng đơn giản và hiệu quả.
/*backtest
start: 2024-03-06 00:00:00
end: 2024-03-07 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy('Pine Script Tutorial Example Strategy 1', overlay=true, initial_capital=1000, default_qty_value=100, default_qty_type=strategy.percent_of_equity)
// fastEMA = ta.ema(close, 24)
// slowEMA = ta.ema(close, 200)
// Higher Time Frame
float sl = na
float tgt = na
posSize = 1
vwap_1d = request.security(syminfo.tickerid, "1D", ta.vwap(close))
// plot(vwap_1d)
// To avoid differences on historical and realtime bars, you can use this technique, which only returns a value from the higher timeframe on the bar after it completes:
// indexHighTF = barstate.isrealtime ? 1 : 0
// indexCurrTF = barstate.isrealtime ? 0 : 1
// nonRepaintingVWAP = request.security(syminfo.tickerid, "1D", close[indexHighTF])[indexCurrTF]
// plot(nonRepaintingVWAP, "Non-repainting VWAP")
enterLong = ta.crossover(close, vwap_1d)
exitLong = ta.crossunder(close, vwap_1d)
enterShort = ta.crossunder(close, vwap_1d)
exitShort = ta.crossover(close, vwap_1d)
if enterLong
sl := low[1]>vwap_1d ?low[1]:vwap_1d
tgt:=close+3
strategy.entry("EL", strategy.long, qty=posSize)
strategy.exit('exitEL', 'EL', stop=sl, limit=tgt)
if enterShort
sl := high[1]<vwap_1d ?high[1]:vwap_1d
tgt := close-3
strategy.entry("ES", strategy.short, qty=posSize)
strategy.exit('exitES', 'ES', stop=sl, limit=tgt)
// if exitLong
// strategy.close("EL")
// if exitShort
// strategy.close("ES")
// goLongCondition1 = ta.crossover(close, vwap_1d)
// timePeriod = time >= timestamp(syminfo.timezone, 2021, 01, 01, 0, 0)
// notInTrade = strategy.position_size <= 0
// if goLongCondition1 and timePeriod and notInTrade
// stopLoss = low[1]
// takeProfit = close+3
// strategy.entry('long', strategy.long)
// strategy.exit('exit', 'long', stop=stopLoss, limit=takeProfit)
plot(close, color=color.new(#00c510, 0))
plot(vwap_1d, color=color.new(#f05619, 0))
plot(sl, color=color.new(#fbff00, 0))
plot(tgt, color=color.new(#00e1ff, 0))