该策略使用布林带作为主要指标,当收盘价突破上轨时开多仓,突破下轨时开空仓。布林带由中轨(移动平均线)、上轨(中轨+标准差)和下轨(中轨-标准差)组成。该策略试图捕捉市场趋势,在价格突破布林带上轨时买入,突破下轨时卖出,同时使用中轨作为平仓条件。
布林带突破策略通过布林带上下轨的突破来捕捉市场趋势,中轨作为平仓条件。该策略逻辑清晰,易于实现,能够有效捕捉趋势,但在参数选择和震荡市场中存在一定风险。未来可以通过引入其他指标、优化参数、加入风险管理等方式来提升策略表现。
/*backtest start: 2023-04-24 00:00:00 end: 2024-04-29 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Bollinger Bands Strategy", shorttitle='BB Strategy', overlay=true) // Bollinger Bands parameters length = input.int(20, title="Length") mult = input.float(2.0, title="Multiplier") // Calculate Bollinger Bands basis = ta.sma(close, length) dev = mult * ta.stdev(close, length) upper_band = basis + dev lower_band = basis - dev // Plot Bollinger Bands plot(basis, color=color.blue, title="Basis") plot(upper_band, color=color.red, title="Upper Band") plot(lower_band, color=color.green, title="Lower Band") // Strategy long_condition = ta.crossover(close, upper_band) short_condition = ta.crossunder(close, lower_band) if (long_condition) strategy.entry("Long", strategy.long) if (short_condition) strategy.entry("Short", strategy.short) // Exit conditions exit_long_condition = ta.crossunder(close, basis) exit_short_condition = ta.crossover(close, basis) if (exit_long_condition) strategy.close("Long") if (exit_short_condition) strategy.close("Short")