该策略基于布林带(Bollinger Bands)指标,通过价格突破布林带上下轨的方式产生交易信号。当价格突破上轨时做多,突破下轨时做空。同时,当持有多单时,如果价格跌破下轨则平多;持有空单时,如果价格突破上轨则平空。该策略旨在捕捉市场的波动性,在价格波动加剧时及时入场交易,并在价格反转时及时止损。
BB均线突破策略是一个基于布林带指标的交易策略,通过捕捉价格突破布林带上下轨的机会进行交易。该策略优点是信号明确,易于实现,同时具有一定的风险控制措施。但是该策略也存在一些局限性,如交易频率可能过高,信号滞后等问题。因此在实际应用中,可以考虑从信号确认、止损优化、参数优化等方面对策略进行改进,以提高策略的稳定性和盈利能力。
/*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")