
Chiến lược này dựa trên các chỉ số Bollinger Bands, tạo ra tín hiệu giao dịch bằng cách giá phá vỡ Bollinger Bands xuống đường. Khi giá phá vỡ đường lên, hãy làm nhiều, khi phá vỡ đường xuống. Đồng thời, khi giữ nhiều đơn, nếu giá giảm xuống đường; khi giữ đơn trống, nếu giá phá vỡ đường lên thì bằng phẳng.
Chiến lược phá vỡ BB là một chiến lược giao dịch dựa trên chỉ số Brin, giao dịch bằng cách nắm bắt cơ hội giá phá vỡ Brin và đi xuống đường. Chiến lược này có lợi thế là tín hiệu rõ ràng, dễ thực hiện và có một số biện pháp kiểm soát rủi ro. Tuy nhiên, chiến lược này cũng có một số hạn chế, chẳng hạn như tần suất giao dịch có thể quá cao, tín hiệu chậm trễ.
/*backtest
start: 2023-06-08 00:00:00
end: 2024-06-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("BB Strategy", overlay=true)
// Input parameters
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval=-500, maxval=500, title="Offset")
// Moving average function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculate Bollinger Bands
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Plot Bollinger Bands
plot(basis, "Basis", color=color.blue, offset=offset)
p1 = plot(upper, "Upper", color=color.red, offset=offset)
p2 = plot(lower, "Lower", color=color.green, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))
// Strategy logic
longCondition = ta.crossover(close, upper)
shortCondition = ta.crossunder(close, lower)
// Strategy entries and exits
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (shortCondition and strategy.position_size > 0)
strategy.close("Long")
if (longCondition and strategy.position_size < 0)
strategy.close("Short")