Chiến lược Bollinger Break Out với Pyramiding

Tác giả:ChaoZhang, Ngày: 2023-11-23 14:01:57
Tags:

img

Tổng quan

Chiến lược này đi vào các vị trí dài hoặc ngắn dựa trên sự đột phá của Bollinger Bands. Nó đi dài khi giá phá vỡ dưới dải dưới và đi ngắn khi giá phá vỡ trên dải trên. Sau khi nhập vị trí, nó tiếp tục kim tự tháp và cập nhật dừng lỗ trong thời gian thực.

Chiến lược logic

Chiến lược này sử dụng 3 đường Bollinger Bands - trung bình, trên và dưới. Đường giữa là đường trung bình di chuyển n ngày. Đường trên là đường giữa + k * lệch chuẩn n ngày. Đường dưới là đường giữa - k * lệch chuẩn n ngày. Thông thường n là 20 và k là 2.

Khi giá phá vỡ trên đường trên, nó báo hiệu xu hướng giảm và đi ngắn. Khi giá phá vỡ dưới đường dưới, nó báo hiệu xu hướng tăng và đi dài.

Sau khi lấy vị trí, chiến lược tiếp tục kim tự tháp, có nghĩa là thêm nhiều vị trí theo cùng một hướng.

Giá dừng lỗ cho tất cả các vị trí cũng được cập nhật theo thời gian thực dựa trên sự khác biệt giữa giá nắm giữ trung bình hiện tại và giá dải.

Phân tích lợi thế

Những lợi thế của chiến lược này bao gồm:

  1. Sử dụng Bollinger Bands để xác định chính xác sự đột phá và thay đổi xu hướng.
  2. Nhập các vị trí trên cây thánh giá vàng và cây thánh giá chết một cách có hệ thống.
  3. Tạo thêm lợi nhuận bằng cách xây dựng kim tự tháp.
  4. Thời gian thực cập nhật stop loss để tránh bị đánh bại.

Phân tích rủi ro

Có một số rủi ro của chiến lược này:

  1. Bollinger Bands nhạy cảm với sự biến động của thị trường và có thể gặp phải sự biến động.
  2. Đánh kim tự tháp làm tăng sự phơi nhiễm và tạo ra lợi thế cho những tổn thất tiềm tàng.
  3. Stop loss không được đảm bảo và vẫn có khả năng dừng lại.

Một số phương pháp để giải quyết rủi ro:

  1. Tối ưu hóa các thông số Bollinger Bands cho các chu kỳ khác nhau.
  2. Điều chỉnh thang đo và tần số kim tự tháp.
  3. Thêm đường giữa là đường dừng lỗ tiếp theo.

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

Chiến lược có thể được tối ưu hóa từ các khía cạnh sau:

  1. Tối ưu hóa các thông số của Bollinger Bands để thích nghi với nhiều chế độ thị trường hơn.
  2. Cải thiện logic kim tự tháp để cân bằng rủi ro-lợi ích.
  3. Thêm thêm các đường dừng lỗ như đường trung tâm.
  4. Phát triển cơ chế lấy lợi nhuận để khóa lợi nhuận chủ động.
  5. Kết hợp các chỉ số khác để lọc các mục.
  6. Cải thiện quản lý rủi ro để kiểm soát lỗ cho mỗi giao dịch.

Kết luận

Kết luận, đây là một chiến lược theo xu hướng điển hình. Nó đi theo đà khi xu hướng xuất hiện và kiếm lợi nhuận phù hợp. Trong khi đó, nó cũng chứa rủi ro vốn có.


/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5

strategy(title='Bollinger Band strategy with split, limit, stop', shorttitle='bb strategy', overlay=true,commission_type = strategy.commission.percent, commission_value = 0.01, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, pyramiding = 4)



//Summary: Going Long or Short when Entering after Breaking the Bollinger Bands\
//At this time, the stop-loss, profit-taking price, and pyramiding standard\
// are determined from the difference between the position average price and the band price.

//After entering the position, if the price crosses the mid-band line, the stop loss is adjusted to the mid-band line.



//each trade, entry position size = 10% of total cash
//max pyramiding is 4
//commission = 0.01%





in_period = true


bb_length = input.int(20)
bb_mult = input.int(2)

[middle, upper, lower] = ta.bb(close,bb_length, bb_mult)
plot(middle, color=color.aqua)
plot(upper, color=color.orange)
plot(lower, color=color.orange)
long_cond = ta.crossover(close,lower)
short_cond = ta.crossunder(close,upper)

var saved_ph = 0.0
if strategy.opentrades>0 and strategy.opentrades[1]==0 and strategy.position_size > 0
    saved_ph := upper[1]
var saved_pl = 0.0
if strategy.opentrades>0 and strategy.opentrades[1]==0 and strategy.position_size < 0
    saved_pl := lower[1]

avg = strategy.position_avg_price

long_diff = saved_ph-avg
short_diff = saved_pl-avg

long_stoploss = avg - 1*long_diff
short_stoploss = avg - 1*short_diff

long_avgdown = avg - 0.5*long_diff
short_avgup = avg - 0.5*short_diff

long_profit_price = avg + 0.5*long_diff
short_profit_price = avg + 0.5*short_diff

var label _label = na
if in_period
    if long_cond and strategy.opentrades==0
        strategy.entry("Long",strategy.long)
    if long_cond and strategy.opentrades >0 and (close[1]<long_avgdown or close[2]<long_avgdown)
        strategy.entry("Long",strategy.long)

    if short_cond and strategy.opentrades==0
        strategy.entry("Short", strategy.short)
    if short_cond and strategy.opentrades>0 and (close[1]>short_avgup or close[2]>short_avgup)
        strategy.entry("Short",strategy.short)

plot(avg, style=plot.style_linebr)


plot(strategy.position_size > 0? long_profit_price: na,color=color.green, style=plot.style_linebr)
plot(strategy.position_size > 0? long_avgdown: na,color=color.yellow, style=plot.style_linebr)
plot(strategy.position_size > 0? long_stoploss: na,color=color.red, style=plot.style_linebr)

plot(strategy.position_size < 0? short_profit_price: na,color=color.green, style=plot.style_linebr)
plot(strategy.position_size < 0? short_avgup: na,color=color.yellow, style=plot.style_linebr)
plot(strategy.position_size < 0? short_stoploss: na,color=color.red, style=plot.style_linebr)

if strategy.position_size > 0
    if ta.crossover(close, middle)
        strategy.exit("Long Exit", "Long", limit=long_profit_price, stop=middle)
    else
        strategy.exit("Long Exit", "Long", limit=long_profit_price, stop=long_stoploss)
if strategy.position_size < 0
    if ta.crossunder(close, middle)
        strategy.exit("Short Exit", "Short", limit=short_profit_price, stop=middle)
    else
        strategy.exit("Short Exit", "Short", limit=short_profit_price, stop=short_stoploss)

Thêm nữa