Bollinger Bands and StochRSI Momentum Strategy

Author: ChaoZhang, Date: 2023-10-30 17:19:21



The Bollinger Bands and StochRSI Momentum Strategy is designed to identify potential buy and sell opportunities in financial markets by combining two widely-used technical indicators: Bollinger Bands and Stochastic RSI. This strategy aims to capture momentum shifts and take advantage of price movements.

Strategy Logic

The strategy utilizes the following two indicators:

Bollinger Bands: Bollinger Bands consist of three lines on a price chart – a simple moving average (SMA) as the middle band, and upper and lower bands that represent standard deviation away from the SMA. These bands help identify periods of high and low volatility.

Stochastic RSI (StochRSI): Stochastic RSI is a momentum oscillator derived from the Relative Strength Index (RSI). It measures the position of the RSI relative to its range and is useful in identifying overbought and oversold levels.

The parameters of the strategy include:

  • Bollinger Bands Length: The number of periods used to calculate the Bollinger Bands. Longer length captures long-term trends while shorter length responds faster to price changes.

  • Bollinger Bands Deviation: Adjusts the width of the bands by scaling the standard deviation. Higher values increase the width to account for higher volatility.

  • StochRSI Length: The number of periods used to calculate the StochRSI. Shorter length makes the indicator more responsive to recent price swings.

  • K and D Periods: Control the smoothing and signal line generation in StochRSI, affecting sensitivity.

Trading logic:

  • Bollinger Bands are calculated based on chosen length and deviation. The bands envelope the SMA and quantify volatility.

  • StochRSI is computed using the defined length, generating oscillating K and D lines between 0 and 100. This identifies momentum shifts.

  • The buy condition occurs when the StochRSI K line crosses above the D line and the close is below the lower Bollinger Band. This suggests a potential bullish reversal with low volatility, signaling an opportunity to buy.

  • The sell condition is triggered when the StochRSI K line crosses below the D line and the close is above the upper Bollinger Band. This indicates a potential bearish reversal with high volatility, signaling an opportunity to sell.

  • Entry orders are placed when the buy/sell conditions are met, going long or short based on the market expectation.

  • Optional buy/sell signals can be visualized on the chart using up/down triangles.

  • The strategy plots the Bollinger Bands, StochRSI K/D for visual analysis.


  • Combines two widely-followed indicators, benefiting from both.

  • Bollinger Bands identify volatility trends, StochRSI catches reversals.

  • Customizable parameters suit different trading styles and market environments.

  • Clear entry signals are generated with visual plot shapes.

  • Can trade both long and short based on conditions.

  • Systematic logic allows backtesting to quantify performance.


  • Performance depends on robust optimization of parameters.

  • Trading costs and slippage affect profitability and must be considered.

  • Bollinger Band width is critical, too wide or narrow reduces accuracy.

  • Severe volatility increases likelihood of false signals.

  • Stop losses need to be implemented and monitored for risk control.

Enhancement Opportunities

  • Optimize parameters for the targeted instrument and time frame.

  • Incorporate trailing stops or position sizing to control risk per trade.

  • Add filters using other indicators like MACD, KDJ to improve signal reliability.

  • Incorporate machine learning to judge the probability of buy/sell signals.

  • Add volume indicators to avoid trading against the trend.


This strategy provides a systematic approach to trading momentum shifts using Bollinger Bands and StochRSI. With robust optimization, backtesting, and risk management, it has strong practical potential. Further enhancements can build it into a reliable automated trading system.

start: 2023-10-22 00:00:00
end: 2023-10-29 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

strategy("My Strategy with Bollinger Bands and StochRSI", overlay=true)

// Define your Bollinger Bands parameters
bollinger_length =, title="Bollinger Bands Length")
bollinger_dev = input.float(2, title="Bollinger Bands Deviation")

// Calculate Bollinger Bands
sma = ta.sma(close, bollinger_length)
dev = bollinger_dev * ta.stdev(close, bollinger_length)

upper_band = sma + dev
lower_band = sma - dev

// Define your StochRSI parameters
stoch_length =, title="StochRSI Length")
k_period =, title="K Period")
d_period =, title="D Period")

// Calculate StochRSI
rsi = ta.rsi(close, stoch_length)
k = ta.sma(ta.stoch(rsi, rsi, rsi, k_period), k_period)
d = ta.sma(k, d_period)

// Define your buy and sell conditions
buy_condition = ta.crossover(k, d) and close < lower_band
sell_condition = ta.crossunder(k, d) and close > upper_band

// Place orders based on the conditions
if (buy_condition)
    strategy.entry("Buy", strategy.long)

if (sell_condition)
    strategy.entry("Sell", strategy.short)

// Optional: Plot buy and sell signals on the chart
plotshape(buy_condition,, style=shape.triangleup, location=location.belowbar, size=size.small)
plotshape(sell_condition,, style=shape.triangledown, location=location.abovebar, size=size.small)

// Plot Bollinger Bands and StochRSI on the chart
plot(upper_band, title="Upper Bollinger Band",
plot(lower_band, title="Lower Bollinger Band",
plot(k, title="StochRSI K",
plot(d, title="StochRSI D",