Skip to main content
  • Pricing
Tutorials

KDJ indicator explained: how the K, D and J lines are built and read

By Oakgen TeamPublished 3 min read

Share
KDJ indicator explained: how the K, D and J lines are built and read

The KDJ indicator is a stochastic oscillator with a third line added. K and D behave like the familiar %K and %D lines, and J is calculated as 3K minus 2D, so it swings further and sooner than either of them. This guide covers how each line is built, which settings are common, and why the same chart can show different KDJ values on different platforms. It is educational material, not trading advice.

How the three lines are built

TA-Lib's reference defines the raw input, called RSV, as 100 x (Close - LL) / (HH - LL), where LL is the lowest low and HH the highest high over a lookback window of n bars. K is a moving average of RSV, D is a moving average of K, and J = 3K - 2D. Capital.com describes the classic recursive version in words: K is a one-third exponential smoothing of RSV against the previous K, D applies the same smoothing to K, and both start at 50.

LineBuilt fromHow it behaves
KRSV, smoothedTracks where price closed inside its recent range
DK, smoothedThe smoothest line, used as the signal line
J3K - 2DThe most sensitive line, not limited to 0-100

A worked example with invented prices: if the highest high over the window is 120, the lowest low is 100 and the close is 115, then RSV = 100 x (115 - 100) / (120 - 100) = 75. Now take K and D values. With K = 30 and D = 40, J = 3 x 30 - 2 x 40 = 10. With K = 80 and D = 70, J = 100. With K = 90 and D = 60, J = 150, and with K = 10 and D = 40, J = -30. Rearranged, J = K + 2(K - D): it is K pushed away from D by twice the gap between them, which is why it overshoots the 0-100 band.

Common settings

TA-Lib's documented defaults are a 9-bar lookback, a 3-period smoothing for K and a 3-period smoothing for D, with Wilder's moving average (RMA) as the default smoother for both stages. Capital.com calls 9 the most common lookback for swing traders on daily or 4-hour charts, says a shorter period such as 5 raises sensitivity and false signals, and says a longer one such as 14 suits position trading but lags at turning points.

For comparison, TradingView's plain Stochastic defaults to a K period of 14, a D period of 3 and a smoothing of 3. The MetaTrader 5 help describes the same family of controls: %K periods, %K slowing (1 gives a fast stochastic, 3 a slow one), %D periods and a choice of Exponential, Simple, Smoothed or Weighted averaging for %D. TA-Lib adds that setting both of its smoothers to a simple moving average reproduces the classic slow stochastic with a J line attached.

How the lines are read

Capital.com uses 20 and 80 as reference zones. When K, D and J all sit above 80 the instrument is generally considered overbought, and below 20 possibly oversold. J above 100 or below 0 is described as a heavier version of the same condition. A golden cross (K crossing above D, most meaningful below 20) is its main bullish signal, a death cross above 80 its main bearish one, and crossovers in the 40-60 middle band carry little weight.

The platform documentation is more guarded. MetaTrader's help gives 20 and 80 only as example levels, mentions %K crossing %D, and describes divergence: price making new highs while the oscillator fails to exceed its previous highs can signal weakening momentum. TradingView warns that overbought or oversold readings "can be a sign of a strengthening trend and not necessarily an impending reversal." Capital.com agrees the indicator works best in range-bound markets and that K and D can sit at extremes for long periods in a trend. It treats J extremes as alerts rather than automatic reversal signals.

Why two platforms show different numbers

  • Smoothing type. RMA, SMA and EMA smoothers give different K and D from the same RSV.
  • Seeding. TA-Lib seeds its first RMA value with the simple average of the first N inputs and notes that other platforms seed differently, so early values can differ for several dozen bars. Capital.com's description starts K and D at 50.
  • Flat windows. If the high-low range over the window is zero, TA-Lib sets the raw value to 0 rather than leaving it undefined. Other code may treat it differently.
  • Parameters. A 9-3-3 script and a 14-3-3 stochastic will never match.

A checklist before trusting any KDJ script

  1. Read the three periods and the smoothing type from the inputs or the source code.
  2. Recompute RSV by hand for two or three bars and compare it with the plotted value.
  3. Check that J can leave the 0-100 band; if it never does, it has probably been clamped.
  4. Test any rule on a demo account first. Capital.com suggests this, and MetaTrader's help suggests testing signals by building an Expert Advisor in the MQL5 Wizard.

Capital.com's own page states that the indicator "should not be used in isolation when making trading decisions" and carries a risk warning that 69% of retail investor accounts lose money trading spread bets and CFDs with that provider. MetaQuotes notes that it provides no investment or brokerage services.

Take this further with Oakgen Agent

Agent can explain the formulas, run the calculation in a Python sandbox, and create a downloadable xlsx or csv from prices you provide.

Coming soon: A live price chart with indicator overlays or an MT4/MT5 indicator installer is not available in Agent yet.

Looking for a recap of one specific YouTube video? The YouTube Summarizer does that today.

Open this task in Oakgen Agent

The prompt is filled in for you. Nothing is sent until you press send.

Open in Oakgen Agent

Frequently asked questions

What is the KDJ indicator?

KDJ is a momentum oscillator that extends the stochastic oscillator with a third line. Capital.com describes it as a stochastic oscillator plus a J line, and TA-Lib's reference gives the same structure: a raw value (RSV) is smoothed into K, K is smoothed into D, and J is derived from the two. K and D work like the %K and %D lines of a stochastic oscillator.

What is the formula for the J line?

J = 3K - 2D, which is the same as K + 2(K - D). TA-Lib's documentation states the formula and describes J as three parts K less two parts D. Because it is not clamped, J can read above 100 or below 0, while K and D usually stay inside 0 to 100.

Which settings does KDJ usually use?

TA-Lib's defaults are a 9-bar lookback for the raw value, then a 3-period smoothing for K and a 3-period smoothing for D, with Wilder's moving average (RMA) as the default smoother. Capital.com also names 9 as the most common lookback and says 5 is more sensitive with more false signals, while 14 lags more at turning points. TradingView's plain Stochastic defaults to 14, 3 and 3.

Why does KDJ look different on two platforms?

The inputs may match but the smoothing can differ. TA-Lib notes that its default Wilder smoothing is seeded with a simple average of the first N inputs and that other platforms seed differently, so early values can differ for several dozen bars. Choosing a simple moving average for both smoothers reproduces the classic slow stochastic with a J line attached, so always check which smoothing a script uses.

Is a K and D crossover a buy or sell signal?

Treat it as one input, not an instruction. Capital.com calls a K cross above D below 20 the primary bullish signal and the reverse above 80 the primary bearish one, but it also warns that in strong trends K and D can stay at extremes and that the indicator should not be used in isolation. TradingView's documentation adds that overbought readings can signal a strengthening trend rather than a reversal.

Sources

  1. TA-Lib, KDJ Stochastic (KDJ) function reference (read 2026-11-19)
  2. Capital.com, What is the KDJ indicator and how does it work? (read 2026-11-19)
  3. MetaQuotes, MetaTrader 5 Help: Stochastic Oscillator (read 2026-11-19)
  4. TradingView Support, Stochastic (STOCH) (read 2026-11-19)
Share