0bps

Strategy vault / Breakout

Bollinger Band and Stoch RSI Trading Strategy

This strategy combines the Bollinger Bands and Stoch RSI indicators for multiple indicator trading. It belongs to the typical combined indicators strategy type. The Bollinger Bands determine trend direction and the…

Author
ChaoZhang
Complexity
Intermediate · 94 lines
Parameters
15
Backtest bar
2d · swing
Tested on
BTC/USDT · futures

Overview

This strategy combines the Bollinger Bands and Stoch RSI indicators for multiple indicator trading. It belongs to the typical combined indicators strategy type. The Bollinger Bands determine trend direction and the Stoch RSI optimizes entry timings for trade signals.

Strategy Logic

The strategy is based on two main indicators:

  1. Bollinger Bands

    Calculate the upper, middle and lower bands. A buy signal is generated when price breaks above the lower band.

  2. Stoch RSI

    Calculate the Stoch RSI indicator. A buy signal is generated when the K line crosses above the D line.

The specific trading logic is: open long when both the Bollinger Bands lower breakout and Stoch RSI golden cross occur together.

The exit logic uses the bands for take profit and stop loss: close for profit when price touches the upper or middle band again, close for loss when price breaks back below the lower band.

Advantages

  • Combines Bollinger Bands and Stoch RSI
  • Bands judge overall trend, Stoch RSI optimizes entry
  • Stoch RSI filters false band breakouts
  • Middle and lower bands provide exits
  • Multiple adjustable parameters for optimizations

Risks

  • MA-based indicators lag, missing best entries
  • Purely indicator-driven, slow reaction to sudden events
  • Improper band settings invalidate stops
  • Bad Stoch RSI parameters generate false signals
  • Separate parameter tuning needed for different products

Risks can be reduced by:

  • Optimizing parameters for higher accuracy
  • Adding confirming filters like MACD
  • Using trailing stops instead of band stops
  • Testing parameters for different products
  • Adjusting position sizing system

Enhancement Directions

The strategy can be improved by:

  1. Optimizing Bollinger Bands parameters

    Adjust upper/lower calculation ratios for best fit

  2. Optimizing Stoch RSI parameters

    Finding optimal K and D values

  3. Adding confirming indicators like MACD

    Avoid false signals relying on single indicator

  4. Using trailing profit stops instead of fixed stops

    Trail stops based on price volatility

  5. Testing parameters separately for different products

    Optimal parameters vary across different products

Summary

This strategy leverages the Bollinger Bands for trend direction and Stoch RSI for entry optimization, taking advantage of a multi-indicator approach. But challenges like difficult parameter optimization and signal accuracy exist. Rigorous backtesting for parameter optimization, adding filters, and continuously adjusting rules based on results can improve accuracy while retaining the strengths of a combined system. Persistent optimizations lead to robustness.

Parameters

NameDefaultWhat it controls
v_input_150bblength
v_input_22Multiplier for BB Upper Band
v_input_32Multiplier for BB Lower Band
v_input_46lengthrsi
v_input_520overSold
v_input_670overBought
v_input_73smoothK
v_input_83smoothD
v_input_914lengthRSI
v_input_1014lengthStoch
v_input_11_close0RSI Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_126monthfrom
v_input_1312monthuntil
v_input_14truedayfrom
v_input_1531dayuntil

Source Pine Script

/*backtest
start: 2022-09-14 00:00:00
end: 2023-09-20 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3

strategy(title = "BB+RSI v2", overlay = true)

price=close
////////// ///////  BB /////////////////////////

bblength = input(50)
bbupmult =input(2,step=0.1,title="Multiplier for BB Upper Band")
bblowmult = input(2,step=0.1,title="Multiplier for BB Lower Band")

basis =  sma(close,bblength)

devup = bbupmult * stdev(close, bblength)
devlow = bblowmult * stdev(close, bblength)

upper = basis + devup
lower = basis - devlow
plot(basis, color=red)
p1 = plot(upper, color=blue)
p2 = plot(lower, color=blue)
fill(p1, p2)


bbbuy= crossover(price,lower)
bbsell = crossunder(price,upper) or price>upper or crossunder(price,basis)



//////////////////// BB //////////////////////




////////////////////////  S RSI  /////////////////////

lengthrsi = input(6)
overSold = input( 20 )
overBought = input( 70 )
vrsi = rsi(price, lengthrsi)

smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
src = input(close, title="RSI Source")

rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)

SRSIbuy=crossover(k,d)

////////////////////// S  RSI  ///////////////////////

// Conditions



longcond = bbbuy and SRSIbuy
closelong = bbsell


monthfrom =input(6)
monthuntil =input(12)
dayfrom=input(1)
dayuntil=input(31)



if (  longcond ) 
    strategy.entry("BUY", strategy.long, stop=close, oca_name="TREND",  comment="BUY")
    
else
    strategy.cancel(id="BUY")


if ( closelong  ) 

    strategy.close("BUY")





Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-21. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bollinger-Band-and-Stoch-RSI-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open