Stochastic Oscillator
systemic:core-soIndicatorsInputs
| Name | Type | Description |
|---|---|---|
| Window | Whole number | The number of bars searched for the highest high and lowest low. |
| Smooth Factor | Whole number | The window, in bars, of the Simple Moving Average applied to %K to produce %D. |
| Price High | Number series | The highest price reached during each bar (candle). |
| Price Low | Number series | The lowest price reached during each bar (candle). |
| Price Close | Number series | The closing price for each bar. |
Outputs
| Name | Type | Description |
|---|---|---|
| SOK | Number series | The raw Stochastic Oscillator value: where the current close sits within the recent range. |
| SOD | Number series | The signal line: a simple moving average of %K. |
Cost
0.21 + 0.0115·n credits for n bars, rounded up. The marks are each plan's limit of bars.
The Insight: Momentum Changes Before Price
In the late 1950s, George C. Lane made an observation that became one of the best-known ideas in technical analysis:
"It doesn't follow price, it doesn't follow volume or anything like that. It follows the speed or the momentum of price. As a rule, the momentum changes direction before price."
Think of a ball thrown straight up. Before it turns and falls, it slows down. Its momentum changes before its direction does. Lane noticed that markets behave the same way: momentum weakens before price reverses.
The Stochastic Oscillator captures this with a simple question: Where is the current close within the recent price range?
The Formula
Where:
- = the Window (commonly 14 bars)
- = the Smooth Factor for %D (commonly 3 bars)
What %K measures: If the stock closed at its 14-bar high, %K = 100. If it closed at its 14-bar low, %K = 0. A %K of 70 means the close is 70% of the way from the lowest low to the highest high.
Why This Works
During an uptrend, prices tend to close near the high of each bar: buyers push prices up and hold them there. During a downtrend, prices tend to close near the low: sellers dominate.
When an uptrend weakens, prices may still make new highs, but they start to close further from those highs. The Stochastic Oscillator detects this before the price chart shows a clear reversal.
flowchart LR
subgraph Healthy["Healthy Uptrend"]
direction TB
H1["Price makes new high"]
C1["Close near the high"]
K1["%K stays elevated"]
end
subgraph Weakening["Weakening Uptrend"]
direction TB
H2["Price makes new high"]
C2["Close drifts from high"]
K2["%K starts falling"]
end
Healthy --> Weakening
This is the core idea: the oscillator often turns before price does.
Interpreting the Zones
| %K Value | Zone | What It Means |
|---|---|---|
| 80–100 | Overbought | Close is near the top of the recent range |
| 50–79 | Upper neutral | Buyers have the edge |
| 21–49 | Lower neutral | Sellers have the edge |
| 0–20 | Oversold | Close is near the bottom of the recent range |
An Important Caveat
Overbought ≠ Sell. Oversold ≠ Buy.
This is the most misunderstood part of the Stochastic Oscillator. In a strong uptrend, the oscillator can stay overbought for weeks or months while the price keeps climbing. In a strong downtrend, it can stay oversold while prices keep falling.
Lane himself stressed that overbought and oversold readings depend on context. They tell you where the close is within the range, not whether a reversal is near. You need more confirmation.
The Two Lines: %K and %D
The oscillator produces two lines:
| Line | Role | Behavior |
|---|---|---|
| %K | The raw measurement | Faster, more reactive, noisier |
| %D | The signal line (SMA of %K) | Slower, smoother, used for crossovers |
Lane considered %D divergence the most important signal, above crossovers and zone readings. When %D diverges from price (price makes a new high but %D does not), it warns that momentum has already turned.
Trading Signals
1. Crossovers
| Signal | Condition | Strongest When |
|---|---|---|
| Bullish | %K crosses above %D | From oversold territory (<20) |
| Bearish | %K crosses below %D | From overbought territory (>80) |
Crossovers in the middle of the range (30–70) are less reliable and give more whipsaws.
2. Divergence — Lane's "Only Signal"
Lane stated that divergence is "the only signal which will cause you to buy or sell."
| Type | Price | Stochastic | Implication |
|---|---|---|---|
| Bullish divergence | Lower low | Higher low | Downside momentum weakening |
| Bearish divergence | Higher high | Lower high | Upside momentum weakening |
Divergence does not tell you when to act. It tells you to pay attention. Confirmation (a support break, a crossover, or a move past 50) is needed.
3. The 50-Line
The centerline at 50 splits the range in half:
- %K above 50: Price is closing in the upper half of its range (bullish bias)
- %K below 50: Price is closing in the lower half of its range (bearish bias)
Crossing 50 after a divergence confirms the shift in momentum.
Input Tuning
| Input | Typical value | Lower Values | Higher Values |
|---|---|---|---|
| Window (n) | 14 | More sensitive, more signals, more noise | Smoother, fewer signals, more lag |
| Smooth Factor (m) | 3 | %D follows %K more closely | %D lags further behind %K |
The module has no built-in defaults: you set both values.
Common configurations:
- (5, 3): Fast, for scalping or day trading
- (14, 3): Standard, balanced sensitivity
- (21, 5): Slow, for swing trading or position trading
When It Works, When It Struggles
Excels In:
- Range-bound markets — The classic use case. When price moves between support and resistance, the Stochastic is good at timing entry and exit signals
- Trend pullbacks — In an established uptrend, oversold readings can mark good pullback entry points
- Divergence detection — Early warning of momentum exhaustion
Struggles In:
- Strong trends — Can stay overbought or oversold for a long time while price keeps moving
- Choppy, directionless markets — Frequent whipsaws as %K and %D cross repeatedly
- Low-volume or illiquid assets — Erratic price movements produce noisy signals
Creative Applications
Regime Detection
The Stochastic does more than give buy and sell signals. It can show what type of market you are in:
- %K consistently above 50: Trending up — favor long signals, be patient with overbought readings
- %K consistently below 50: Trending down — favor short signals, be patient with oversold readings
- %K oscillating around 50: Range-bound — look at the extremes
Multi-Period Confirmation
Check the Stochastic on a longer period to set the bias, then use signals on a shorter period:
| Longer-Period Stochastic | Shorter-Period Reading |
|---|---|
| Rising, not overbought | Favor bullish crossovers |
| Falling, not oversold | Favor bearish crossovers |
| Overbought + divergence | Be cautious with long signals |
Mean Reversion on Correlated Assets
When two highly correlated assets show opposite Stochastic readings (one oversold, one overbought), the spread between them may revert to its mean.
Summary
| Aspect | Key Point |
|---|---|
| Core insight | Momentum changes before price |
| What it measures | Where the close sits within the recent range |
| %K | The raw oscillator (0–100) |
| %D | Smoothed signal line |
| Overbought/Oversold | Context matters — not automatic signals |
| Best signal | Divergence between price and oscillator |
| Best environment | Range-bound markets, trend pullbacks |
Missing Data
A window of N bars means N bars that have data. A bar counts as missing when any one of high, low or close is empty (a data gap, or a closed market such as a weekend). A missing bar is skipped when the highest high and lowest low are searched. Friday and Monday count as neighboring bars; the gap is never treated as zero or as a repeated value.
- Gaps are skipped: the window always holds N real bars. A gap does not shrink the window.
- Warm-up is empty: %K is empty for the first
window - 1bars that have data. %D is empty for a further Smooth Factor − 1 bars. - Gap bars stay empty: a missing bar gives no %K and no %D. No value is filled in.
- A flat window is empty: when the highest high equals the lowest low, %K is undefined and stays empty. It is not reported as 50. %D is also empty while that bar is inside its smoothing window.
- Enough bars are required: the run fails if Window or Smooth Factor is larger than the number of input bars.
Indicator Assessment
%%{init: {"quadrantChart": {"titleFontSize": 16}}}%%
quadrantChart
title Stochastic Oscillator Assessment
x-axis Low Complexity --> High Complexity
y-axis Low Reliability --> High Reliability
quadrant-1 Complex but Reliable
quadrant-2 Simple and Reliable
quadrant-3 Simple but Unreliable
quadrant-4 Complex and Unreliable
SO - Stocks: [0.30, 0.70]
SO - Crypto: [0.30, 0.55]
| Dimension | Stocks/Macro | Crypto | Notes |
|---|---|---|---|
| Popularity | 9/10 | 8/10 | One of the most widely used oscillators since the 1950s; standard on virtually all charting platforms |
| Reliability | 7/10 | 5.5/10 | Good in ranging markets; prone to false signals in trends; crypto's volatility increases whipsaws |
| Complexity | 3/10 | 3/10 | Moderate formula with several parts (%K, %D, smoothing); zones are easy to read |
| Versatility | 8/10 | 7/10 | Works across periods and asset classes; adjustable inputs; crypto benefits from tuning |
| Recent Interest | 6/10 | 7/10 | Established classic; renewed crypto interest for mean-reversion strategies in ranging altcoin markets |
Assessment Rationale
-
Popularity: The Stochastic Oscillator is a classic of technical analysis, developed by George Lane in the 1950s. It appears on every major charting platform and in nearly all technical analysis courses.
-
Reliability: In ranging markets, the Stochastic gives reliable overbought and oversold signals. In strong trends, it can stay in an extreme zone for a long time and give many false reversal signals. Crypto markets, with their sharp moves and volatility clusters, make this weakness worse.
-
Complexity: The formula has several steps (highest high, lowest low, smoothing), but the idea is simple: "Where is the current close within the recent range?" The 0-100 scale with clear zones is easy for beginners to read.
-
Versatility: The Stochastic works on equities, forex, commodities and crypto. Window and Smooth Factor can be adjusted for different volatility. Several signal types (crossovers, divergence, zone reversals) cover different market conditions.
-
Recent Interest: Interest in the Stochastic is steady, not surging. Crypto traders have shown new interest in momentum oscillators for mean reversion in range-bound altcoin markets.