0bps

Strategy vault / Mean reversion

Bollinger Bands Stochastic RSI Extreme

This is the finalized code released to the public that I created in a video linked here. This indicators combines a Bollinger Band and Stochastic RSI to produce signals for possible price reversal. The signals are…

Author
ChaoZhang
Complexity
Intermediate · 67 lines
Parameters
10
Backtest bar
15m · intraday
Tested on
BTC/USDT · futures

This is the finalized code released to the public that I created in a video linked here.

This indicators combines a Bollinger Band and Stochastic RSI to produce signals for possible price reversal. The signals are displayed by default as green arrows for bullish and red arrows for bearish .

To trigger a signal the indicator checks for the following:

( Bullish ) A candle closes above the upper Bollinger Band The following candle closes within the upper Bollinger Band The RSI Stochastic is below the set threshold (10 by default)

( Bearish ) A candle closes below the lower Bollinger Band The following candle closes within the lower Bollinger Band The RSI Stochastic is above the set threshold (90 by default)

backtest IMG

Parameters

NameDefaultWhat it controls
v_input_1_close0Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_2falseOffset
v_input_320Bollinger Band Length
v_input_42StdDev
v_input_53K
v_input_63D
v_input_714RSI Length
v_input_814Stochastic Length
v_input_990Upper Limit
v_input_1010Upper Limit

Source Pine Script

/*backtest
start: 2022-04-30 00:00:00
end: 2022-05-29 23:59:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
study(shorttitle="BBSR Extreme", title="Bollinger Bands Stochastic RSI Extreme Signal", overlay=true, resolution="")

//General Inputs
src = input(close, title="Source")
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)

//Bollinger Inputs
length = input(20, title="Bollinger Band Length", minval=1)
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")

//Bollinger Code
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
plot(basis, "BB Basis", color=#872323, offset = offset)
p1 = plot(upper, "BB Upper", color=color.teal, offset = offset)
p2 = plot(lower, "BB Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "BB Background", color=#198787, transp=95)


//Stoch Inputs
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)

upperlimit = input(90, "Upper Limit", minval=0.01)
lowerlimit = input(10, "Upper Limit", minval=0.01)

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

//Evaluation
Bear = close[1] > upper[1] and close < upper
     and k[1] > upperlimit and d[1] > upperlimit
Bull = close[1] < lower[1] and close > lower
     and k[1] < lowerlimit and d[1] < lowerlimit


//Plots
plotshape(Bear, style=shape.triangledown, location=location.abovebar, 
     color=color.red, size=size.tiny)
plotshape(Bull, style=shape.triangleup, location=location.belowbar, 
     color=color.green, size=size.tiny)
 
// Alert Functionality
alertcondition(Bear or Bull, title="Any Signal", message="{{exchange}}:{{ticker}}" + " {{interval}}" + " BB Stochastic Extreme!")
alertcondition(Bear, title="Bearish Signal", message="{{exchange}}:{{ticker}}" + " {{interval}}" + " Bearish BB Stochastic Extreme!")
alertcondition(Bull, title="Bullish Signal", message="{{exchange}}:{{ticker}}" + " {{interval}}" + " Bullish BB Stochastic Extreme!")


if Bear
    strategy.entry("Enter Long", strategy.long)
else if Bull
    strategy.entry("Enter Short", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-31. 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-Bands-Stochastic-RSI-Extreme.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