Skip to content

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 ​

InputTypeDefault
Kint3
Dint3
RSI lengthint14
Stochastic lengthint14
RSI sourcesource"close"
K colorcolor"#2962FF"
D colorcolor"#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)" });

AlphaScript language v0.1 · runtime 0.2.0