
This strategy uses the relationship between the upper band, middle band, lower band of Bollinger Bands and 200-day moving average to determine the trend direction. It goes long when price touches the lower band during an uptrend and goes short when price touches the upper band during a downtrend.
This strategy determines trend direction with Bollinger Bands first. It then utilizes the volatility range of Bollinger Bands together with moving averages to form a trading system that ensures directional correctness and locks in decent profits. There are still some issues with parameter selection and stop loss that can be further improved via optimization and mechanism additions to achieve better performance.
/*backtest
start: 2023-11-29 00:00:00
end: 2023-12-06 00:00:00
period: 1m
basePeriod: 1m
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("boll trend", overlay=true,initial_capital=1000,default_qty_type=strategy.fixed, default_qty_value=1 )
bollL=input.int(20,minval=1,title = "length")
bollmult=input.float(2.3,minval=0,step=0.1,title = "mult")
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 = "trend")
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) or ta.crossunder(close,ta.sma(close,300))
shortEXIT=ta.crossunder(low,lower) or ta.crossover(close,ta.sma(close,250))
if longT and longE
strategy.entry("多long",strategy.long)
if longEXIT
strategy.close("多long",comment = "close long")
if shortE and shortT
strategy.entry("空short",strategy.short)
if shortEXIT
strategy.close("空short",comment = "close short")