KDJ Indicator

Calculate the KDJ indicator: the Stochastic Oscillator’s %K and %D with the J line that leads them, to show overbought and oversold levels and turning points.

The KDJ indicator is a stochastic oscillator, widely used in Chinese and other Asian markets, that smooths the raw stochastic with Wilder’s average instead of a simple one and adds a third line, J, which extrapolates K away from D. J leaves the 0 to 100 range when the momentum is strong, so J above 100 (or below 0) is read as overbought (or oversold) before K and D get there, and K crossing D is the trade signal, as with the stochastic.

The formula is as follows:

\[\text{RSV} = \frac{100 \cdot (\text{Close} - \text{Lowest Low}(\text{window}))}{\text{Highest High}(\text{window}) - \text{Lowest Low}(\text{window})}\] \[K = \text{Wilder's MA}(\text{RSV},\; k_{\text{window}})\] \[D = \text{Wilder's MA}(K,\; d_{\text{window}})\] \[J = 3 \cdot K - 2 \cdot D\]

Wilder’s moving average is the recursion \(K (t) = K (t - 1)\) + (RSV(t) - K(t - 1)) / k_window, written SMA(RSV, 3, 1) in the formula language of Asian charting platforms. The KDJ has no single primary source; it extends Lane’s stochastic (see get_stochastic_oscillator).

Also known as: KDJ, KDJ stochastic, random index.

Example · AAPL, MSFT · 2024 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_kdj_indicator:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2024-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_kdj_indicator().xs("AAPL", level=1, axis="columns")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What did the KDJ indicator of Apple show in 2025?

Which returns:

Parameters

get_kdj_indicator accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”, in which case the high and low prices are adjusted for dividends in the same way."Close"
windowintThe number of periods of the high-low range of the RSV. Defaults to 9.20
k_windowintThe number of periods of Wilder’s average of the RSV that gives K. Defaults to 3.3
d_windowintThe number of periods of Wilder’s average of K that gives D. Defaults to 3.3
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the K, D and J. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Lane, G.C. (1984). “Lane’s Stochastics.” Technical Analysis of Stocks & Commodities, 2(3).
  • Library Referenced against TA-Lib’s KDJ
  • Library Shares similar logic as pandas-ta-classic’s kdj
Share