Bentrix Docs
HomePricingDashboard

Stochastic RSI

Oscillatorsoscillator2 linesin every package

The fast stochastic computed on the RSI series instead of on price: where momentum sits inside its OWN recent range.

It measures a second derivative of sentiment, not of price, so it can be at 100 while price is falling. Readings: the same 0 to 100 extremes and %K against %D, with the warning that it saturates at 0 and 100 for long stretches, which is normal behaviour and not a defect.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
2080
bar —O — H — L — C —main line —signal —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars. Stochastic RSI has no value on the first 20 — the bars it needs before it can answer — and its first value stands on bar 21. Its line runs between 0 and 100 on these bars, and the last value is 54.64. The pane's scale is fixed at 0 to 100, the range the study can take. Counting the conditions the study declares on these bars: crosses above 20 36 times; crosses below 20 36 times; crosses above 80 34 times; crosses below 80 35 times; crosses above its signal line 52 times; crosses below its signal line 52 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 20 on 177 bars; is below 20 on 103 bars; is above 80 on 99 bars; is below 80 on 181 bars; is above its signal line on 119 bars; is below its signal line on 155 bars.

02Its parts, named

The bars it readseach bar's close, unless you chooseanother priceWarm-upno value on the first 20 bars: thestudy needs them before it cananswerThe main linethe study's own value on each barThe second linedrawn with the main line: its signalor its partnerLevel 80a fixed reference the study is readagainstLevel 20a fixed reference the study is readagainst
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

A fast oscillator between 0 and 100: the Stochastic formula applied to the RSI instead of to price.

Stochastic RSI is two lines in a pane of its own, %K and its average %D, on a fixed scale from 0 to 100 with levels at 20 and 80. It moves from one end of the scale to the other within a few bars and often lies flat at 0 or 100 for a stretch, while the RSI it is made from is still making new highs or lows for the window.

04Where it comes from

Tushar Chande and Stanley Kroll described it in The New Technical Trader (1994) to make the RSI reach its extremes more often.

05The formula

StochRSI=RSIt−min(RSIN)max(RSIN)−min(RSIN)
RSItthe RSI on this bar
min(RSIN), max(RSIN)its lowest and highest value over the last N bars

scaled to 0–100, then smoothed by a %K and %D window.

06A worked example

Take an RSI of 14 whose last five values were 48, 55, 61, 52 and 58, and a %K period of 5.

The highest RSI of the five is 61 and the lowest 48. The newest is 58:

Fast %K = (58 − 48) / (61 − 48) × 100 = 76.9

Nothing in the calculation looks at price any more — only at where the RSI stands inside its own recent range. Had the five RSI values been 70, 74, 79, 72 and 77, an RSI the usual reading calls high throughout, the result would be (77 − 70) / (79 − 70) × 100 = 77.8: almost the same. %D is the average of the last three %K values.

On real closes — 20, 21, 23, 22, 24, 25, 24, 26 — the 3-bar RSI reads 89.19, 65.35 and 80.77 on the last three bars. With a %K period of 3, Fast %K = (80.77 − 65.35) / (89.19 − 65.35) × 100 = 64.7. The bar before, the RSI was the lowest of its three and %K was 0; with %D over 2 bars, %D = (0 + 64.7) / 2 = 32.3.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("Stochastic RSI")
rsiLength = input.int(14, "RSI length")
kLength = input.int(5, "%K length")
dLength = input.int(3, "%D length")
// TA-Lib's STOCHRSI: the RSI over `rsiLength`, then where it stands inside its own lowest-to-highest range over
// `kLength` bars (%K, 0 at the low, 100 at the high), and %K's simple average over `dLength` bars (%D).
[k, d] = talib.STOCHRSI(close, rsiLength, kLength, dLength, 0)
plot(k, "%K")
plot(d, "%D")
hline(80)
hline(20)

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

Read like the Stochastic: near 100 the RSI is at the top of its own recent range; near 0, at the bottom; %K and %D crossing.

How the 80 and 20 readings fail. The line reaches 0 or 100 whenever the RSI makes a new high or low for the window, which in a quiet market can be a move of a point or two of RSI. The reading says the RSI is at the edge of its recent range; it does not say the RSI, or price, is extreme.

How crossings fail. They are frequent by construction — an oscillator of an oscillator moves fast — and most are small wiggles of the RSI.

09In different markets and timeframes

The Stochastic RSI is for markets where the RSI itself seldom reaches its levels — quiet trends, long RSI periods. It turns the RSI's small wiggles into full-scale swings, which is useful in a range and far too lively in a trend.

10With other studies

Read beside the RSI it is made from, always: a reading of 100 means only that the RSI is at its highest for the window, and the RSI pane shows what that value is.

11What it does not tell you

!

It is an oscillator of an oscillator: very sensitive, it hits its extremes constantly. An extreme says the RSI is at its own recent high or low.

12Inputs and defaults

