Direct answer
A worked example of the Stochastic Oscillator shows, step by step, how the indicator turns price data into two numbers: %K and a smoothed %D. This example is intentionally numeric and assumption-driven, so you can recompute the same results.
What you need to know first
Stochastic Oscillator is a momentum indicator that measures where the latest closing price sits within a recent high–low window. The standard inputs are:
- Lookback window (n): how many past periods are used for the high and low.
- %K period and smoothing: how %K is calculated and optionally averaged.
- %D smoothing: a moving average (often of %K).
Because the calculation depends on the chosen window lengths and on the exact OHLC values used, a worked example must state its settings and the price series it uses.
Mechanism or definition
A common formulation uses these steps:
- Compute the range extremes over the lookback window (n):
- Highest high over the last n periods: HH
- Lowest low over the last n periods: LL
- Compute the raw %K value:
- %K = 100 × (Close − LL) / (HH − LL)
- Compute %D:
- %D = moving average of %K (example below uses a simple 3-period average of prior %K values).
Assumptions for the worked example
To keep everything verifiable and non-real-time:
- We use a toy dataset with 5 consecutive periods (Period 1 to 5).
- We choose lookback window n = 5, meaning HH and LL are taken across all 5 periods for the %K at Period 5.
- We compute %K for Periods 3, 4, and 5 using a lookback window of n = 3 for those points (so we can form %D).
- We compute %D as a simple average of the last 3 %K values: %D at Period 5 = average(%K3, %K4, %K5).
Toy OHLC data (assumed)
The example assumes the following OHLC values:
- Period 3: High = 1.1080, Low = 1.1000, Close = 1.1040
- Period 4: High = 1.1120, Low = 1.1010, Close = 1.1100
- Period 5: High = 1.1150, Low = 1.1090, Close = 1.1120
For the %K calculation at each of these periods, the lookback window n = 3 means HH and LL are taken from that period and the prior two periods. To avoid ambiguity, we assume the precomputed HH/LL for each window:
- For Period 3 (Periods 1–3 window): HH = 1.1100, LL = 1.1000
- For Period 4 (Periods 2–4 window): HH = 1.1120, LL = 1.1005
- For Period 5 (Periods 3–5 window): HH = 1.1150, LL = 1.1000
These HH/LL values are part of the explicit assumptions of the example.
Evidence or example (the worked numbers)
Step 1: Compute %K
Using %K = 100 × (Close − LL) / (HH − LL):
-
%K at Period 3
- Close = 1.1040, LL = 1.1000, HH = 1.1100
- HH − LL = 1.1100 − 1.1000 = 0.0100
- Close − LL = 1.1040 − 1.1000 = 0.0040
- %K3 = 100 × 0.0040 / 0.0100 = 40
-
%K at Period 4
- Close = 1.1100, LL = 1.1005, HH = 1.1120
- HH − LL = 1.1120 − 1.1005 = 0.0115
- Close − LL = 1.1100 − 1.1005 = 0.0095
- %K4 = 100 × 0.0095 / 0.0115 ≈ 82.61
-
%K at Period 5
- Close = 1.1120, LL = 1.1000, HH = 1.1150
- HH − LL = 1.1150 − 1.1000 = 0.0150
- Close − LL = 1.1120 − 1.1000 = 0.0120
- %K5 = 100 × 0.0120 / 0.0150 = 80
Step 2: Compute %D as a 3-period simple average
- %D at Period 5 = ( %K3 + %K4 + %K5 ) / 3
- %D5 = (40 + 82.61 + 80) / 3 ≈ 202.61 / 3 ≈ 67.54
How this “worked example” answers “how it works”
This is the core mechanic: the oscillator rescales today’s close within a past range. If the close moves near the recent high, %K rises; if it moves near the recent low, %K falls. %D adds smoothing so it changes more gradually than raw %K.
Limitations and risks (material failure modes)
- Division-by-zero when HH equals LL: If the high and low over the lookback window are identical, then HH − LL = 0 and %K cannot be computed by the basic formula. Many platforms handle this differently; your recomputation may need a defined rule. 2.