A bounded momentum oscillator showing where the close sits within a recent high-low range.
The Stochastic Oscillator is a momentum indicator popularized by George Lane in the late 1950s. It compares an instrument's closing price to its trading range over a chosen lookback period, expressing the result as two lines (%K and %D) that move between 0 and 100. The idea behind it is that closing prices tend to cluster near the top of the recent range when momentum is firm and near the bottom when momentum is soft. It is an educational analysis tool, not a buy/sell signal, and like all indicators it is not predictive.
Over a lookback window (commonly 14 periods), the indicator finds the highest high and the lowest low. The raw %K line measures where the current close falls within that range: a close at the very top of the range reads near 100, a close at the very bottom reads near 0, and a close in the middle reads near 50. Because raw %K can be jumpy, most charting platforms smooth it (this smoothed value is often what is labelled %K), then take a short moving average of that line to produce the %D signal line. The two lines together describe how recent closes sit relative to the recent range, and how that position is changing.
Classic settings are %K length 14, %K smoothing 1 or 3, and %D smoothing 3 — often written as 14, 3, 3 (the "slow" stochastic). Overbought/oversold bands are conventionally drawn at 80 and 20. Faster traders sometimes shorten the lookback (e.g. 5 or 8); those wanting fewer signals lengthen it. Bands of 70/30 are also used to mark less extreme zones.
//@version=6
indicator("Stochastic Oscillator", overlay = false)
kLength = input.int(14, "%K Length")
kSmooth = input.int(3, "%K Smoothing")
dSmooth = input.int(3, "%D Smoothing")
k = ta.sma(ta.stoch(close, high, low, kLength), kSmooth)
d = ta.sma(k, dSmooth)
plot(k, "%K", color = color.blue)
plot(d, "%D", color = color.orange)
hline(80, "Overbought", color = color.gray)
hline(20, "Oversold", color = color.gray)Pro tip: One educational way to study the oscillator is to anchor it to the prevailing trend before reading its extremes: in a clear uptrend, traders often pay more attention to dips into the lower zone and tend to discount upper-zone readings, and the reverse in a downtrend. This is a framing for studying behaviour, not advice to enter or exit a position, and no setting makes the indicator predictive.
Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.