Stochastic RSI (3, 5)settings card
1%D period3
2%K period5
3Period14
4AverageThe study's own
5Applied priceClose
6TimeframeChart
7Wait for the candle to closeOn
  1. 1
    %D period — 3The smoothing of %K drawn beside it.
  2. 2
    %K period — 5How many RSI values the newest one is placed within. Shorter: the line hits 0 and 100 more often.
  3. 3
    Period — 14The period of the RSI underneath.
  4. 4
    Average — The study's ownThe kind of moving average inside the study. Left at the study's own, it is the one the study's calculation uses by itself.
  5. 5
    Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
  6. 6
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  7. 7
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

What each input changes

  • AverageThe kind of average %D is. Left at the study's own it is a simple average of %K.
  • In use14 for the RSI, then 5 and 3 here (TA-Lib's); 14, 14, 3, 3 is the form most platforms show.

13Limits and common misreadings

Two transformations from price. A reading of 100 can sit on an RSI of 45.

It needs the RSI's warm-up and then its own: the first value appears later than either period suggests.

It is flat at 0 or 100 for stretches, when the RSI keeps making new extremes for the window.

14Conditions an alert or a strategy can watch

crosses above 20 eventcrosses below 20 eventis above 20 stateis below 20 statecrosses above 80 eventcrosses below 80 eventis above 80 stateis below 80 statecrosses above its signal line eventcrosses below its signal line eventis above its signal line stateis below its signal line state

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

15Practise it in the laboratory

Put RSI 14 and Stochastic RSI (14, 5, 3) in two panes. Find a bar where the lower pane reads 100 and read the RSI on the same bar; repeat a few times and note how different those RSI values are.

Open the laboratory

17In Bentrix

  • From the menu: a chart's Indicators button › Oscillators › Stochastic RSI, or type Stochastic RSI in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

18From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "stoch_rsi"}).

The study, as a chart files it

This is a new Stochastic RSI’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "talib",
  "kind": "stoch_rsi",
  "settings": {
    "d": 3,
    "k": 5,
    "period": 14,
    "shape": "stoch_rsi"
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "talib",
      "kind": "stoch_rsi",
      "settings": {
        "d": 3,
        "k": 5,
        "period": 14,
        "shape": "stoch_rsi"
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "talib", "kind": "stoch_rsi", "settings": {"d": 3, "k": 5, "period": 14, "shape": "stoch_rsi"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "talib", "kind": "stoch_rsi", "settings": { "d": 3, "k": 5, "period": 14, "shape": "stoch_rsi" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "stoch_rsi", ["settings"] = new Dictionary<string, object?> { ["d"] = 3, ["k"] = 5, ["period"] = 14, ["shape"] = "stoch_rsi" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "stoch_rsi", "settings": map[string]any{"d": 3, "k": 5, "period": 14, "shape": "stoch_rsi"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "talib", "kind", "stoch_rsi", "settings", obj("d", 3, "k", 5, "period", 14, "shape", "stoch_rsi"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "stoch_rsi"}, {"settings", Json::Object{{"d", 3}, {"k", 5}, {"period", 14}, {"shape", "stoch_rsi"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "talib", "kind" => "stoch_rsi", "settings" => Dict{String,Any}("d" => 3, "k" => 5, "period" => 14, "shape" => "stoch_rsi")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "talib", kind = "stoch_rsi", settings = list(d = 3, k = 5, period = 14, shape = "stoch_rsi")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "stoch_rsi", "settings": {"d": 3, "k": 5, "period": 14, "shape": "stoch_rsi"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
  • Its fixed levels, drawn on the chart: [20.0, 80.0].
lineWhat it is
Mainthe indicator's own value
Signala smoothing of the main line, drawn beside it

In a strategy

Filed under a key of your choice in a strategy document’s studies — here stoch_rsi: {"stoch_rsi": {"applied": "close", "convention": "talib", "kind": "stoch_rsi", "settings": {"d": 3, "k": 5, "period": 14, "shape": "stoch_rsi"}}} — its rules can name:

WriteWhat it is
stoch_rsiits main line, as a value in a compare
stoch_rsi.signalthis line, as a value in a compare
{"cond": "stoch_rsi:level.cross_up:20"}a condition it declares itself
{"cond": "stoch_rsi:level.cross_down:20"}a condition it declares itself
{"cond": "stoch_rsi:level.above:20"}a condition it declares itself
{"cond": "stoch_rsi:level.below:20"}a condition it declares itself
{"cond": "stoch_rsi:level.cross_up:80"}a condition it declares itself
{"cond": "stoch_rsi:level.cross_down:80"}a condition it declares itself
{"cond": "stoch_rsi:level.above:80"}a condition it declares itself
{"cond": "stoch_rsi:level.below:80"}a condition it declares itself
{"cond": "stoch_rsi:signal.cross_up"}a condition it declares itself
{"cond": "stoch_rsi:signal.cross_down"}a condition it declares itself
{"cond": "stoch_rsi:signal.above"}a condition it declares itself
{"cond": "stoch_rsi:signal.below"}a condition it declares itself

19Sources

  1. Chande, Tushar S. & Kroll, Stanley. The New Technical Trader. Wiley, 1994.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed