Mean-reversion at the bands is one of the oldest ideas in technical analysis: when price pierces a Bollinger Band, it is statistically far from its short-term mean, and a snap-back becomes more likely. The weakness of using Bollinger Bands alone is that strong trends spend long stretches walking the upper or lower band, producing a stream of false reversal signals.
The Bollinger Bands Stochastic RSI Extreme Signal addresses this by demanding that two unrelated extremes happen at the same time: price must be returning back inside the band and the Stochastic RSI must be in overbought or oversold territory. The setup only fires when price stretch and momentum extreme align, which filters out the long band-walks of trending markets and isolates the moments when a counter-move is most plausible.
The bands are computed on the standard recipe: a 20-period simple moving average of the close as the basis, plus and minus two standard deviations of the same series. A close outside the upper or lower band marks a statistically extended condition relative to recent price action.
The Stochastic RSI is a second-order oscillator. First, a standard RSI is computed on the source. Then a Stochastic transformation is applied to that RSI: the indicator looks at where the current RSI value sits within its own high–low range over the last lengthStoch bars and rescales it to a 0–100 reading. The K line is a short smoothing of that ratio; the D line is a smoothing of K.
The result is an oscillator that registers extremes in the RSI itself, not in price. When K and D both move above 90 the underlying RSI is at the top of its recent range; below 10 the RSI is at the bottom. These are deeper extremes than a raw RSI reading and tend to mark genuine momentum exhaustion.
The indicator fires a bearish triangle when all of the following are true on the current bar:
A bullish triangle is the symmetric case at the lower band with K and D below the oversold threshold (default 10).
The first two conditions together mean the price has just made a failed excursion outside the band — it pierced and came back. The third condition adds momentum confirmation: that excursion happened while the Stochastic RSI was already at an extreme. The combination is rare on purpose; it is designed to flag pivots, not provide a continuous stream of signals.
The two triangles carry a clear directional bias:
The signals are bar-confirmed: they appear when the current bar closes, not intrabar, so there is no repainting. In strongly trending markets the signal becomes naturally rare because the Stochastic RSI tends to stay pinned at the extreme rather than briefly visiting it — that is by design, not a defect.
//--------------------------------------------------------------------//
//PRC_BB Stochastic RSI Extreme Signal
//version = 0
//28.06.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
//-----Inputs---------------------------------------------------------//
src=close
length=20
mult=2
smoothK=3
smoothD=3
lengthRSI=14
lengthStoch=14
upperlimit=90
lowerlimit=10
colorbands=1
showsignals=1
//-----Bollinger Bands------------------------------------------------//
basis=average[length](src)
dev=mult*std[length](src)
upper=basis+dev
lower=basis-dev
//-----Stochastic RSI (manual reconstruction)-------------------------//
rsi1=rsi[lengthRSI](src)
maxrsi=highest[lengthStoch](rsi1)
minrsi=lowest[lengthStoch](rsi1)
osc=(rsi1-minrsi)/(maxrsi-minrsi)*100
k=average[smoothK](osc)
d=average[smoothD](k)
//-----Signal logic---------------------------------------------------//
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
//-----Visuals--------------------------------------------------------//
if bear and showsignals then
drawtext("▼",barindex,high+0.25*averagetruerange[14](close))coloured("red")
elsif bull and showsignals then
drawtext("▲",barindex,low-0.25*averagetruerange[14](close))coloured("green")
endif
if colorbands then
colorbetween(upper,lower,"teal",50)
endif
//--------------------------------------------------------------------//
return basis as "SMA" coloured(135,35,35), upper as "BB top" coloured("teal"), lower as "BB bot" coloured("teal")