Skip to main content

Bollinger Bands Strategy

Discover our Bollinger Band Strategy PineScript template, designed for traders seeking to use bollinger bands indicator. Easily backtest on TradingView and live execute this template on AlgoTest.
Adjusting inputs like Bollinger Bands Length, Bollinger Bands Multiplier, target points, and stop loss points to suit your trading preferences.

info

To learn how to add this pinescript in TradingView, click here.

Bollinger Band Indicator Pinescript​

warning

These strategies are for demonstration purposes only and are not intended for actual trading. AlgoTest is not responsible for any profit or loss arising from the use of these sample strategies.

//@version=5
strategy("Bollinger Bands Strategy", overlay=true)

// Input parameters
length = input.int(20, title="BB Length")
mult = input.float(2.0, title="BB Multiplier")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Bollinger Bands
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper_band = basis + dev
lower_band = basis - dev

// Strategy logic
long_condition = ta.crossover(close, lower_band)
short_condition = ta.crossunder(close, upper_band)

// Plot Bollinger Bands
plot(upper_band, color=color.blue, title="Upper Band")
plot(lower_band, color=color.red, title="Lower Band")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)


Understanding the Bollinger Bands Indicator​

History of the Bollinger Bands Indicator​

Developed by John Bollinger in the 1980s, Bollinger Bands are a popular technical analysis tool that has become integral to many trading strategies over the decades. Bollinger designed these bands to help traders assess the volatility and relative price levels over a specified time period.

What is the Bollinger Bands Indicator?​

Bollinger Bands consist of three lines: the middle band is a simple moving average (SMA) typically set to 20 periods, and the two outer bands are placed two standard deviations away from the middle band, both above and below it. This configuration allows the bands to adjust to volatility in the market. The bands widen during periods of increased volatility and contract when volatility decreases, providing dynamic insights into market price behavior and potential overbought or oversold conditions.

Best Use Cases for Bollinger Bands​

  1. Trend Identification: Traders use Bollinger Bands to identify the start and end of trending movements. The bands help in recognizing when an asset is trading outside of its typical ranges, which can indicate a strong trend.

  2. Volatility Analysis: By measuring the distance between the bands, traders can assess the volatility of an asset. Wider bands suggest higher volatility, while narrower bands indicate lower volatility.

  3. Price Targeting: The bands can act as dynamic support and resistance levels. The upper band often serves as a resistance level, while the lower band can be seen as a support level.

  4. Squeeze Strategy: A Bollinger Band squeeze, which occurs when the bands tighten closely around the price, often precedes a significant price movement. Traders look for a squeeze to signal potential breakouts.

Frequently Asked Questions​

How do you use the Bollinger Band indicator?​

Bollinger Bands are typically used to measure market volatility and identify overbought or oversold conditions. Traders may look for stock prices crossing above or below the bands as buy or sell signals, respectively.

What is the best setting for Bollinger Bands?​

The standard setting for Bollinger Bands is a 20-day simple moving average with bands drawn at 2 standard deviations. However, settings can be adjusted for shorter or longer timeframes based on trading strategy needs.

What does a Bollinger Bands squeeze indicate?​

A Bollinger Bands squeeze suggests that the market is very low in volatility and is often followed by a significant move in either direction, indicating a potential breakout.

Is the Bollinger Band strategy profitable?​

Like any trading indicator, the profitability of Bollinger Bands depends on the trader's skill in using them in conjunction with other technical analysis tools and market conditions. They are not foolproof but can be a powerful component of a diversified trading strategy.

Which indicators pair well with Bollinger Bands?​

Traders often combine Bollinger Bands with momentum indicators like the Relative Strength Index (RSI) or the Moving Average Convergence Divergence (MACD) to confirm signals and enhance trading decisions.

For more insights and detailed signal analysis tools, visit AlgoTest Signals.