KD indicator (Stochastic): formula, meaning and how to test it
KD measures where the close sits in the recent high–low range, then smooths it twice. It behaves differently in trends and ranges, so a KD rule is only worth trading after a precise backtest with costs and out-of-sample data.
By Soren Huang · Published · updated · Editorial policy
Contents
- What does the KD indicator actually measure?
- How are RSV, K and D calculated with the 9-3-3 setting?
- Why do KD values differ between platforms?
- What do overbought and oversold KD values mean?
- What entry and exit rules do traders build on KD?
- Why does KD behave so differently in trends and ranges?
- How do you backtest a KD rule with costs included?
- What do a good and a bad KD result look like?
- Frequently asked questions
- References
The KD indicator (the Stochastic oscillator) shows where the latest close sits inside the high–low range of the last nine bars, on a 0–100 scale. K smooths that position and D smooths K. Above 80 means closes near the top of the range, below 20 near the bottom. Only a backtest with costs shows whether a KD rule works.
What does the KD indicator actually measure?
KD measures position inside a recent range, not price direction and not trend strength. Think of the last nine bars as a room. The highest high is the ceiling and the lowest low is the floor. KD tells you how high the latest close is standing in that room.
In Taiwan the indicator is usually called KD (KD 指標), and its two lines are the K line and the D line (KD 線). When people ask what a stock's KD means (股票 KD 意思), they are asking this one thing: is the price closing near the top or the bottom of its recent range?
The same idea is known internationally as the Stochastic oscillator. The Stochastic indicator page covers the general family. This article focuses on the 9-3-3 KD version that is standard on Taiwanese charts, and on how to test it.
The bar size changes what "recent" means. On a daily stock chart, nine bars cover about two trading weeks. On a 5-minute futures chart, nine bars cover 45 minutes. The calculation is identical; the market behaviour it describes is not.
How are RSV, K and D calculated with the 9-3-3 setting?
KD is built in three steps: first RSV, then K, then D. The three numbers in 9-3-3 are the settings for these three steps.
RSV (raw stochastic value) is the position of the latest close between the lowest low and the highest high of the last 9 bars, expressed from 0 to 100. This is the only formula you need:
RSV = (C − L9) ÷ (H9 − L9) × 100
- C is the close of the current bar.
- L9 is the lowest low of the last 9 bars, including the current bar.
- H9 is the highest high of the last 9 bars, including the current bar.
An RSV of 100 means the bar closed exactly at the 9-bar high. An RSV of 0 means it closed at the 9-bar low.
RSV jumps around a lot, so KD smooths it. The K and D steps need no extra formula:
- K value: today's K moves one-third of the way from yesterday's K toward today's RSV. The "3" in the middle of 9-3-3 sets this one-third.
- D value: today's D moves one-third of the way from yesterday's D toward today's K. The last "3" sets this one-third.
- Starting value: on the first bar, when there is no yesterday, K and D are usually set to 50.
A thermostat is a good picture. It does not jump to the new temperature. Each step, it closes one-third of the gap. That is why K lags RSV, and D lags K.
Hypothetical example
Over the last 9 bars, the highest high is 110 and the lowest low is 90. The current bar closes at 105. RSV = (105 − 90) ÷ (110 − 90) × 100 = 75.
Yesterday's K was 60. The gap to RSV is 15. One-third of 15 is 5, so today's K is 65.
Yesterday's D was 55. The gap to today's K is 10. One-third of 10 is about 3.3, so today's D is about 58.3.
Why do KD values differ between platforms?
KD values (KD 值) can differ slightly between charting programs because the smoothing method is not the same everywhere. The table shows the two common versions.
| Step | Taiwan-style KD (9-3-3) | Common "slow stochastic" |
|---|---|---|
| Range lookback | 9 bars | Often 14 bars by default |
| K smoothing | Moves one-third of the way toward RSV each bar | Simple average of the last 3 RSV values |
| D smoothing | Moves one-third of the way toward K each bar | Simple average of the last 3 K values |
| Early bars | Depend on the starting value of 50 | Undefined until enough bars exist |
Two more details matter in a backtest. First, if the 9-bar high equals the 9-bar low, RSV divides by zero, and platforms handle this in different ways. Second, the starting value of 50 affects the first few dozen bars, so let the indicator warm up before the backtest takes any trades.
What do overbought and oversold KD values mean?
A KD above 80 means price has closed near the top of its recent range for several bars. A KD below 20 means it has closed near the bottom. Overbought is the name for the zone above 80, and oversold is the name for the zone below 20.
The names suggest that price "must" fall from overbought and rise from oversold. KD does not say that. It only says where recent closes were. Some traders use 70 and 30 instead of 80 and 20 to get more signals. Others treat 50 as a midline: K above 50 means closes in the upper half of the range.
| K and D reading | What it describes | What it does not tell you |
|---|---|---|
| Both above 80 | Several closes near the top of the 9-bar range | That a fall is coming |
| Both below 20 | Several closes near the bottom of the 9-bar range | That a rise is coming |
| K crosses above D | Recent closes are rising faster than the smoothed average | How far the move will go |
| K near 50 | Closes in the middle of the range | Whether a trend is starting |
What entry and exit rules do traders build on KD?
Most KD strategies are built from a few standard rules, and each one needs an exact definition before it can be tested. A rule block is a single, precisely defined piece of a strategy, such as one entry condition or one exit condition, that can be combined with other pieces.
| Rule | Long entry | Typical exit | Where it struggles |
|---|---|---|---|
| Low-zone golden cross | K crosses above D while both are below 20 | K crosses below D, or K rises above 80 | Downtrends, where it buys again and again too early |
| Zone exit | K rises back above 20 after being below it | K falls back below 80 after being above it | Choppy markets near the 20 line |
| Midline cross | K crosses above 50 | K crosses below 50 | Ranges, where it flips often |
| Trend-filtered pullback | ADX shows a strong trend, price is above a long moving average, and K crosses up from below 20 (see the ADX trend-strength indicator page) | Opposite cross, a stop loss, or a time limit | Turning points, where the filter is late |
| Divergence | Price makes a lower low while K makes a higher low | Fixed target or opposite cross | Hard to define exactly, so hard to test fairly |
Short entries mirror these rules. A golden cross (黃金交叉) is K crossing above D, and a death cross (死亡交叉) is K crossing below D.
Exits matter as much as entries. A KD cross alone often exits late in fast moves, so many traders combine it with a stop loss or a maximum holding time. Each added exit is another rule block, and another choice that must be tested rather than assumed.
Why does KD behave so differently in trends and ranges?
KD works as a turning signal mainly in sideways markets, and in strong trends it stays stuck near one extreme. The reason is in the calculation. In a steady uptrend, each close is near the top of the last nine bars, so RSV stays high and K stays above 80 for a long time.
Taiwanese traders call this passivation (鈍化). Passivation is the state in which K and D stay pinned in the overbought or oversold zone while the trend continues. A rule that sells every time K is above 80 keeps selling into a rising market.
In a range, the ceiling and floor of the 9-bar room stay roughly in place. Price bounces between them, and KD swings between 20 and 80 with it. This is the environment the overbought and oversold rules were made for.
KD has other limits a tester should know:
- It lags. D is a smoothing of a smoothing, so D crosses come after the price turn.
- It ignores volume and the size of the range. A 9-bar range of 5 points and one of 200 points can give the same KD value.
- It crosses often. On short bars, many crosses mean many trades, and many trades mean high total costs.
How do you backtest a KD rule with costs included?
Test KD as a precise rule block, with costs and next-bar execution from the first run, and judge it on data it was not tuned on. Follow these steps in order:
- Write the rule exactly. For example: "On bar close, if K crosses above D and both are below 20, buy one contract at the next bar's open."
- Fix the KD version. Lookback, smoothing method, starting value and warm-up bars, as in the table above.
- Execute on the next bar. A cross is only known when the bar closes, so filling at that same close uses a price you could not trade.
- Include all costs per round trip. Commission, exchange fees, taxes where they apply, and slippage on both entry and exit. The guide to trading costs in backtests shows how to estimate them.
- Keep parameter ranges small and count them. For example, lookbacks of 7 to 12 bars and zones of 15/85 to 25/75. Write down how many variants you tested.
- Test out of sample. Tune on one period and test on the following one. Walk-forward analysis repeats this across the whole history.
- Stress the result. Rerun with double slippage and with neighbouring parameters such as 8-3-3 and 10-3-3.
Counting variants matters because searching many rules on the same data makes the best one look better than it is. Sullivan, Timmermann and White (1999) studied this for technical trading rules. They used a resampling test, which reshuffles the historical data many times to see how good the best rule would look by luck alone, across the whole set of rules searched. Their work built on White's (2000) reality check for data snooping.
What do a good and a bad KD result look like?
| Check | Encouraging result | Weak result |
|---|---|---|
| Neighbouring parameters | 8-3-3, 9-3-3 and 10-3-3 behave similarly | Only one exact setting works |
| Average trade vs. cost | Gross average trade is several times the round-trip cost | Gross average trade is close to the cost |
| Double slippage | Result shrinks but stays positive | Result turns negative |
| Out of sample | Behaviour similar to the tuning period | Edge disappears after the tuning period |
| Trend vs. range periods | You can explain where it gains and where it loses | One period carries the whole result |
Hypothetical example
Rule A is a plain golden cross on 60-minute futures bars. It makes 500 trades with a gross average of 3 points per trade. Commission, fees and one point of slippage cost 2 points per round trip, so the net average is 1 point. With slippage doubled, the cost is 3 points and the net average is 0.
Rule B adds a trend filter. It makes 200 trades with a gross average of 6 points. After the same 2-point cost, the net average is 4 points. With slippage doubled, it is 3 points.
Rule B is not proven by this. It has simply passed one check that Rule A fails, and it still needs out-of-sample testing.
Testing a few KD variants by hand is practical. Testing every combination of lookback, zones, exits and filters is not; that is where tools for strategy generation and backtesting come in, because they can run many precisely defined rule combinations with costs and next-bar execution included.
What this means if you use AlphaPrime (Valynox): treat KD as one rule block among many, give it narrow parameter ranges, and keep realistic fees and slippage in the search settings from the first run. Then judge the survivors on out-of-sample results and neighbouring parameters, not on the single best backtest.
Frequently asked questions
What does a KD value of 80 or 20 mean?
A KD value of 80 means recent closes have been near the top of the last nine bars' high–low range. A value of 20 means they have been near the bottom. These levels describe where price has been closing. They do not predict a reversal, especially during strong trends.
What is the KD indicator formula?
First calculate RSV: the close minus the 9-bar lowest low, divided by the 9-bar range, times 100. Then K moves one-third of the way from its previous value toward RSV each bar. D moves one-third of the way from its previous value toward K. K and D usually start at 50.
Is the KD indicator the same as the Stochastic oscillator?
KD is a version of the Stochastic oscillator. The Taiwan-style KD usually uses a 9-bar lookback and one-third recursive smoothing. Many other platforms use a 14-bar lookback and simple 3-bar averages. The readings are similar but can cross on different bars.
What does KD passivation (鈍化) mean?
Passivation means K and D stay in the overbought zone above 80, or the oversold zone below 20, while the trend continues. It happens because each new close stays near one end of the recent range. During passivation, rules that sell overbought or buy oversold readings tend to fail.
Can KD be used for day trading futures?
The calculation works on any bar size, including 1-minute or 5-minute futures bars. Short bars produce many crosses, so trading costs take a large share of each trade. Test intraday KD rules with full round-trip costs and next-bar execution before judging them.
References
- Sullivan, R., Timmermann, A., & White, H. (1999). Data-Snooping, Technical Trading Rule Performance, and the Bootstrap. The Journal of Finance, 54(5), 1647–1691.
- White, H. (2000). A Reality Check for Data Snooping. Econometrica, 68(5), 1097–1126.
What AlphaPrime does here
AlphaPrime's strategy generation turns ideas such as KD crosses into testable rules with parameter ranges and entry and exit conditions. AlphaPrime's backtesting evaluates them in batches with fees, slippage, next-bar execution and trading sessions included.

