Trend Following Strategy Based on Bollinger Bands

Author: ChaoZhang, Date: 2024-02-22 17:21:42



This strategy is a trend following strategy based on the Bollinger Bands indicator. It utilizes the upper and lower bands of Bollinger Bands to determine trend direction and implement trend tracking. It goes long when price breaks through the upper band and goes short when price breaks through the lower band. The stop loss is set at the middle band of Bollinger Bands.

Strategy Logic

This strategy uses the Bollinger Bands indicator to determine price trend. Bollinger Bands contain three lines - upper band, lower band and middle band. The upper band represents the upside limit of price, the lower band represents the downside limit of price, and the middle band represents the moving average line of price. When price breaks through upper band from lower band, it signals an upward trend start. When price breaks through lower band from upper band, it signals a downward trend start.

Specifically, the long entry conditions of this strategy are: 1) the close price of the current candle is higher than the upper band; 2) the close price of the previous candle is lower than the upper band. This signals that price has broken through and the uptrend begins, so going long is appropriate. The short entry conditions are similar: current candle’s close price is below lower band and previous candle’s close price is above lower band, indicating that going short is ready.

The stop loss mechanism of this strategy sets the stop loss level on the middle band, for both long and short positions. Because the middle band represents the moving average line of price, it is a key level to judge the change in trend.

Strategy Strengths

The greatest strength of this strategy is its ability to identify price trends clearly, using features of Bollinger Bands indicator to track trends, avoiding misguidance by market swings. Compared with other indicators, Bollinger Bands are more reliable for breakout judging, reducing false breakouts.

In addition, this strategy sets entry rules for both long and short sides, enabling two-way trading to maximize capturing price fluctuations. Adopting the middle band as stop loss level can improve loss cut accuracy. Timely stop loss is crucial for strategy profitability.

Strategy Risks

The main risk of this strategy lies in Bollinger Bands parameter configuration. The moving average period and standard deviation size of Bollinger Bands will affect directly the position of upper and lower bands. Improper parameter settings may lead to increased rate of false breakouts.

Besides, using middle band as stop loss level also has risk itself. When market experiences sharp fluctuations, price could break through the middle band abruptly, triggering stop loss. Then we need to evaluate if there is a major trend reversal, and expand the stop loss range accordingly as needed.

Strategy Improvements

This strategy can be improved from the following aspects:

  1. Optimize Bollinger Bands parameters. Accumulate empirical data with different periods to find the best parameter combination.

  2. Add volume checking rules to avoid false breakout under light trading volume scenarios. Can set threshold of trading volume needing to exceed recent average value before triggering orders.

  3. Refine stop loss mechanism by adjusting stop loss level dynamically based on market volatility degree. widen stop loss range under high volatility and narrow it under low volatility.

  4. Incorporate judgement from more indicators like MACD, KDJ to help determine entry timing, enhancing operation accuracy.


In conclusion, this is a practical trend following strategy generally. It identifies trend direction using Bollinger Bands indicator and triggers orders when price breaks through upper or lower bands. Two-way trading helps maximizing capturing of price movements. There is large room for strategy optimization through parameter tuning, stop loss refining etc for better results.

start: 2024-01-22 00:00:00
end: 2024-02-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

// © Valente_F
strategy(title="Strategy: Trend Following Bollinger Bands", shorttitle="Strategy: Trend Following Bollinger Bands", overlay = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity)

//Bollinger Bands Parameters
length = input(defval=20, minval=1, title= "Length")
stddev = input(defval=2, minval=0.5, title= "StdDev")

//Entry and Exit Parameters
checkbox1 = input(true, title="Enable Long Entrys")
checkbox2 = input(true, title="Enable Short Entrys")

//Bollinger Bands Calculation

[middle, upper, lower] = bb(close, length, stddev)

//Long Conditions

bulls1 = close > upper
bulls2 = close[1] < upper[1]
bulls = bulls1 and bulls2

//Short Conditions

bears1 = close < lower
bears2 = close[1] > lower[1]
bears = bears1 and bears2

// Plots of Bollinger Bands
plot(upper, title = "Upper Band", color = color.aqua)//, display = display.none)
plot(middle, title = "MA", color =, display = display.none)
plot(lower, title = "Lower Band", color = color.aqua)//, display = display.none)

neutral_color =, 100)
barcolors = bulls ? : bears ? : neutral_color

//Paint bars with the entry colors


long_entry = bulls and checkbox1

long_entry_level = high

strategy.entry("Long", true, stop = long_entry_level, when = long_entry)
strategy.cancel("Long", when = not long_entry)

strategy.exit("Stop Long", "Long", stop = middle)

short_entry = bears and checkbox2

short_entry_level = low

strategy.entry("Short", false, stop = short_entry_level, when = short_entry)
strategy.cancel("Short", when = not short_entry)

strategy.exit("Stop Short", "Short", stop = middle)