Stochastic RSI (Tushar Chande & Stanley Kroll) — the
stochastic construction applied to rsi instead of to
price:
r =rsi(column, rsiPeriod) raw =100 · (r − LL(r, stochPeriod)) / (HH(r, stochPeriod) − LL(…)) ${prefix}K=SMA(raw, kPeriod) ${prefix}D=SMA(${prefix}K, dPeriod)
Appends two columns, both bounded 0..100. RSI spends most of its life
between 40 and 60, so its own overbought/oversold thresholds fire rarely;
normalising it against its own recent range makes it reach both
extremes constantly. It is a much faster indicator than the RSI under it,
and that is the point rather than a defect.
It composes on the shipped rsi — the study, not a private copy —
so Wilder's seed, the flat-window rule and every other RSI decision are
inherited by construction rather than restated.
The option names are TradingView's, and kPeriod does NOT mean what it
rsiPeriod and stochPeriod are separate knobs even though both default
to 14: they answer different questions (how much history the RSI averages,
and how much of the RSI's own history the range covers), and vendors ship
them independently.
Definition — TA-Lib's STOCHRSI, with the mapping measured
TA-Lib's STOCHRSI returns fastk and fastd, not a slowed %K and
%D, so the correspondence is not the obvious one and the generator
measures which column equals which. On the oracle input at the defaults:
${prefix}K == talib.STOCHRSI(…, fastk_period = stochPeriod, fastd_period = kPeriod).fastd — bar for bar, to 9.9e-14, with
identical null masks (both first valid at bar 29).
The raw, unsmoothed range position — which this study does not emit
— equals TA-Lib's fastk to 1.3e-13.
${prefix}D has no TA-Lib counterpart.STOCHRSI stops at fastd;
the second smoothing is the conventional %D that every charting
platform draws beside it, and it is a pandas replication in the oracle.
Crossing the columns is a real error, not a rounding one: ${prefix}K
against TA-Lib's fastk differs by 45 points on this fixture, which
is why the generator asserts both the match and the mismatch.
Two deliberate deltas, both inherited
A flat RSI window is undefined. When HH === LL the ratio is
0/0; TA-Lib reports 0, which is also the value for "the RSI is at the
very bottom of its range". The rule lives in
percentOfRangeValues so stochastic, williamsR and
this study all make the same call. It is genuinely reachable here — an
RSI pinned at 100 through a run of unbroken gains gives a flat window on
real data, where a flat price range mostly does not — and a unit test
pins it.
A flat RSI window inside the underlying RSI (no gains and no losses
at all) is undefined too, from rsi's own rule.
Warm-up — per column
On gap-free input: the RSI at bar rsiPeriod (differences need one extra
bar), the range at + stochPeriod − 1, %K at + kPeriod − 1 and %D at
+ dPeriod − 1. At the defaults that is bars 29 and 31. Both
smoothings go through rollingMeanValues, which waits for the
window's worth of finite values — the derived-input rule, and the same
reason stochastic's slow %K is not one bar early.
Edges
Scale- and shift-invariant, because the RSI under it is: multiplying
or offsetting every price leaves both columns unchanged (pinned).
An interior gap propagates to the end, and that is the RSI's Wilder
recursion rather than anything here — a recursion has no state to carry
across a hole. Fill before smoothing if you need continuity.
kPeriod: 1 leaves %K as the raw range position — the "fast"
Stochastic RSI, one knob rather than a second function, exactly as
stochastic's slowing: 1 gives the fast stochastic.
Stochastic RSI (Tushar Chande & Stanley Kroll) — the stochastic construction applied to rsi instead of to price:
Appends two columns, both bounded
0..100. RSI spends most of its life between 40 and 60, so its own overbought/oversold thresholds fire rarely; normalising it against its own recent range makes it reach both extremes constantly. It is a much faster indicator than the RSI under it, and that is the point rather than a defect.It composes on the shipped rsi — the study, not a private copy — so Wilder's seed, the flat-window rule and every other RSI decision are inherited by construction rather than restated.
The option names are TradingView's, and
kPerioddoes NOT mean what itmeans on stochastic
Read this before reaching for the analogy. The two studies use their own vendor's vocabulary, and the same word lands on different knobs:
STOCHRSIstochPeriodkPeriodfastk_periodkPeriodslowingfastd_perioddPerioddPeriod%KrsiPeriodandstochPeriodare separate knobs even though both default to 14: they answer different questions (how much history the RSI averages, and how much of the RSI's own history the range covers), and vendors ship them independently.Definition — TA-Lib's
STOCHRSI, with the mapping measuredTA-Lib's
STOCHRSIreturnsfastkandfastd, not a slowed%Kand%D, so the correspondence is not the obvious one and the generator measures which column equals which. On the oracle input at the defaults:${prefix}K==talib.STOCHRSI(…, fastk_period = stochPeriod, fastd_period = kPeriod).fastd— bar for bar, to 9.9e-14, with identical null masks (both first valid at bar 29).fastkto 1.3e-13.${prefix}Dhas no TA-Lib counterpart.STOCHRSIstops atfastd; the second smoothing is the conventional%Dthat every charting platform draws beside it, and it is a pandas replication in the oracle.Crossing the columns is a real error, not a rounding one:
${prefix}Kagainst TA-Lib'sfastkdiffers by 45 points on this fixture, which is why the generator asserts both the match and the mismatch.Two deliberate deltas, both inherited
undefined. WhenHH === LLthe ratio is0/0; TA-Lib reports0, which is also the value for "the RSI is at the very bottom of its range". The rule lives in percentOfRangeValues so stochastic, williamsR and this study all make the same call. It is genuinely reachable here — an RSI pinned at 100 through a run of unbroken gains gives a flat window on real data, where a flat price range mostly does not — and a unit test pins it.undefinedtoo, from rsi's own rule.Warm-up — per column
On gap-free input: the RSI at bar
rsiPeriod(differences need one extra bar), the range at+ stochPeriod − 1,%Kat+ kPeriod − 1and%Dat+ dPeriod − 1. At the defaults that is bars 29 and 31. Both smoothings go through rollingMeanValues, which waits for the window's worth of finite values — the derived-input rule, and the same reason stochastic's slow%Kis not one bar early.Edges
kPeriod: 1leaves%Kas the raw range position — the "fast" Stochastic RSI, one knob rather than a second function, exactly as stochastic'sslowing: 1gives the fast stochastic.