Appearance
Stochastic RSI
Stochastic applied to RSI, with K and D lines.
Kind indicator · Drawn in its own pane
Try it
On the chart, press / and choose Stochastic RSI under Oscillators. To change it, copy the source below into the AlphaScript editor.
Inputs
| Input | Type | Default |
|---|---|---|
| K | int | 3 |
| D | int | 3 |
| RSI length | int | 14 |
| Stochastic length | int | 14 |
| RSI source | source | "close" |
| K color | color | "#2962FF" |
| D color | color | "#FF6D00" |
Source
From packages/alphascript/indicators/stochrsi.as.js.
js
indicator({ name: "Stochastic RSI", shortTitle: "Stoch RSI", overlay: false, precision: 2 });
const smoothK = input.int("K", 3, { min: 1 }), smoothD = input.int("D", 3, { min: 1 });
const rsiLength = input.int("RSI length", 14, { min: 1 }), stochLength = input.int("Stochastic length", 14, { min: 1 });
const src = input.source("RSI source", "close");
const r = ta.rsi(src, rsiLength), hh = ta.highest(r, stochLength), ll = ta.lowest(r, stochLength);
const k = ta.sma(ta.calc([r, hh, ll], (v, h, l) => (h - l ? (100 * (v - l)) / (h - l) : 0)), smoothK);
plot(k, { title: "K", color: input.color("K color", "#2962FF", { group: "Style" }) });
plot(ta.sma(k, smoothD), { title: "D", color: input.color("D color", "#FF6D00", { group: "Style" }) });
hline(80, { title: "Upper band", color: "#787B86", style: "dashed" });
hline(50, { title: "Middle band", color: "rgba(120,123,134,0.5)", style: "dotted" });
hline(20, { title: "Lower band", color: "#787B86", style: "dashed" });
fill(80, 20, { title: "Background", color: "rgba(33,150,243,0.1)" });