该策略是一个基于布林带和随机振荡器的交易策略。它利用布林带来确定市场的波动范围,并使用随机振荡器来判断市场的超买和超卖状态。当价格突破布林带上轨时,策略进行做多;当价格跌破布林带下轨时,策略进行做空。同时,该策略还使用了随机振荡器来过滤交易信号,以提高策略的准确性和可靠性。
该策略的核心是布林带和随机振荡器两个技术指标。布林带由三条线组成:中轨、上轨和下轨。中轨是价格的简单移动平均线,上轨和下轨分别是中轨加上和减去价格标准差的某个倍数。当价格突破上轨时,表明市场可能处于超买状态;当价格跌破下轨时,表明市场可能处于超卖状态。
随机振荡器由两条线组成:%K线和%D线。%K线衡量了收盘价在最近一段时间内的最高价和最低价之间的位置,%D线是%K线的移动平均线。当%K线上穿%D线时,表明市场可能处于超买状态;当%K线下穿%D线时,表明市场可能处于超卖状态。
该策略结合了这两个指标,当价格突破布林带上轨且随机振荡器%K线上穿%D线时,策略进行做多;当价格跌破布林带下轨且随机振荡器%K线下穿%D线时,策略进行做空。这种组合可以有效地捕捉市场的趋势,同时也能够避免在波动市场中频繁交易。
该策略是一个简单而有效的交易策略,通过结合布林带和随机振荡器两个经典的技术指标,能够在趋势和震荡两种市场状态下获得稳定的收益。尽管该策略也存在一些风险和局限性,但通过适当的优化和改进,可以进一步提高策略的性能和适应性,成为一个值得参考和学习的交易策略。
/*backtest start: 2023-05-03 00:00:00 end: 2024-05-08 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Unique Bollinger Bands Strategy", overlay=true) src = input(close) length = input.int(34, minval=1) mult = input.float(2.0, minval=0.001, maxval=50) basis = ta.sma(src, length) dev = ta.stdev(src, length) dev2 = mult * dev upper1 = basis + dev lower1 = basis - dev upper2 = basis + dev2 lower2 = basis - dev2 colorBasis = src >= basis ? color.blue : color.orange pBasis = plot(basis, linewidth=2, color=colorBasis) pUpper1 = plot(upper1, color=color.new(color.blue, 0), style=plot.style_circles) pUpper2 = plot(upper2, color=color.new(color.blue, 0)) pLower1 = plot(lower1, color=color.new(color.orange, 0), style=plot.style_circles) pLower2 = plot(lower2, color=color.new(color.orange, 0)) fill(pBasis, pUpper2, color=color.new(color.blue, 80)) fill(pUpper1, pUpper2, color=color.new(color.blue, 80)) fill(pBasis, pLower2, color=color.new(color.orange, 80)) fill(pLower1, pLower2, color=color.new(color.orange, 80)) // Parameters bbLength = input.int(34, title="Length", minval=1) bbMultiplier = input.float(2.0, title="Multiplier", minval=0.001, maxval=50) // Source priceData = close // Unique name for price data source // Bollinger Bands Calculation bbBasis = ta.sma(priceData, bbLength) bbDeviation = ta.stdev(priceData, bbLength) bbDeviationMultiplied = bbMultiplier * bbDeviation bbUpperBand = bbBasis + bbDeviationMultiplied bbLowerBand = bbBasis - bbDeviationMultiplied // Plot Bollinger Bands plot(bbBasis, color=color.blue, linewidth=2) plot(bbUpperBand, color=color.blue) plot(bbLowerBand, color=color.orange) // Strategy Logic for Entry and Exit enterLong = ta.crossover(priceData, bbUpperBand) enterShort = ta.crossunder(priceData, bbLowerBand) // Enter Long when price crosses over upper band if (enterLong) strategy.entry("Long", strategy.long) // Enter Short when price crosses under lower band if (enterShort) strategy.entry("Short", strategy.short) // Close Long when Short condition is met (i.e., price under lower band) if (enterShort) strategy.close("Long") // Close Short when Long condition is met (i.e., price over upper band) if (enterLong) strategy.close("Short")