Chiến lược Bollinger Band Breakout dựa trên VWAP

Tác giả:ChaoZhang, Ngày: 2024-02-06 14:36:26
Tags:

img

Tổng quan

Chiến lược này sử dụng Bollinger Bands để theo dõi VWAP. Nó áp dụng một vị trí dài khi VWAP phá vỡ trên dải giữa, và đóng vị trí khi VWAP phá vỡ dưới dải dưới. Điểm trục cũng được sử dụng như một tín hiệu phụ trợ để vào, để tránh phá vỡ sai.

Chiến lược logic

  1. Tính toán VWAP.
  2. Đánh giá các chỉ số Bollinger Bands của VWAP, bao gồm các chỉ số trên, giữa và dưới.
  3. Lấy vị trí dài khi VWAP phá vỡ trên dải giữa và giá trên Pivot Point.
  4. Đặt stop loss ở mức 5%.
  5. Nếu VWAP phá vỡ dưới dải dưới, đóng vị trí dài. Nếu dừng lỗ được kích hoạt, cũng thoát.

Phân tích lợi thế

  1. VWAP có khả năng theo dõi xu hướng mạnh mẽ. Với BB, nó xác định chính xác sự khởi đầu của xu hướng.
  2. Thêm Pivot Point lọc ra các sự đột phá sai, tránh mất mát không cần thiết.
  3. Khóa thoát một phần trong một số lợi nhuận và kiểm soát rủi ro.
  4. Các thử nghiệm ngược lại cho thấy hiệu suất tốt trong thị trường tăng với sự ổn định tốt.

Phân tích rủi ro

  1. Có xu hướng thua lỗ từ các vụ phá vỡ sai trong thị trường giới hạn phạm vi.
  2. Điểm trục không thể tránh hoàn toàn tín hiệu sai cần thêm bộ lọc.
  3. Tăng tần suất giao dịch dẫn đến chi phí giao dịch cao hơn.
  4. Không hoạt động tốt trong thị trường giảm giá.

Hướng dẫn tối ưu hóa

  1. Thêm các chỉ số như MACD, KDJ để lọc tín hiệu.
  2. Tối ưu hóa các thông số BB thông qua backtests.
  3. Sử dụng máy học để tối ưu hóa các thông số BB.
  4. Kiểm tra các mức dừng lỗ khác nhau để tìm ra tối ưu.
  5. Thêm lợi nhuận thích nghi dựa trên biến động thị trường.

Kết luận

Một hệ thống breakout ổn định phù hợp với giao dịch thuật toán. Cần chú ý đến kiểm soát rủi ro. Với nghiên cứu và tối ưu hóa thêm, nó có thể trở thành một chiến lược breakout tuyệt vời.


/*backtest
start: 2024-01-06 00:00:00
end: 2024-02-05 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ediks123

//@version=4
strategy("BBofVWAP with entry at Pivot Point", overlay=false, pyramiding=1,   default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,

// Function outputs 1 when it's the first bar of the D/W/M/Y
is_newbar(res) =>
    ch = 0
    if(res == 'Y')
        t  = year(time('D'))
        ch := change(t) != 0 ? 1 : 0
    else
        t = time(res)
        ch := change(t) != 0 ? 1 : 0
    ch


//variables BEGIN
//smaLength=input(200,title="Slow MA Length")

bbLength=input(50,title="BB Length")  
//bbsrc = input(close, title="BB Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)

pp_period = input(title = "Pivot Period", type=input.string, defval="Week", options = ['Day', 'Week'])

pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' 

riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(5,title="Stop Loss",minval=1)



//sma200=sma(close,smaLength)
//plot(sma200, title="SMA 200", color=color.orange)

myVwap=vwap(hlc3)

//bollinger calculation
basis = sma(myVwap, bbLength)
dev = mult * stdev(myVwap, bbLength)
upperBand = basis + dev
lowerBand = basis - dev

//plot bb
plot(basis, "Basis", color=color.teal, style=plot.style_circles , offset = offset)
p1 = plot(upperBand, "Upper", color=color.teal, offset = offset)
p2 = plot(lowerBand, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=color.teal, transp=95)

plot(myVwap, title="VWAP", color=color.purple)


//pivot points 


// Calc High
high_cur = 0.0
high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)

phigh = 0.0
phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]

// Calc Low
low_cur = 0.0
low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)

plow = 0.0
plow := is_newbar(pp_res) ? low_cur[1] : plow[1]

// Calc Close
pclose = 0.0
pclose := is_newbar(pp_res) ? close[1] : pclose[1]


vPP = (phigh + plow + pclose) / 3

//pivot points


//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  

//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1


strategy.entry(id="BB_VWAP_PP",long=true, qty=qty1, when=   crossover(myVwap,basis)  and close>=vPP  )

bgcolor(strategy.position_size>=1?color.blue:na, transp=75)
barcolor(strategy.position_size>=1?color.green:na)

stopLossVal=  strategy.position_size>=1 ?  close * (1 - (stopLoss*0.01) ) : 0.00

//partial exit
//strategy.close(id="BBofVwap", qty=strategy.position_size/3, when=crossunder(myVwap,upperBand) and strategy.position_size>=1 )  //and close>strategy.position_avg_price)



//exit on lowerband or stoploss 
strategy.close(id="BB_VWAP_PP", comment="P" , qty=strategy.position_size/3, when= crossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_price)  //
strategy.close(id="BB_VWAP_PP", comment="Exit All", when=crossunder(myVwap,lowerBand) and strategy.position_size>=1 )
//strategy.close(id="BBofVwapWithFibPivot", comment="Exit All", when=crossunder(close,vPP) and strategy.position_size>=1 )

strategy.close(id="BB_VWAP_PP", comment="Stop Loss Exit", when=crossunder(close,stopLossVal) and strategy.position_size>=1 )

Thêm nữa