Chiến lược đảo ngược xu hướng Bollinger Bands

Tác giả:ChaoZhang, Ngày: 2023-11-01 11:29:34
Tags:

img

Tổng quan

Chiến lược này sử dụng Bollinger Bands và Moving Average để đi LONG hoặc SHORT khi giá tiếp cận các dải trên hoặc dưới. Nó đi ngắn khi giá phá vỡ trên dải trên và đi dài khi giá phá vỡ dưới dải dưới. Chiến lược kết hợp các lợi thế của cả hai chiến lược theo xu hướng và đảo ngược trung bình, và hoạt động tốt trong các thị trường giới hạn phạm vi.

Lý luận

Chiến lược xác định hai tín hiệu nhập cảnh:

  1. Tín hiệu dài: khi giá đóng chạm vào dải dưới trong khi trên đường EMA, nến trước đó là giảm và nến hiện tại là tăng.

  2. Tín hiệu ngắn: khi giá đóng chạm vào dải trên trong khi dưới đường EMA, nến trước đó tăng và nến hiện tại giảm.

Stop loss sử dụng stop loss cố định. Mức stop loss được thiết lập ở mức giá đầu vào cộng với tỷ lệ rủi ro / phần thưởng giảm nhân khoảng cách giữa giá đầu vào và mức lợi nhuận.

Lợi nhuận lấy sử dụng lợi nhuận lấy động. Lợi nhuận lấy dài được đặt ở dải dưới. Lợi nhuận lấy ngắn được đặt ở dải trên.

Ưu điểm

  1. Kết hợp các điểm mạnh của cả hai chiến lược theo xu hướng và đảo ngược trung bình, hoạt động tốt trong các thị trường giới hạn phạm vi.

  2. Sử dụng Bollinger Bands để xác định mức mua quá mức và bán quá mức, cải thiện độ chính xác của tín hiệu đảo ngược.

  3. Stop loss cố định giúp quản lý rủi ro dễ dàng hơn.

  4. Lợi nhuận động cho phép tối đa hóa lợi nhuận.

Rủi ro

  1. Chiến lược thoát hiểm có thể ngăn chặn các cuộc chạy.

  2. Stop loss thường xuyên được kích hoạt khi thị trường quá hỗn loạn.

  3. Stop loss cố định không thích nghi với biến động thị trường. Có thể quá rộng hoặc quá chật.

  4. Điều chỉnh tham số kém của Bollinger Bands có thể dẫn đến kết quả tầm thường.

Tăng cường

  1. Kết hợp chỉ số RSI để lọc các tín hiệu đầu vào. Ví dụ, chỉ mua dài nếu RSI trên 50, và chỉ mua ngắn nếu RSI dưới 50.

  2. Thực hiện stop loss thích nghi điều chỉnh khoảng cách dừng dựa trên biến động. ví dụ: sử dụng ATR để thiết lập stop loss động.

  3. Tối ưu hóa các thông số Bollinger Bands để tìm kết hợp thông số tốt nhất.

  4. Kiểm tra các khoảng thời gian EMA khác nhau để tăng cường hiệu ứng hỗ trợ/kháng cự của EMA.

Tóm lại

Chiến lược này kết hợp xu hướng và đảo ngược, đi vào mức mua quá mức / bán quá mức được xác định bởi Bollinger Bands. Nó tối đa hóa lợi nhuận thông qua lợi nhuận tích cực. Hoạt động tốt trong các thị trường giới hạn phạm vi. Cẩn thận với các hoạt động dừng. Điều chỉnh các tham số để tối ưu hóa hiệu suất. Nhìn chung là một chiến lược thực tế và hiệu quả.


/*backtest
start: 2023-10-24 00:00:00
end: 2023-10-31 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

// Welcome to yet another script. This script was a lot easier since I was stuck for so long on the Donchian Channels one and learned so much from that one that I could use in this one
// This code should be a lot cleaner compared to the Donchian Channels, but we'll leave that up to the pro's
// This strategy has two entry signals, long = when price hits lower band, while above EMA, previous candle was bearish and current candle is bullish
// Short = when price hits upper band, while below EMA, previous candle was bullish and current candle is bearish
// Take profits are the opposite side's band(lower band for long signals, upper band for short signals). This means our take profit price will change per bar
// Our stop loss doesn't change, it's the difference between entry price and the take profit target divided by the input risk reward
// At the time of writing this, I could probably calculate that much easier by simply multiplying the opposite band by the input risk reward ratio
// Since I want to get this script out and working on the next one, I won't clean that up, I'm sorry
// strategy(shorttitle="BB Trending Reverse Strategy", title="Bollinger Bands Trending Reverse Strategy", overlay=true, default_qty_type = strategy.cash, default_qty_value = 150, initial_capital = 1000, currency = currency.USD, commission_type = "percent", commission_value = 0.036)

// The built-in Bollinger Band indicator inputs and variables, added some inputs of my own and organised the code
length              = input(20, minval=1)
src                 = input(close, title="Source")
mult                = input(2.0, minval=0.001, maxval=50, title="StdDev")
emaInput            = input(title = "EMA Input", type = input.integer, defval = 200, minval = 10, maxval = 400, step = 1)
riskreward          = input(title = "Risk/Reward Ratio", type = input.float, defval = 1.50, minval = 0.01, maxval = 100, step = 0.01)
offset              = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
basis               = sma(src, length)
dev                 = mult * stdev(src, length)
upper               = basis + dev
lower               = basis - dev
ema                 = ema(close, emaInput)

// These are our conditions as explained above
entryLong           = low[1] <= lower[1] and low <= lower and low > ema
entryShort          = high[1] >= upper[1] and high >= upper and high < ema
reversecandleLong   = close > open and close[1] < open[1]
reversecandleShort  = close < open and close[1] > open[1]
var stopLong        = 0.0
var stopShort       = 0.0

// These are our entry signals, notice how the stop condition is within the if statement while the strategy.exit is outside of the if statement, this way the take profit targets trails up or down depending on what the price does
if reversecandleLong and entryLong and strategy.position_size == 0
    stopLong := (((close / upper - 1) * riskreward + 1) * close)
    strategy.entry("Long Entry", strategy.long, comment = "Long Entry")
    
strategy.exit("Exit Long", "Long Entry", limit = upper, stop = stopLong, comment = "Exit Long")

if reversecandleShort and entryShort and strategy.position_size == 0
    stopShort := (((close / lower - 1) / riskreward + 1) * close)
    strategy.entry("Short Entry", strategy.short, comment = "Short Entry")

strategy.exit("Exit Short", "Short Entry", limit = lower, stop = stopShort, comment = "Exit Short")


// The built-in Bollinger Band plots
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=#198787, transp=95)
plot(ema, color=color.red)

// These plots are to check the stoplosses, they can  make a mess of your chart so only use these if you want to make sure these work
// plot(stopLong)
// plot(stopShort)

Thêm nữa