# Stochastic Oscillator (Stochastic)

Category: momentum

The Stochastic Oscillator compares a security's closing price to its price range over a given period. It measures momentum and identifies overbought/oversold conditions, oscillating between 0 and 100.

## Formula

```text
%K = 100 × ((Close - LowestLow(N)) / (HighestHigh(N) - LowestLow(N)))
%D = SMA(3) of %K
where N = lookback period (default 14)
```

## Common strategies

- Overbought/oversold: %K > 80 suggests overbought (sell), %K < 20 suggests oversold (buy).
- %K/%D crossover: %K crossing above %D in oversold territory is bullish; crossing below in overbought territory is bearish.
- Divergence: Price makes a lower low but Stochastic makes a higher low — bullish divergence signaling potential reversal.

## How CommonQuant uses it

CommonQuant pre-calculates Stochastic(14, 3) on all timeframes. DSL strategies can reference stoch_k() and stoch_d() functions for %K and %D respectively.

## Frequently asked questions

### What is the difference between Stochastic and RSI?

Both are momentum oscillators (0-100), but Stochastic compares close to the price range, while RSI measures the ratio of gains to losses. Stochastic is more sensitive in ranging markets; RSI is better for trend strength.

### What are fast vs slow Stochastic?

Fast Stochastic uses raw %K, which is very volatile. Slow Stochastic (the default) smooths %K with a 3-period SMA, producing fewer but more reliable signals.

Canonical: https://commonquant.ai/learn/indicators/stochastic
