# Stochastic %D

> The %D line of the stochastic oscillator on its own: a moving average of where the close sits within the recent high-low range, from 0 to 100.

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

## What you see
One line in its own pane plus two horizontal reference lines at 80 and 20. The pane scales to the lowest and highest %D of the visible candles, so the 80 and 20 lines move with the scale and can lie outside the pane. 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 (1 = no smoothing).
3. `%D`: simple average of the smoothed %K over `Period %D` candles.

With the defaults, %D is the 3-candle average of a 9-candle %K. 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
- Above 80 the close has been near the top of its recent range (overbought), below 20 near the bottom (oversold). In trends it can stay there.
- %D is smoother than %K, so it turns later but with fewer false turns. To see %K and %D together, use the [Stochastic](https://chartrider.com/docs/indicators/stochastic/).
- The classic signals are turns back out of the 80 and 20 zones, and divergences.

## Using it in strategies
Output: `value` (%D, 0 to 100). In the [Trade Setup](https://chartrider.com/docs/strategies/trade-setup/), "Against" with center 50 and x −30 allows longs only at 20 or lower and shorts only at 80 or higher; "Compare" checks a level. In [WickScript](https://chartrider.com/docs/wickscript/) the built-in `stoch(length, smoothK, smoothD)` returns `.k` and `.d`, so `stoch(9, 1, 3).d` is this line; or use `use indicator "StochD" with period 9, periodD 3 as sd` and read `sd.value`.

## 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 before %D is calculated (1 = raw %K). (min 1) |
| Height | Number | `70` | 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 |
|---|---|---|---|
| Line Color | Color | `#0f6347` |  |
| Line Color overbought | Color | `#630F0F` | Color of the reference line at 80. |
| Line Color Oversold | Color | `#210F63` | 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` |  |

## 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 %D from the list" in pane
use indicator "StochD" with period 9 as myStochd
show myStochd.value as line "value"
```
