Appearance
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
| Input | Type | Default |
|---|---|---|
| %K length | int | 14 |
| %K smoothing | int | 1 |
| %D smoothing | int | 3 |
| %K color | color | "#2962FF" |
| %D color | color | "#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)" });