Skip to content

Stochastic ​

Close within the N-bar range, %K and %D.

Kind indicator · Drawn in its own pane

Try it ​

On the chart, press / and choose Stochastic under Oscillators. To change it, copy the source below into the AlphaScript editor.

Inputs ​

InputTypeDefault
%K lengthint14
%K smoothingint1
%D smoothingint3
%K colorcolor"#2962FF"
%D colorcolor"#FF6D00"

Source ​

From packages/alphascript/indicators/stoch.as.js.

js
indicator({ name: "Stochastic", shortTitle: "Stoch", overlay: false, precision: 2 });
const kLength = input.int("%K length", 14, { min: 1 }), kSmooth = input.int("%K smoothing", 1, { min: 1 }), dSmooth = input.int("%D smoothing", 3, { min: 1 });
const st = ta.stoch(kLength, kSmooth, dSmooth);
plot(st.k, { title: "%K", color: input.color("%K color", "#2962FF", { group: "Style" }) });
plot(st.d, { 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