
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng kết hợp các dải Bollinger Bands và Moving Average. Nó sử dụng Bollinger để nắm bắt các đột phá biến động giá, đồng thời sử dụng moving averages để xác nhận hướng xu hướng, tạo thành một khung quyết định giao dịch hoàn chỉnh.
Chiến lược sử dụng hai chỉ số kỹ thuật cốt lõi:
Logic tạo tín hiệu giao dịch:
Đây là một chiến lược theo dõi xu hướng kết hợp sáng tạo giữa các chỉ số kỹ thuật cổ điển và đường trung bình di chuyển. Bằng cách sử dụng đường trung bình di động để xác nhận xu hướng, chiến lược có khả năng thích ứng và tùy chỉnh mạnh mẽ, nhưng trong ứng dụng thực tế cần chú ý đến phán đoán và kiểm soát rủi ro của môi trường thị trường.
/*backtest
start: 2024-02-08 00:00:00
end: 2025-02-07 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bollinger Bands + Moving Average Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// === Vstupy ===
// Moving Average
maPeriod = input.int(20, title="MA Period", minval=1)
maType = input.string("SMA", title="MA Type", options=["SMA", "EMA"])
// Bollinger Bands
bbPeriod = input.int(20, title="BB Period", minval=1)
bbMultiplier = input.float(2.0, title="BB Multiplier", step=0.1)
// === Výpočty Indikátorov ===
// Moving Average
ma = maType == "SMA" ? ta.sma(close, maPeriod) : ta.ema(close, maPeriod)
// Bollinger Bands
basis = ta.sma(close, bbPeriod)
dev = bbMultiplier * ta.stdev(close, bbPeriod)
upperBB = basis + dev
lowerBB = basis - dev
// === Podmienky Pre Vstupy ===
// Nákupný signál: Cena prekonáva dolný Bollinger Band smerom nahor a cena je nad MA
longCondition = ta.crossover(close, lowerBB) and close > ma
// Predajný signál: Cena prekonáva horný Bollinger Band smerom nadol a cena je pod MA
shortCondition = ta.crossunder(close, upperBB) and close < ma
// === Vstupné Signály ===
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// === Výstupné Podmienky ===
// Uzavretie Long pozície pri prekonaní MA smerom nadol alebo ceny pod MA
exitLongCondition = ta.crossunder(close, ma) or close < ma
if (exitLongCondition)
strategy.close("Long")
// Uzavretie Short pozície pri prekonaní MA smerom nahor alebo ceny nad MA
exitShortCondition = ta.crossover(close, ma) or close > ma
if (exitShortCondition)
strategy.close("Short")
// === Vykreslenie Indikátorov na Grafe ===
// Vykreslenie Moving Average
plot(ma, color=color.blue, title="Moving Average")
// Vykreslenie Bollinger Bands
upperPlot = plot(upperBB, color=color.red, title="Upper BB")
lowerPlot = plot(lowerBB, color=color.green, title="Lower BB")
fill(upperPlot, lowerPlot, color=color.rgb(173, 216, 230, 90), title="BB Fill")
// Vizualizácia Signálov
plotshape(series=longCondition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="Long")
plotshape(series=shortCondition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")
plotshape(series=exitLongCondition, title="Long Exit", location=location.abovebar, color=color.red, style=shape.labeldown, text="Exit Long")
plotshape(series=exitShortCondition, title="Short Exit", location=location.belowbar, color=color.green, style=shape.labelup, text="Exit Short")