
Đây là một chiến lược giao dịch dựa trên các chỉ số Bollinger Bands để xác định xu hướng thị trường và tạo ra tín hiệu giao dịch thông qua mối quan hệ chéo giữa giá và Bollinger Bands. Chiến lược này sử dụng đường trung bình di chuyển 55 chu kỳ làm đường trung tâm của Bollinger Bands và tính toán dựa trên chênh lệch chuẩn gấp 1.0 lần đường trên và đường dưới của Bollinger Bands.
Các hoạt động chính của chiến lược bao gồm các phần quan trọng sau:
Đây là một chiến lược theo dõi xu hướng cổ điển dựa trên Brin Belt, để nắm bắt xu hướng thị trường thông qua sự liên kết chéo giữa giá và Brin Belt. Thiết kế chiến lược được thiết kế đơn giản và rõ ràng, có hiệu quả hiển thị tốt và cơ chế tạo tín hiệu. Mặc dù có thể gặp thách thức trong thị trường bất ổn, nhưng sự ổn định và độ tin cậy của chiến lược có thể được nâng cao hơn nữa bằng cách tối ưu hóa tham số thích hợp và thêm các chỉ số hỗ trợ.
/*backtest
start: 2024-02-19 00:00:00
end: 2025-02-16 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bollinger Bands Filter [Strategy]", overlay=true)
// -- INPUTS (kratke tooltipy, ziadne prelomenie riadku)
src = input.source(close, title="Source", tooltip="Source for BB calc")
length = input.int(55, minval=1, title="SMA length", tooltip="Period for BB basis")
mult = input.float(1.0, minval=0.1, maxval=5, title="Std Dev", tooltip="Std Dev multiplier")
CC = input.bool(true, "Color Bars", tooltip="If true, color bars by BB logic")
// -- Bollinger calc
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// -- Long/Short logic
longCondition = close > upper
shortCondition = close < lower
L1 = ta.barssince(longCondition)
S1 = ta.barssince(shortCondition)
longSignal = L1 < S1 and not (L1 < S1)[1]
shortSignal = S1 < L1 and not (S1 < L1)[1]
// -- Plot signals
plotshape(shortSignal ? close : na, color=color.red, style=shape.triangledown, size=size.small, location=location.abovebar, title="Short Signal")
plotshape(longSignal ? close : na, color=color.green, style=shape.triangleup, size=size.small, location=location.belowbar, title="Long Signal")
// -- Plot BB lines
plot(upper, color=color.new(color.red, 40), title="Upper BB")
plot(lower, color=color.new(color.green,40), title="Lower BB")
plot(basis, color=color.new(color.blue, 10), title="Basis")
// -- Fill
fill(plot(na), plot(na)) // 'dummy' fill reset
fill(plot(upper, display=display.none), plot(basis, display=display.none), color=color.new(color.teal, 80))
fill(plot(lower, display=display.none), plot(basis, display=display.none), color=color.new(color.orange, 80))
// -- barcolor
bcol = close > upper ? color.lime : close < lower ? color.red : na
barcolor(CC ? bcol : na)
// -- Alerts
alertcondition(longSignal, title="Long - BB", message="BB Filter Long")
alertcondition(shortSignal, title="Short - BB", message="BB Filter Short")
// -- Strategy entries
if longSignal
strategy.entry("Long", strategy.long)
if shortSignal
strategy.entry("Short", strategy.short)