# Stochastic

> Stochastic oscillator with %K, smoothed %K and %D lines: where the close sits within the high-low range of the last candles, from 0 to 100.

Updated: 2026-10-25T00:01:52.000Z · https://chartrider.com/docs/indicators/stochastic/

## What you see
Three lines in their own pane, %K, smoothed %K and %D, each with its own color, plus reference lines at 80 and 20. The pane scales to the lowest and highest %K and smoothed %K of the visible candles. With `Period Smoothing` at 1, smoothed %K equals %K and the two lines lie on top of each other. Green and red lines mark divergences between price and %D.

## How it is calculated
1. `%K = 100 × (close − LL) / (HH − LL)`, where HH and LL are the highest high and lowest low of the last `Period %K` candles, the current one included. If HH equals LL, %K is 0.
2. Smoothed %K: simple average of %K over `Period Smoothing` candles.
3. `%D`: simple average of the smoothed %K over `Period %D` candles.

Smoothing 1 gives the "fast" stochastic; smoothing 3 gives the "slow" stochastic, whose %K is the fast %D. Divergences compare %D with the close, using `Period %K` as the swing window and the same rules as the [RSI](https://chartrider.com/docs/indicators/rsi/).

## How to read it
- %K crossing above %D below 20 is the classic buy signal, %K crossing below %D above 80 the classic sell signal.
- Overbought and oversold readings can last a long time in trends; a trend filter helps.
- Divergences between price and %D hint at a weakening move.

## Using it in strategies
Outputs: `k`, `smoothedK`, `d`, and `value`, which is also %D. In the [Trade Setup](https://chartrider.com/docs/strategies/trade-setup/), "Compare" can check `smoothedK` against the line `d`; as a trigger it fires when smoothed %K moves above %D. "Range" or "Against" on `d` work as overbought/oversold filters. In [WickScript](https://chartrider.com/docs/wickscript/), `s = stoch(9, 1, 3)` gives `s.k` (the smoothed %K) and `s.d`, e.g. `s.k crosses above s.d`. With `use indicator "Stoch" with period 14, periodSmooth 3 as st` you read `st.k`, `st.smoothedK` and `st.d`.

## Settings

Open the settings with the slider icon next to the indicator (Indicators, `F3`). Numeric settings can be swept as Step 1 / Step 2 parameters when you run a strategy.

### Inputs

| Setting | Type | Default | Description |
|---|---|---|---|
| Period %K | Number | `9` | Candles for the high-low range of %K. Also the swing window for divergence detection. (min 1) |
| Period %D | Number | `3` | Candles in the simple average that turns the smoothed %K into %D. (min 1) |
| Period Smoothing | Number | `1` | Candles in the simple average applied to %K (1 = fast stochastic, 3 = slow stochastic). (min 1) |
| Height | Number | `50` | Height of the pane in pixels. (min 10) |
| Look Back Range | Number | `2` | Candles after a swing point that are checked before the swing counts for a divergence. Higher values give fewer, later divergences. (min 1) |

### Styles

| Setting | Type | Default | Description |
|---|---|---|---|
| %D Line Color | Color | `#26bf8cff` |  |
| %K Line Color | Color | `#6B3AD1ff` |  |
| %K Smoothing Line Color | Color | `#9c7070ff` |  |
| Line Color overbought | Color | `#bd1c1cff` | Color of the reference line at 80. |
| Line Color Oversold | Color | `#5f38edff` | Color of the reference line at 20. |

## Outputs

These values can be used in Trade Setup triggers, filters and exits (see [Trade Setup](https://chartrider.com/docs/strategies/trade-setup/)) and in WickScript.

| Output | In WickScript | Description |
|---|---|---|
| value | `value` | %D, the same line as `d`. |
| k | `k` | Raw %K. |
| smoothedK | `smoothedK` | %K after the `Period Smoothing` average. |
| d | `d` | %D, the average of the smoothed %K. |

## Use in WickScript

`use indicator` creates this indicator inside a script, with settings by their ID. Each output is a field of the name after `as`. See [WickScript indicators](https://chartrider.com/docs/wickscript/indicators/).

```wickscript
wickscript 1
indicator "Stochastic from the list" in pane
use indicator "Stoch" with period 9 as myStoch
show myStoch.value as line "value"
```
