This strategy uses the Bollinger Bands indicator to determine market trend direction, and takes counter-trend trades when trend reversal occurs. It goes long when price breaks below the lower band in an uptrend; and goes short when price breaks above the upper band in a downtrend. Also, a moving average is used as the benchmark for long-term trend to make the strategy more stable.
This strategy utilizes the middle band, upper band and lower band of Bollinger Bands to determine market trend direction. The middle band is the n-period exponential moving average, while the upper band and lower band are middle band +2.3 standard deviation and middle band -2.3 standard deviation respectively. When price breaks below the lower band, it indicates a current uptrend. When price breaks above the upper band, it indicates a current downtrend.
In addition, the strategy sets a 200-period simple moving average (sma) as the benchmark for long-term trend judgement. Trading signals are only triggered when BB and sma indicators agree on the same direction. This can effectively filter out some false breakouts.
The specific trading logic is as follows:
Improvements:
Overall this is a simple and easy to understand strategy, using BB to determine trends and taking counter-trend trades at turning points. Adding short-term and benchmark indicators also helps filter signals. Still large room for optimizations, like parameter tuning, volume indicators etc. can further improve it.
/*backtest start: 2023-10-23 00:00:00 end: 2023-11-22 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Aayonga //@version=5 strategy("布林趋势震荡单", overlay=true,initial_capital=10000,default_qty_type=strategy.fixed, default_qty_value=1 ) bollL=input.int(20,minval=1,title = "长度") bollmult=input.float(2.3,minval=0,step=0.1,title = "标准差") basis=ta.ema(close,bollL) dev=bollmult*ta.stdev(close,bollL) upper=basis+dev lower=basis-dev smaL=input.int(200,minval=1,step=1,title = "趋势分界线") sma=ta.sma(close,smaL) //多头趋势 longT=upper>sma and basis>sma and lower>=sma //空头趋势 shortT=upper<sma and basis<sma and lower<=sma //入场位 longE=ta.crossover(close,lower) shortE=ta.crossover(close,upper) //出场位 longEXIT=ta.crossover(high,upper) shortEXIT=ta.crossunder(close,basis) or ta.crossover(close,ta.sma(close,230)) if longT and longE strategy.entry("多",strategy.long) if longEXIT strategy.close("多",comment = "多出场") if shortE and shortT strategy.entry("空",strategy.short) if shortEXIT strategy.close("空",comment = "空出场")