Stochastic RSI
The Stochastic formula applied to RSI: where RSI sits inside its own recent range, with %K, %D and 80/20 bands.
- Stoch RSI
- Built into Spectral
- Updates every tick
- stochastic rsi
- stoch rsi
- rsi
- oscillator
- overbought
- oversold
- momentum
MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.
Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Overview
Stochastic RSI applies the Stochastic formula to the RSI instead of to price: 100 means the RSI is at its highest value of the last Stochastic length bars, 0 at its lowest. %K is that position smoothed by a short simple average, and %D averages %K again as a signal line. Bands mark 80 and 20.
How to read it
It is far more sensitive than RSI: it moves through its whole range even when RSI stays between 40 and 60. Above 80 the RSI is near the top of its recent range, below 20 near the bottom. In a trend it can stay pinned at 100 or 0 for many bars.
%K crossing %D, especially near the bands, shows the short-term turn in momentum. Use it to time entries within a trend you have identified elsewhere rather than as a trend signal of its own.
Settings and limitations
Defaults are a 14-bar RSI, a 14-bar stochastic window, and 3-bar smoothing for %K and %D, as on TradingView. Set %K smoothing to 1 for the raw value. %K first appears on bar RSI length + Stochastic length + %K smoothing - 1 (bar 30 with the defaults). When the RSI did not move at all inside the window, there is no value.
Notes
Matches the Stochastic RSI on TradingView and most platforms (Chande and Kroll). The RSI is Wilder's RSI, the same as Spectral's RSI.
Settings
Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.
| Setting | Type | Default | Range or options | What it does |
|---|---|---|---|---|
| RSI length | Whole number | 14 | 1 – 500 | Bars in the Wilder RSI the oscillator is built from. |
| Stochastic length | Whole number | 14 | 1 – 500 | Bars in the RSI range the current RSI is compared with. |
| %K smoothing | Whole number | 3 | 1 – 100 | Bars in the simple average that forms %K. 1 draws the raw, unsmoothed value. |
| %D smoothing | Whole number | 3 | 1 – 100 | Bars in the simple average of %K that forms the %D signal line. |
| Source | Price source | close | open, high, low, close, hlc3 | Price the RSI is calculated from. |
| Upper band | Number | 80 | 0 – 100, step 1 | Level of the upper reference band. |
| Middle band | Number | 50 | 0 – 100, step 1 | Level of the middle reference band. |
| Lower band | Number | 20 | 0 – 100, step 1 | Level of the lower reference band. |
| Fill between bands | On / off | On | — | Shade the area between the upper and lower band. |
Presets
Each preset is its own entry in the Indicators toolbox, with these settings changed.
| Toolbox entry | Short name | Settings |
|---|---|---|
| Stochastic RSI (unsmoothed) | Stoch RSI fast | %K smoothing: 1 |
What it draws
Lines
- %Ksolid · 1.5 px · primary
#8AA9C3 - %Dsolid · 1 px
#C4A46A
Levels
- Upper banddashed · 1 px
#788493 - Middle banddotted · 1 px
#788493 - Lower banddashed · 1 px
#788493
Zones
- Band fillfilled at 10% opacity
#8AA9C3
Source
Save it as stochastic-rsi.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.
// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
schemaVersion: 2,
id: 'stochastic-rsi',
name: 'Stochastic RSI',
shortName: 'Stoch RSI',
version: '1.0.0',
author: 'Spectral',
description: 'The Stochastic formula applied to RSI: where RSI sits inside its own recent range, with %K, %D and 80/20 bands.',
pane: 'oscillator',
live: { lookback: 'stochLength' },
inputs: {
rsiLength: { type: 'integer', label: 'RSI length', default: 14, min: 1, max: 500, description: 'Bars in the Wilder RSI the oscillator is built from.' },
stochLength: { type: 'integer', label: 'Stochastic length', default: 14, min: 1, max: 500, description: 'Bars in the RSI range the current RSI is compared with.' },
kSmoothing: { type: 'integer', label: '%K smoothing', default: 3, min: 1, max: 100, description: 'Bars in the simple average that forms %K. 1 draws the raw, unsmoothed value.' },
dSmoothing: { type: 'integer', label: '%D smoothing', default: 3, min: 1, max: 100, description: 'Bars in the simple average of %K that forms the %D signal line.' },
source: { type: 'source', label: 'Source', default: 'close', description: 'Price the RSI is calculated from.' },
upperBand: { type: 'number', label: 'Upper band', default: 80, min: 0, max: 100, step: 1, description: 'Level of the upper reference band.' },
middleBand: { type: 'number', label: 'Middle band', default: 50, min: 0, max: 100, step: 1, description: 'Level of the middle reference band.' },
lowerBand: { type: 'number', label: 'Lower band', default: 20, min: 0, max: 100, step: 1, description: 'Level of the lower reference band.' },
showFill: { type: 'boolean', label: 'Fill between bands', default: true, description: 'Shade the area between the upper and lower band.' },
},
plots: {
k: { label: '%K', color: '#8AA9C3', lineWidth: 1.5, primary: true },
d: { label: '%D', color: '#C4A46A', lineWidth: 1 },
},
levels: {
upper: { label: 'Upper band', color: '#788493', lineStyle: 'dashed' },
middle: { label: 'Middle band', color: '#788493', lineStyle: 'dotted' },
lower: { label: 'Lower band', color: '#788493', lineStyle: 'dashed' },
},
zones: {
fill: { label: 'Band fill', color: '#8AA9C3', opacity: 0.1 },
},
presets: [
{ id: 'fast', name: 'Stochastic RSI (unsmoothed)', shortName: 'Stoch RSI fast', inputs: { kSmoothing: 1 } },
],
docs: {
overview: 'Stochastic RSI applies the Stochastic formula to the RSI instead of to price: 100 means the RSI is at its highest value of the last Stochastic length bars, 0 at its lowest. %K is that position smoothed by a short simple average, and %D averages %K again as a signal line. Bands mark 80 and 20.',
howToRead: 'It is far more sensitive than RSI: it moves through its whole range even when RSI stays between 40 and 60. Above 80 the RSI is near the top of its recent range, below 20 near the bottom. In a trend it can stay pinned at 100 or 0 for many bars.\n\n%K crossing %D, especially near the bands, shows the short-term turn in momentum. Use it to time entries within a trend you have identified elsewhere rather than as a trend signal of its own.',
settings: 'Defaults are a 14-bar RSI, a 14-bar stochastic window, and 3-bar smoothing for %K and %D, as on TradingView. Set %K smoothing to 1 for the raw value. %K first appears on bar RSI length + Stochastic length + %K smoothing - 1 (bar 30 with the defaults). When the RSI did not move at all inside the window, there is no value.',
notes: 'Matches the Stochastic RSI on TradingView and most platforms (Chande and Kroll). The RSI is Wilder\'s RSI, the same as Spectral\'s RSI.',
},
calculate(ctx) {
const { bars, inputs, ta } = ctx;
const rsi = ta.rsi(ta.source(bars, inputs.source), inputs.rsiLength);
const highest = ta.highest(rsi, inputs.stochLength);
const lowest = ta.lowest(rsi, inputs.stochLength);
const raw = rsi.map((value, index) => {
const high = highest[index];
const low = lowest[index];
return value === null || high === null || low === null || high === low ? null : (100 * (value - low)) / (high - low);
});
const k = ta.sma(raw, inputs.kSmoothing);
const d = ta.sma(k, inputs.dSmoothing);
const band = (value) => bars.map(() => (inputs.showFill ? value : null));
return {
plots: { k, d },
levels: { upper: inputs.upperBand, middle: inputs.middleBand, lower: inputs.lowerBand },
zones: { fill: { upper: band(inputs.upperBand), lower: band(inputs.lowerBand) } },
};
},
};Adapt it with an LLM
Paste this into your assistant and replace the second-to-last line with the change you want.
Start from this Spectral custom indicator: https://spectral.trade/indicators/stochastic-rsi.js Format reference: https://spectral.trade/docs/custom-indicators.llm.md Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match. Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow. Change I want: <describe the change> Answer with the complete file in one code block, ready to save as <id>.js.


