In this article
After this article, you can
- Calculate an oscillator from aggregated OHLC candles.
- Distinguish a higher-timeframe reading from the mean of lower-timeframe readings.
Terms at hand: Stochastic Oscillator · Simple Moving Average (SMA) · Stop loss · Trading Plan · Average True Range (ATR) · Relative Strength Index (RSI)
On one chart, %K can mean raw Close position; on another, it already contains smoothing. Define the calculation order before comparing Stochastic values. The same line names do not guarantee identical results, and 80 is neither a return probability nor a fundamental valuation.
Three stages: raw R, smoothed K and smoothed D
For a closed bar, let C be its Close, L the lowest Low and H the highest High across the last N bars including the current one. With H > L, raw R = 100(C − L)/(H − L). The extremes come from the OHLC window, not only from closes.
Our explicit model then uses K = SMA(R,s) and D = SMA(K,d). Require complete windows at every stage and retain intermediate precision. Missing observations are not zeros. This smooths oscillator outputs, rather than replacing the price series with its average.
TradingView documents separate K-window, K-smoothing and D-period fields. Record their names and averaging convention, not just a tuple of three numbers. A raw value and a smoothed K can differ without either calculation being inconsistent.
Stochastic on an aggregate is not the mean of shorter readings
Two arbitrary candles have OHLC: A=(100, 110, 90, 110), B=(110, 130, 100, 120). At N=1, raw A is 100 and B about 66.67; their mean is 83.33. Aggregated OHLC=(100, 130, 90, 120) gives a raw result 75.
Scroll sideways to see the full diagram
Aggregation selects the highest High, lowest Low and final Close. Averaging outputs instead combines two ratios with different denominators. To obtain a higher-timeframe indicator, calculate it from that timeframe’s candles; do not substitute a mean of lower readings without defining a different tool.
Assumptions: Complete arbitrary OHLC, two consecutive candles without a gap. N=1 and no smoothing deliberately isolate operation order; this is not a recommended setting. Formula or data reference: MetaTrader 5: Stochastic formula.
Fast, slow and full are named conventions
| Variant | K | D |
|---|---|---|
| Fast | Raw R | Usually SMA3 of K |
| Slow | SMA3 of R | Usually SMA3 of smoothed K |
| Full | SMA of R with chosen s | SMA of K with chosen d |
Here full with s = 1 skips the first smoothing; s = 3 and d = 3 gives slow. Fast D equals slow K only when they use identical R and the same three-period SMA. These formulas do not assign fast to M5, slow to H4 or a profitable variant to any interval.
A complete seven-candle model
Use N = 3, s = 2 and d = 2 solely to learn the calculation. All prices below are hypothetical, in arbitrary units; all bars are closed. Open is included for OHLC validation, although this formula does not use it.
| Bar | Open | High | Low | Close |
|---|---|---|---|---|
| 1 | 100 | 120 | 80 | 100 |
| 2 | 100 | 110 | 90 | 100 |
| 3 | 100 | 110 | 90 | 104 |
| 4 | 104 | 110 | 90 | 104 |
| 5 | 104 | 110 | 90 | 108 |
| 6 | 108 | 110 | 90 | 92 |
| 7 | 92 | 110 | 90 | 100 |
| Bar | Window Low / High | R | K = SMA2(R) | D = SMA2(K) |
|---|---|---|---|---|
| 3 | 80 / 120 | 60 | — | — |
| 4 | 90 / 110 | 70 | 65 | — |
| 5 | 90 / 110 | 90 | 80 | 72.5 |
| 6 | 90 / 110 | 10 | 50 | 65 |
| 7 | 90 / 110 | 50 | 30 | 40 |
Bar 3 gives R = 100(104 − 80)/40 = 60. At bar 4, the first candle’s extremes leave the window: R becomes 100(104 − 90)/20 = 70 despite unchanged Close. The first K is (60 + 70)/2 = 65. At bar 5, K = 80 and first D = (65 + 80)/2 = 72.5. At bar 7, R = 50, K = 30 and D = 40: three different stages.
Smoothed values have a different interpretation
Raw R describes the latest Close within its current range. K and D combine earlier readings, potentially calculated from different extreme windows. At bar 5, K = 80 while raw R = 90. With valid OHLC and positive range width, R stays within 0–100; SMAs of those values do too. That mathematical bound does not create a probability of a profitable trade.
A trend-following rule or a separately defined support or resistance level is a further hypothesis. Neither turns one oscillator event into a certified entry or guarantees an ATR-based stop is safe.
Flat ranges and the first available output
If the entire window has H = L, the ratio is mathematically undefined. The read TA-Lib 0.6.4 STOCH code sets raw output to 0 in its zero-range branch before averaging. That is a software convention, not evidence of selling pressure. Other implementations require separate checking; our exercise instead marks a flat range unavailable and does not average across it.
Under full-window SMAs, first R is at bar N, first K at N + s − 1, and first D at N + s + d − 2: bars 3,4,5 here. A library may return K and D together only when D exists. A display beginning later need not mean another formula.
Two SMA2 stages do not equal one SMA3
Substitute K(t) = [R(t) + R(t−1)]/2 into D(t) = [K(t) + K(t−1)]/2. Then D(t) = [R(t) + 2 R(t−1) + R(t−2)]/4. The middle value appears in both overlapping windows. Its effective weight is 1/2; the outer weights are 1/4 each.
| Index | D after two SMA2 stages | One SMA3 |
|---|---|---|
| 2 | 25 | 33⅓ |
| 3 | 50 | 33⅓ |
| 4 | 25 | 33⅓ |
These assigned raw values can represent closes at the maximum or minimum of a positive range. Both filters start with three observations but give different outputs. Replacing the two stages with SMA3 changes the calculation and potentially crossings with K. Divergence with other oscillators also requires its own point-pairing and recognition-time rules; it is not a proven strongest signal.
Aggregation order and signal time matter
The diagram separately uses A = (100,110,90,110) and B = (110,130,100,120). At N = 1 their raw readings are 100 and 66⅔, mean 83⅓. Aggregating OHLC first gives (100,130,90,120), hence raw 75. Averaging ratios with different denominators is a different operation from computing the ratio on an aggregate. For the quiz’s final Close of 110, the aggregate result is 50.
For a downward crossing, one rule is prior K ≥ D and current K < D. Bar 6 satisfies it: prior 80 > 72.5, then 50 < 65. That identifies an event, without assuming a trade outcome. If the rule uses final Close, wait until the bar is closed and the observation known.
Reproduce one changed input
Change only bar 7’s Close to 106, keeping High 110 and Low 90. Raw R = 80; with prior R = 10, K = 45. Prior K = 50, so D = 47.5. Raw 80 and smoothed 45 are not contradictory.
Record data source, interval, time zone, N, s, d, average types, flat-range policy and confirmation time before evaluating a strategy. The technical analysis section on ForexMechanics provides related reading. The Stochastic interpretation article explains the raw/smoothed distinction; RSI compares another indicator construction. An extra filter, a selected candle or a fixed month of observation does not establish an edge.
Check your understanding
One short exercise
About 2 min · you can try again
Two candles aggregate to Low 90, High 130 and final Close 110. What is the raw N=1 aggregate reading?
- Unknown without both earlier Stochastic readings.
- 50.
- 110.
Check the answer and explanation
50.
(110−90)/(130−90)×100=50. This is the aggregate result, not the mean of two separate results.
Frequently asked
Does K always show the current Close’s position?
Only when K denotes an unsmoothed raw ratio. An averaged K includes earlier readings; in our bar 5, raw R is 90 and K = 80. Record the exact convention and line before interpreting the number.
Can Stochastic rise without a higher Close?
Yes. Close remains 104 between bars 3 and 4, but the first candle’s 80/120 extremes leave the window. The new 90/110 range changes raw R from 60 to 70. That is a reference-window change, not a price rise.
What if High equals Low across the whole window?
The ratio has a zero denominator. Check the implementation policy; TA-Lib 0.6.4 uses raw 0 in that branch. Our exercise treats it as unavailable. A software zero does not describe position in a positive range or establish selling pressure.
Does a K/D crossing establish a strategy’s result?
No. It changes the relation of computed series under a defined timing/equality rule. Add entry, exit, execution, costs and a complete observation sample before evaluating outcomes. A divergence or another filter does not automatically certify success.
Sources & bibliography
-
StockCharts ChartSchool Stochastic Oscillator (Fast, Slow, and Full) · Explains %K/%D formulas, fast/slow/full variants and conventional stochastic interpretations, with an attributed George Lane quotation. chartschool.stockcharts.com ↗
-
TradingView Stochastic (STOCH) · Documents the stochastic oscillator, its %K and %D lines, conventional threshold zones and divergence interpretation. www.tradingview.com ↗
-
Corporate Finance Institute Stochastic Oscillator · Explains stochastic %K/%D calculations, attributes the indicator to George Lane and discusses limitations such as false signals. corporatefinanceinstitute.com ↗
-
StockCharts ChartSchool StochRSI · Explains StochRSI's application of the stochastic formula to RSI values, allowing comparison of indicator construction. chartschool.stockcharts.com ↗
-
TA-Lib STOCH implementation, version 0.6.4 · Pinned source shows the raw zero-range branch, chosen moving-average stages and output start. Software conventions do not infer market direction. raw.githubusercontent.com ↗
