该策略结合了布林带和移动平均线两个技术指标,通过布林带和价格的相对位置以及快慢移动平均线的交叉信号来判断市场趋势,从而实现择时买卖。当价格突破布林带下轨时开仓做多,突破上轨时开仓做空;同时,当快速移动平均线上穿慢速移动平均线时开仓做多,下穿时平仓。该策略能够帮助投资者把握市场趋势,实现稳健的投资收益。
布林带交叉移动平均策略是一个经典的趋势跟踪策略,通过布林带判断超买超卖,利用均线交叉判断趋势,能够有效把握市场趋势,实现稳健收益。但在实际运用中需要注意控制回撤,优化参数,并结合其他方法不断改进,以适应多变的市场环境。
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(shorttitle="BB Strategy", title="Bollinger Bands Strategy", overlay=true)
// Input parameters
length = input.int(20, minval=1)
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)
// 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 entry and exit conditions
if (ta.crossover(close, lower))
strategy.entry("Buy", strategy.long)
if (ta.crossunder(close, upper))
strategy.entry("Sell", strategy.short)