Stochastic RSI
Created by Tushar Chande and Stanley Kroll, Stochastic RSI is a Stochastic interpretation of the Relative Strength Index. It is different from, and often confused with the more traditional Stochastic Oscillator. [Discuss] 💬
// C# usage syntax
IReadOnlyList<StochRsiResult> results =
bars.ToStochRsi(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods);Create a buffer list and add each bar as it arrives:
StochRsiList stochRsiList = new(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods);
// call from your WebSocket or SSE message handler
void OnBarReceived(IBar bar) => stochRsiList.Add(bar);
// the list itself holds the results; fills as the handler runs
IReadOnlyList<StochRsiResult> results = stochRsiList;See Buffer lists for the full usage guide.
Subscribe to a BarHub and add each bar as it arrives:
BarHub barHub = new();
StochRsiHub observer = barHub.ToStochRsiHub(rsiPeriods, stochPeriods, signalPeriods, smoothPeriods);
// call from your WebSocket or SSE message handler
void OnBarReceived(IBar bar) => barHub.Add(bar);
// results fill as the handler runs
IReadOnlyList<StochRsiResult> results = observer.Results;Compound hub
The StochRSI hub is based on the RSI indicator. When the StochRSI hub is chained from an existing RsiHub instance it will reuse the existing RSI hub values rather than creating its own internal RSI calculations. This is not a normal chaining model.
// creates a new internal RSI hub
var stochRsiHub = bars
.ToStochRsiHub();As an option, if you have an existing RSI hub you may reuse it:
// existing hub
var rsiHub = bars
.ToRsiHub();
// does not create a 2nd internal hub
var stochRsiHub = rsiHub
.ToStochRsiHub();
// ❌ RSI → [ RSI ] → StochRSI
// ✅ RSI → StochRSISee Stream hubs for the full usage guide.
Parameters
| param | description |
|---|---|
rsiPeriodsint | Number of periods (R) in the lookback period. Must be greater than 0. Default is 14. |
stochPeriodsint | Number of periods (S) in the lookback period. Must be greater than 0. Typically the same value as rsiPeriods. Default is 14. |
signalPeriodsint | Number of periods (G) in the signal line (SMA of the StochRSI). Must be greater than 0. Typically 3-5. Default is 3. |
smoothPeriodsint | Smoothing periods (M) for the Stochastic. Must be greater than 0. Default is 1. |
The original Stochastic RSI formula uses a the Fast variant of the Stochastic calculation (smoothPeriods=1). For a standard period of 14, the original formula would be bars.ToStochRSI(14,14,3,1). The "3" here is just for the Signal (%D), which is not present in the original formula, but useful for additional smoothing and analysis.
Historical price bars requirements
You must have at least N periods of bars, where N is the greater of R+S+M and R+100 to cover the warmup and convergence periods. Since this uses a smoothing technique in the underlying RSI value, we recommend you use at least 10×R periods prior to the intended usage date for better precision.
bars is a collection of generic TBar historical price bars. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.
Response
IReadOnlyList<StochRsiResult>- This method returns a time series of all available indicator values for the
barsprovided. - It always returns the same number of elements as there are in the historical price bars.
- It does not return a single incremental indicator value.
- The first
R+S+M-2periods will havenullvalues forStochRsi, and the firstR+S+M+G-3periods forSignal, since there's not enough data to calculate.
StochRsiList : IReadOnlyList<StochRsiResult>- The list itself holds the results, one for each bar or value added, in timestamp order.
- It keeps up to 100,000 results by default and drops the oldest beyond that; set
MaxListSizeto keep fewer. - The first
R+S+M-2periods will havenullvalues forStochRsi, and the firstR+S+M+G-3periods forSignal, since there's not enough data to calculate.
IReadOnlyList<StochRsiResult> results = observer.Results;observer.Resultsholds the results, one for each bar in theBarHubcache, in timestamp order.- Results update as bars arrive, including bars that arrive late or are revised.
- The cache keeps up to 100,000 results by default; set
maxCacheSizeon theBarHubto keep fewer. - The first
R+S+M-2periods will havenullvalues forStochRsi, and the firstR+S+M+G-3periods forSignal, since there's not enough data to calculate.
🚩 ⚞ Convergence warning
The first 10×R periods will have decreasing magnitude, convergence-related precision errors that can be as high as ~5% deviation in indicator values for earlier periods. We recommend pruning at least R+S+M+100 initial values.
StochRsiResult
| property | description |
|---|---|
TimestampDateTime | Date from evaluated TBar |
StochRsidouble? | %K Oscillator = Stochastic RSI = Stoch(S,G,M) of RSI(R) of price |
Signaldouble? | %D Signal Line = Simple moving average of %K based on G periods |
Chaining
This indicator may be generated from any chain-enabled indicator or method.
// example
var results = bars
.Use(CandlePart.HL2)
.ToStochRsi(..);Results can be further processed on StochRsi with additional chain-enabled indicators.
// example
var results = bars
.ToStochRsi(..)
.ToSlope(..);See Chaining indicators for more.
This indicator may be generated from results of another chain-enabled buffer list. Add each new result to it yourself.
// example
SmaList smaList = new(..);
StochRsiList stochRsiList = new(..);
void OnBarReceived(IBar bar)
{
smaList.Add(bar);
stochRsiList.Add(smaList[^1]);
}Add each new result to another chain-enabled buffer list to process StochRsi further.
// example
StochRsiList stochRsiList = new(..);
SlopeList slopeList = new(..);
void OnBarReceived(IBar bar)
{
stochRsiList.Add(bar);
slopeList.Add(stochRsiList[^1]);
}See Chaining buffer lists for more.
This indicator may be subscribed to any chain-enabled hub.
// example
StochRsiHub observer = barHub
.ToBarPartHub(CandlePart.HL2)
.ToStochRsiHub();Subscribe other chain-enabled hubs to it to process StochRsi further.
// example
SlopeHub observer = barHub
.ToStochRsiHub()
.ToSlopeHub(..);See Chaining stream hubs for more.
Utilities
Call these on the list itself, as in stochRsiList.Find(lookupDate). .Condense() returns a new list and leaves stochRsiList unchanged.
Warmup removal is left out. Once the list is full it drops its oldest results, so trimming by position would remove valid values.
Call these on observer.Results, as in observer.Results.Find(lookupDate). .Condense() returns a new list and leaves the hub's results unchanged.
Warmup removal is left out. Once the cache is full the hub drops its oldest results, so trimming by position would remove valid values.
See Utilities and helpers for more information.