How it works
The Stochastic Oscillator measures position, not speed. It takes the highest high and the lowest low of the lookback window, treats that span as a 0-100 scale, and reports where the latest close falls on it. The premise is behavioural and easy to state: while buyers are in control, bars tend to close near the top of their recent range; when sellers take over, closes migrate toward the bottom. A reading of 90 says today closed in the top tenth of everything the market has traded in the window.
Because it is normalised by the range itself, the oscillator has no memory of magnitude. A market that has crawled two ticks in a narrow week can print a stochastic of 100 just as easily as one that has ripped fifteen percent, because in both cases the close was at the top of whatever range existed. That is the single most important thing to understand about the tool: it is a relative-position indicator that deliberately discards information about how much price moved, and its readings are only comparable across periods where the range itself is comparable.
Almost every platform shows the 'slow' version by default, which smooths the raw calculation before the signal line is taken. The raw form, sometimes called fast stochastic, is too jumpy to trade directly — it can traverse the entire scale in a couple of bars. Crossovers between %K and %D are the conventional trigger, and the convention that carries the most weight is a crossover that happens inside an extreme zone rather than in the middle of the range.
Its natural habitat is a market that is oscillating within defined boundaries. Fading the extremes at a level that already matters structurally — a prior swing, a value area edge, a well-tested support band — is a coherent use. Applying the same rule in a trend is the classic beginner mistake, because in a trend the oscillator becomes embedded at one end of the scale and every countertrend crossover loses. This is why it is almost always paired with a regime filter such as ADX or a slope test on a longer moving average.
Compared with RSI, the Stochastic is faster, noisier and more literal about range position; compared with Williams %R it is nearly the same calculation with the sign flipped and smoothing added. Where RSI describes the balance of buying and selling force, the Stochastic describes only where the market chose to close relative to its recent envelope.
Calculation
The arithmetic in words, in the order it happens.
Raw %K = 100 x (close - lowest low over N bars) / (highest high over N bars - lowest low over N bars), where the highs and lows include the current bar. The default N is 14. In the fast form, %D is a 3-period simple moving average of raw %K. In the slow form that most charts display, raw %K is first smoothed with a 3-period simple moving average to produce the plotted %K, and %D is then a 3-period simple moving average of that smoothed line. When the highest high equals the lowest low the denominator is zero and the value is conventionally carried forward or set to 50.
Source
An AlgoBeamScript implementation of the formula above, written by us from the arithmetic so the code and the calculation agree line for line.
Runs unchanged on the platform and in the AlgoBeamTS runtime. The language reference is in the documentation.
Inputs
Defaults are the values most charting packages ship with. They are conventions, not optimal settings — the right length depends on your instrument and your holding period.
| Input | Default | What it changes |
|---|---|---|
| %K Length | 14 | Bars used to find the high-low range. Shorter windows make the oscillator hypersensitive because the range it normalises against is small and shifts constantly; longer windows produce a stable envelope and far fewer trips to the extremes. |
| %K Smoothing | 1 (fast) or 3 (slow) | Simple moving average applied to raw %K before plotting. Set to 1 you get the raw, whipsaw-prone line; 3 is the standard slow setting; 5 or more turns it into a slow swing indicator whose crossovers arrive well after the turn. |
| %D Smoothing | 3 | Length of the signal line taken from %K. Raising it separates the two lines and cuts down on crossovers, which reduces false triggers and delays the true ones by the same amount. |
| Overbought / oversold levels | 80 / 20 | Display lines only. In persistently trending instruments many users move them to 90/10 so that only genuine range edges register, and ignore signals in the direction opposite the trend entirely. |
How to read it
What practitioners take from the plot. Read these as descriptions of market state, not as entry signals.
- %K crossing above %D below 20
- Closes are starting to print higher in a range whose lower edge the market has just tested. The standard long trigger in a two-sided market; worth very little in a downtrend.
- %K crossing below %D above 80
- The mirror case. Closes are slipping back from the top of the range after an extended stay there.
- Embedded above 80 for many bars
- Not overbought — trending. Every close is printing near the top of the window. This is a signal to stop taking countertrend signals, not to sell.
- Failure to reach 20 on a pullback
- The range is losing symmetry to the upside: sellers can no longer drag closes back to the bottom of the window. Often an early hint that a range is resolving upward.
- Divergence at a range extreme
- Price made a new extreme but the close sat further inside the range than last time. Meaningful at a well-defined boundary; noise in the middle of a chart.
Limitations
Where this indicator misleads. None of these are fixed by a better parameter.
- It embeds in trends. Long stretches pinned at 100 or 0 render the extreme thresholds useless exactly when a countertrend trade is most expensive.
- It is blind to magnitude. A dead, two-tick range produces the same extreme readings as an explosive one, so signals from quiet periods are frequently meaningless.
- Crossovers are frequent. On intraday timeframes with fast settings the two lines cross constantly, and the resulting signal stream is dominated by transaction costs.
- The denominator can collapse. In a limit-locked or fully flat window the range is zero and the calculation is undefined, and platforms handle that edge case inconsistently.
Educational reference. This page explains how an indicator is built and how it is commonly read. It is not investment advice, not a recommendation and not a signal service. No indicator is profitable on its own — each is a way of describing a market, and any rule built on one has to be tested with realistic costs before it is traded.