该策略基于布林带指标和移动平均线,判断价格是否接近布林带上下轨时进行LONG或SHORT平仓,从而获利。当价格突破布林带上轨时看空;当价格跌破布林带下轨时看多。它结合了趋势反转和突破两种交易策略的优点,可以在趋势震荡时获得较好收益。
该策略主要判断以下两个入场信号:
多头信号:当收盘价触及下轨,且收盘价高于EMA均线,前K线实体为阴线,当前K线实体为阳线时做多。
空头信号:当收盘价触及上轨,且收盘价低于EMA均线,前K线实体为阳线,当前K线实体为阴线时做空。
止损方式:固定止损。止损点为入场价格到对手方轨距的风险回报系数倍。
止盈方式:目标盈利为对手方轨。也就是做多止盈为下轨,做空止盈为上轨。
结合趋势和反转策略的优点,在趋势震荡行情中表现较好。
利用布林带指标判断超买超卖区域,精确判断反转机会。
固定止损点设定合理,有助于风险控制。
移动止盈方式让利润能最大化。
突破型策略容易被套利,需警惕假突破。
行情过于震荡时,止损可能会频繁被触发。
固定止损无法根据市场波动调整,可能过于宽松或过于激进。
布林带参数设置不当时,效果可能会差强人意。
可以考虑結合RSI指标過濾入場信號,例如RSI高於50再做多,RSI低於50再做空,可避免錯誤訊號。
增加自动调整固定止损距离的功能,使止损更具弹性。例如根据ATR指标动态设置止损距离。
优化布林带参数,寻找最佳参数组合。
可以测试不同EMA均线参数,优化均线的护城河效应。
该策略综合考虑趋势和反转,利用布林带判定超买超卖点位入场,通过移动止盈让利润最大化。在趋势震荡行情中表现较好。但需要注意防范被套现象,同时要调整参数优化策略效果。整体来说是一个比较实用的高效策略。
/*backtest start: 2023-10-24 00:00:00 end: 2023-10-31 00:00:00 period: 10m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 // Welcome to yet another script. This script was a lot easier since I was stuck for so long on the Donchian Channels one and learned so much from that one that I could use in this one // This code should be a lot cleaner compared to the Donchian Channels, but we'll leave that up to the pro's // This strategy has two entry signals, long = when price hits lower band, while above EMA, previous candle was bearish and current candle is bullish // Short = when price hits upper band, while below EMA, previous candle was bullish and current candle is bearish // Take profits are the opposite side's band(lower band for long signals, upper band for short signals). This means our take profit price will change per bar // Our stop loss doesn't change, it's the difference between entry price and the take profit target divided by the input risk reward // At the time of writing this, I could probably calculate that much easier by simply multiplying the opposite band by the input risk reward ratio // Since I want to get this script out and working on the next one, I won't clean that up, I'm sorry // strategy(shorttitle="BB Trending Reverse Strategy", title="Bollinger Bands Trending Reverse Strategy", overlay=true, default_qty_type = strategy.cash, default_qty_value = 150, initial_capital = 1000, currency = currency.USD, commission_type = "percent", commission_value = 0.036) // The built-in Bollinger Band indicator inputs and variables, added some inputs of my own and organised the code length = input(20, minval=1) src = input(close, title="Source") mult = input(2.0, minval=0.001, maxval=50, title="StdDev") emaInput = input(title = "EMA Input", type = input.integer, defval = 200, minval = 10, maxval = 400, step = 1) riskreward = input(title = "Risk/Reward Ratio", type = input.float, defval = 1.50, minval = 0.01, maxval = 100, step = 0.01) offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500) basis = sma(src, length) dev = mult * stdev(src, length) upper = basis + dev lower = basis - dev ema = ema(close, emaInput) // These are our conditions as explained above entryLong = low[1] <= lower[1] and low <= lower and low > ema entryShort = high[1] >= upper[1] and high >= upper and high < ema reversecandleLong = close > open and close[1] < open[1] reversecandleShort = close < open and close[1] > open[1] var stopLong = 0.0 var stopShort = 0.0 // These are our entry signals, notice how the stop condition is within the if statement while the strategy.exit is outside of the if statement, this way the take profit targets trails up or down depending on what the price does if reversecandleLong and entryLong and strategy.position_size == 0 stopLong := (((close / upper - 1) * riskreward + 1) * close) strategy.entry("Long Entry", strategy.long, comment = "Long Entry") strategy.exit("Exit Long", "Long Entry", limit = upper, stop = stopLong, comment = "Exit Long") if reversecandleShort and entryShort and strategy.position_size == 0 stopShort := (((close / lower - 1) / riskreward + 1) * close) strategy.entry("Short Entry", strategy.short, comment = "Short Entry") strategy.exit("Exit Short", "Short Entry", limit = lower, stop = stopShort, comment = "Exit Short") // The built-in Bollinger Band plots plot(basis, "Basis", color=#872323, offset = offset) p1 = plot(upper, "Upper", color=color.teal, offset = offset) p2 = plot(lower, "Lower", color=color.teal, offset = offset) fill(p1, p2, title = "Background", color=#198787, transp=95) plot(ema, color=color.red) // These plots are to check the stoplosses, they can make a mess of your chart so only use these if you want to make sure these work // plot(stopLong) // plot(stopShort)