The Stochastic Oscillator measures how close the current price is to the recent high-low range. 100 means close pinned to the high, 0 means pinned to the low. %K is the raw value; %D is %K smoothed.
Formula
lowest_low = min(low, k_period)
highest_high = max(high, k_period)
%K = 100 * (close - lowest_low) / (highest_high - lowest_low)
%D = SMA(%K, d_period)Params
- K period - window for the high-low range. Default 14.
- D period - smoothing for %D. Default 3.
Output
Two columns:
{name}_k- %K (faster){name}_d- %D (slower, smoothed)
Common thresholds
| Range | Meaning |
|---|---|
| > 80 | Overbought |
| < 20 | Oversold |
Usage
- Mean reversion with %K/%D cross inside the overbought or oversold zone.
- %K crossing %D in either direction as a quicker momentum signal.
- Divergence between price and Stochastic, same idea as MACD.
Stochastic vs RSI
Stochastic emphasizes position within the recent range; RSI emphasizes recent gains vs losses. They often disagree at turning points - Stochastic typically fires earlier and gives more signals (including more false ones).
Pitfalls
In strong trends Stochastic gets pinned at 0 or 100 for many bars ("embedded" or "trapped"). Fade-only rules will eat the entire trend. Combine with a trend filter.
