Open-source scriptindicator/v1
Stochastic Oscillator
Compare the closing price with its recent range using smoothed percent K and percent D lines.
#momentum#oscillator#stochastic
Description
The Stochastic Oscillator measures where the close sits within the recent high-low range. Its %K and smoothed %D lines are commonly examined for momentum shifts, crossings, and movement through overbought or oversold zones.
Open-source script. Everyone can inspect the source code, use the script on a chart, and save an editable copy.
Release notes
Version history · 1 published version
Version 1CurrentChart updatedStochastic Oscillator · Aug 31, 2026
Source codempl-2.0View sourceHide source
indicator("Stochastic Oscillator", { overlay: false });
const length = input.int("%K Length", 14, { min: 1, max: 200 });
const smoothK = input.int("%K Smoothing", 3, { min: 1, max: 50 });
const smoothD = input.int("%D Smoothing", 3, { min: 1, max: 50 });
const k = sma(stoch(close, length), smoothK);
const d = sma(k, smoothD);
plot(k, { title: "%K", color: "#2962ff", lineWidth: 2 });
plot(d, { title: "%D", color: "#ff6d00", lineWidth: 2 });
hline(80, { title: "Overbought", color: "#ef5350", style: "dashed" });
hline(20, { title: "Oversold", color: "#26a69a", style: "dashed" });
Community discussion
0 comments
No comments yet. Start the discussion.