全職奶爸

KDJ Indicator: J-Line Formula, 9/3/3 Settings and TradingView Code

KDJ indicator: J-line formula, 9/3/3 settings and TradingView code

TRADINGVIEW INDICATOR GUIDES

The KDJ indicator combines a range-based K line, a slower D line and an amplified J line. In the recursive version below, J = 3K − 2D. A 9/3/3 setup uses nine candles for the price range and a one-third smoothing weight for each of the other two calculations. J can rise above 100 or fall below zero without a calculation error.

The extra line can make a change in momentum easier to spot. It also creates an easy misunderstanding: a J/D cross and a K/D cross are not separate confirmations when J uses that formula. They happen together. Before building a trading rule around KDJ, establish which formula your chart uses and what price must do before you act.

What K, D and J actually measure

KDJ starts with the close's position inside a recent high-to-low range. This raw stochastic value, or RSV, equals 100 when the close matches the range high and zero when it matches the range low. A reading of 50 places the close halfway between those two prices. RSV does not measure how much money traded, the likelihood of a reversal or the distance to your stop.

For a nine-candle lookback, use the highest high and lowest low of the current candle plus the previous eight candles. This is a window of nine observations. At the current candle, calculate:

RSV = 100 × (Close − Lowest low over 9 candles) ÷ (Highest high over 9 candles − Lowest low over 9 candles)

K = ⅔ × previous K + ⅓ × current RSV

D = ⅔ × previous D + ⅓ × current K

J = 3 × current K − 2 × current D

Both smoothing steps use the current input: K uses the current RSV, then D uses the K just calculated for that candle. Using yesterday's K in the second step produces a different series. This order matters when checking a spreadsheet against a chart.

The supplied script starts its stored K and D values at 50, waits for a complete nine-candle window and then plots the calculation. If the range high equals the range low, it uses neutral RSV 50. That is an explicit choice for an otherwise undefined division, not a rule that every KDJ implementation follows.

This recursive formula and the initial values are described in Futu's KDJ explanation. You may also encounter studies that build J from a slow Stochastic pair; CQG's KDJ description uses that approach. A shared indicator name does not guarantee matching outputs.

For the underlying range calculation and ordinary K/D reading, see the Stochastic oscillator guide. This article focuses on the added J line and the particular recursive calculation you can reproduce below.

A worked 9/3/3 example: why J leaves the 0–100 range

Imagine a sequence where every nine-candle range has a high of 110 and a low of 90. A close of 100 gives RSV 50; a close of 110 gives RSV 100; a close of 90 gives RSV zero. Start K and D at 50 before the first calculation. The following nine steps are constructed numbers, not a historical trade.

StepCloseRSVKDJ
01005050.0050.0050.00
111010066.6755.5688.89
211010077.7862.96107.41
311010085.1970.37114.81
490056.7965.8438.68
590037.8656.520.55
690025.2446.09−16.46
790016.8336.34−22.19
811010044.5539.0755.50

At step 1, K is two-thirds of 50 plus one-third of 100, which gives 66.67. D then uses that new K: two-thirds of 50 plus one-third of 66.67 gives 55.56. J equals three times 66.67 minus twice 55.56, or 88.89. Calculations retain full precision; the table rounds only the displayed answers.

The J line amplifies the K/D gapOriginal hypothetical nine-step recursive KDJ path from seed50. K blue, D gold, J purple. All lines share one scale; J rises above100 and below0. Values match the worked table.The J line amplifies the K/D gapHYPOTHETICAL · Same axis · Seed K = D = 50-2002080100120012345678StepKDJJ reaches 114.81 and −22.19; K and D stay within 0–100.Constructed RSV sequence: 50, 100, 100, 100, 0, 0, 0, 0, 100.

By step 2, J reaches 107.41 even though both K and D remain below 100. Later, J falls below zero while K and D stay positive. Nothing in the J formula clips it to the raw range scale. It extends the distance between K and D, so a wide gap creates an extreme J reading.

A J reading of 114.81 does not mean price is 14.81% above fair value. A negative J reading does not mean the asset has a negative price. These are oscillator values derived from the same prices already used for K and D. With valid RSV values and starting values inside 0–100, recursive K and D stay inside that interval; J need not.

J is sometimes called “unbounded.” The practical point is that it is not confined to 0–100. It is still an algebraic function of bounded inputs: if K and D both lie in that interval, the loose bound from the formula is −200 to 300. That is not a promise that every value in that wider interval is reachable under this smoothing sequence.

A J-line cross is not an extra independent signal

Rewrite the formula as J = K + 2(K − D). J sits beyond K in the direction of the K/D gap. If K is 70 and D is 60, J is 90. If K is 50 and D is 60, J is 30. When K and D meet at 60, J also equals 60.

J − D = 3(K − D)

J − K = 2(K − D)

Those identities mean all three pairwise comparisons change sign together. Under the same calculation and candle sampling, J crossing D cannot occur before K crosses D. Nor does J crossing K add a separate vote. A chart may make one intersection easier to see because of line width, colors or rounding, but the algebra has not created new market information.

Three lines, one crossover eventAlgebraic schematic, not historical data: K70,60,50; D60 throughout; J90,60,30. All three meet at60. J-D=3(K-D) and J-K=2(K-D).Three lines, one crossover eventHYPOTHETICAL · D held at 60 to show the identity306090K = D = J = 60K above DSame intersectionK below DKDJJ − D = 3(K − D) · J − K = 2(K − D)Three pairwise crosses are one event, not three confirmations.

J can turn upward while K remains below D. That is a change in slope, not a completed upward crossover. In the worked example, J jumps from −22.19 at step 7 to 55.50 at step 8; at step 8, K also moves above D. Other sequences can produce a J turn without any K/D cross. Define whether your rule means a turn, a threshold crossing or a K/D crossover.

Repeated touches also need a precise rule. One workable definition for an upward cross is previous K less than or equal to previous D, and current K greater than current D. A downward cross reverses those comparisons. Merely seeing K above D means a positive relationship exists; it does not mean a new cross occurred on that candle.

Some scripts use different J coefficients, a separate smoothing step or another timeframe. Their crossings can behave differently. For example, 3D − 2K gives 40 when K is 70 and D is 60, whereas 3K − 2D gives 90. Check the actual code before transferring a rule between studies.

What 9/3/3 settings mean, and why two charts can disagree

The first input controls the RSV window. Increasing it includes more candles in the high/low search, so an older extreme can remain relevant longer. Decreasing it replaces that range more quickly. The last two inputs control smoothing divisors in this reference, not extra price windows. A divisor of three gives the new input one-third of the weight.

ChoiceCalculationWhat to check
Reference KPrevious K × ⅔ + current RSV × ⅓Recursive history; initial K is 50
Reference DPrevious D × ⅔ + current K × ⅓Uses the newly calculated K
Simple average, length 3Mean of the latest three inputsA finite window; different from this recursion
EMA, length 3New-input weight 2 ÷ (3 + 1) = ½A standard EMA 3 is not the one-third update
Reference J3K − 2DDifferent signs or coefficients change the line
Flat nine-candle rangeRSV 50 in this scriptOther implementations can use another policy

Writing “9/3/3” is therefore not enough to reproduce another person's chart. Match the smoothing kernel, seed, available history and J formula as well as the three numbers. A study using two simple moving averages will differ from this one even when both display 9, 3 and 3 in their settings.

The initial seed matters most near the beginning of a calculation. With the same subsequent RSV inputs, the effect of a K starting-value difference shrinks by a factor of two-thirds on each update when its divisor is three. D receives the evolving K difference as well, so matching only a few recent candles does not guarantee identical startup values.

Price data can differ too. Compare the same symbol, exchange, session, timeframe and candle timestamps. A continuous futures chart and a specific contract can contain different historical prices. If a chart exports only its visible tail, earlier data may still have contributed to the recursive values. Do not reset your spreadsheet to 50 at the first exported row and assume the chart did the same.

A 9-candle calculation on a 15-minute chart uses nine 15-minute candles. It does not mean nine trading days or a fixed clock-time session. The current candle's close, high and low can change until it closes, so its K, D and J can also change. A closed-candle rule waits for that candle to finish before evaluating the signal.

Add the reference KDJ script to TradingView

The script below is a Pine Script version 6 indicator named Recursive KDJ Reference. It plots K, D and J in a separate pane and exposes RSV in the Data Window. It places no orders. The code is supplied here so you can see the formula; you do not need to find a similarly named community study.

Open your chart and the Pine Editor. Open the script menu, choose Create new → Indicator, replace the starter code with the complete code below, and select Add to chart. Save it as Recursive KDJ Reference if you want to reuse it. The chart should show a separate pane labelled Recursive KDJ 9 3 3.

Double-click the study name to open its settings. In Inputs, set RSV lookback to 9, K smoothing divisor to 3 and D smoothing divisor to 3. This script follows the chart timeframe; it has no separate higher-timeframe input.

Recursive KDJ Inputs in TradingView with RSV lookback 9 and K and D smoothing divisors 3
Inputs for the supplied reference script: lookback 9, K divisor 3 and D divisor 3.
//@version=6
// Educational reference for homedadpro.com. Plots only; no orders.
indicator("Recursive KDJ Reference", shorttitle="Recursive KDJ", overlay=false)

n = input.int(9, "RSV lookback", minval=1)
mK = input.int(3, "K smoothing divisor", minval=1)
mD = input.int(3, "D smoothing divisor", minval=1)

hh = ta.highest(high, n)
ll = ta.lowest(low, n)
ready = bar_index >= n - 1
// Declared policy: a zero-width range uses neutral RSV 50.
rsv = ready ? (hh == ll ? 50.0 : 100.0 * (close - ll) / (hh - ll)) : na
alphaK = 1.0 / mK
alphaD = 1.0 / mD
var float k = 50.0
var float d = 50.0
if not na(rsv)
    k := (1.0 - alphaK) * nz(k[1], 50.0) + alphaK * rsv
    d := (1.0 - alphaD) * nz(d[1], 50.0) + alphaD * k
j = 3.0 * k - 2.0 * d

plot(not na(rsv) ? k : na, "K", color=color.rgb(41, 98, 255), linewidth=2)
plot(not na(rsv) ? d : na, "D", color=color.rgb(176, 121, 22), linewidth=2)
plot(not na(rsv) ? j : na, "J", color=color.rgb(147, 65, 190), linewidth=2)
plot(rsv, "RSV", display=display.data_window)
hline(80, "Upper reference", color=color.gray, linestyle=hline.style_dashed)
hline(20, "Lower reference", color=color.gray, linestyle=hline.style_dashed)
hline(100, "100", color=color.new(color.gray, 65))
hline(0, "0", color=color.new(color.gray, 65))

K is blue, D is gold and J is purple. The dashed 20 and 80 levels are reference lines, and zero and 100 help you see J's excursions. The script does not generate buy or sell labels. Its flat-range policy and seed are declared in the code, so comparisons with other versions can start from a clear definition.

NQ futures 15-minute TradingView chart with the Recursive KDJ reference in a separate pane and blue K gold D purple J lines
The reference study below an NQ 15-minute chart. J extends beyond K and D; this chart illustrates the display, not a trade result.

If the editor reports an error, check that the first line is the version declaration and that the whole code block was copied. Paste the code into an indicator file rather than a strategy or an existing script with another declaration. If the pane differs from another KDJ, compare the calculation choices in the table before changing the numbers to force a visual match.

For managing panes and finding other studies, use the TradingView indicators guide. Save the layout after you have the display you want, especially if you use different indicator sets for different chart purposes.

How to use KDJ without turning an extreme into an entry

Start with the price decision. A range trade needs a range boundary and a reason to expect it to hold. A trend-continuation trade needs a trend definition and a pullback area. KDJ can describe what momentum is doing near that location, but an extreme reading alone supplies neither the location nor the invalidation price.

Suppose price is approaching the lower boundary of a range you have already marked. J below zero shows that K is far below D; it does not prove sellers are finished. You could require a completed candle to reclaim the boundary and K to cross above D before considering an entry. That is a testable example rule, not a claim that those conditions have a profitable edge.

In a strong trend, price can keep closing near the end of its rolling range. K and D can remain high or low for an extended period, while J stretches and contracts around them. Treating each reading above 80 as a short signal can repeatedly oppose an intact uptrend. State which line uses the threshold and what price action must change.

For divergence, compare two identified price swing highs with the corresponding oscillator highs, or two swing lows with the corresponding oscillator lows. A higher price high and a lower J high describe weakening oscillator confirmation of that push. They do not tell you when a reversal will start. If the second swing is still forming, the comparison can change.

Combining KDJ with another oscillator does not automatically create independent evidence. RSI uses a different calculation based on upward and downward changes, but it still comes from price. Decide which question each tool answers. Three versions of “momentum is weakening” can be less useful than one oscillator plus a clear price level and a defined stop.

The distinction is especially useful when comparing KDJ with Momentum (MOM). KDJ locates the close within a rolling range before smoothing it. Basic MOM subtracts a previous close from the current close. Those outputs have different units and reference levels, so a KDJ 80 and a MOM 80 are not interchangeable.

Keep the position-size decision separate. In a hypothetical trade with entry 111.50 and invalidation at 108.00, the price distance is 3.50. A two-times-distance target would be 118.50 before costs. The permitted size still depends on the instrument's point value, your loss limit and fees. Use the position sizing guide and calculator to translate the actual stop distance into size.

Record the exact variant, inputs, symbol, timeframe, session, entry trigger, invalidation and exit rule before testing. Evaluate signals on the information available at the decision time. Include trading costs and missed or ambiguous setups, then compare results across different market conditions. A clean screenshot of a successful cross is not a test of the rule.

Choosing settings for a real decision

Use 9/3/3 as a reproducible starting specification, not as a universally best configuration. A shorter RSV window can react to nearby prices faster, but also replaces extremes more often. A larger smoothing divisor reduces the weight of each new observation and can delay turns. Changing both at once makes it harder to identify what altered the result.

Keep the price setup fixed while comparing candidates. For example, test whether a different lookback changes entries around the same predefined range boundaries, rather than choosing a new boundary after seeing each signal. Separate the period used to choose settings from later observations used to evaluate them. Report the number of trades and adverse outcomes, not just the best example.

When trading under a prop firm's rules, an oscillator does not change the firm's loss limits, drawdown treatment or payout conditions. Choose the firm and plan around the account rules you can follow. Use the current offer card below to compare official plans after you have decided what constraints fit your approach.

Compare HDP discounts

Lucid 30% · Tradeify 30% · TPT 50%.

See current offers ↗

Eligible partner plans only.

KDJ indicator FAQ

What does the KDJ indicator mean?

KDJ is a price oscillator with K, D and J lines. In the recursive version here, K smooths the close's position within a rolling high/low range, D smooths K, and J equals 3K − 2D. It describes price momentum rather than a probability of success.

What is the KDJ indicator formula?

RSV is 100 × (close − range low) ÷ (range high − range low). For this 9/3/3 version, K = ⅔ previous K + ⅓ RSV, D = ⅔ previous D + ⅓ current K, and J = 3K − 2D. Other studies can use different smoothing.

What do 9, 3 and 3 mean in KDJ?

Here, 9 is the RSV lookback in candles, including the current candle. The two 3s are the K and D smoothing divisors, each giving the current input a one-third weight. Check the script because another implementation may interpret those inputs as moving-average lengths.

Why can the KDJ J line exceed 100 or go below zero?

J extrapolates the K/D gap through 3K − 2D. It is not clipped to the RSV scale. K at 70 and D at 60 produce J at 90; a wider gap can push J beyond 100 or below zero without any calculation error.

Does J crossing D lead the K/D crossover?

Not when J = 3K − 2D on the same candles. J − D = 3(K − D), so the two comparisons change sign together. J can turn before a K/D crossover, but a turn and a crossover are different events.

Is KDJ the same as Stochastic?

They share a range-based foundation, but KDJ adds J. The smoothing can also differ: this reference uses recursive one-third updates, whereas a Stochastic study may use simple moving averages. Match the full formula before expecting identical K and D lines.

Is KDJ better than RSI?

There is no universal ranking. KDJ begins with the close's position inside a high/low range; RSI uses relative upward and downward price changes. Choose a tool for a defined decision and test the full trading rule, including costs and exits.

How do I add this KDJ indicator to TradingView?

Open Pine Editor, choose Create new → Indicator, paste the complete supplied version 6 code and select Add to chart. Save it as Recursive KDJ Reference. Open Inputs to set RSV lookback 9 and the K and D smoothing divisors to 3.

Is this a built-in TradingView KDJ study?

No. Recursive KDJ Reference is the code supplied in this article. Paste it into your own Pine indicator to use it. Other built-in or community studies may use different formulas or settings and should be checked separately.

What happens when the nine-candle high and low are equal?

The RSV formula would divide by zero. This script explicitly assigns RSV 50 to a flat range. Other implementations can use another policy, so compare that choice when reconciling outputs.

Why do two KDJ indicators show different values?

Possible causes include different smoothing kernels, seeds, startup history, J coefficients, flat-range policies or price data. Compare the same symbol, session, timeframe and completed candle, then inspect the calculation rather than matching only the 9/3/3 labels.

Does the current KDJ candle change before it closes?

Yes. The current close, high and low can change while the candle is open, which changes RSV and the plotted lines. If your rule uses closed-candle signals, evaluate it after that candle completes.

What are the best KDJ settings for a 5-minute chart?

No fixed settings are best for every 5-minute market and rule. Start with a declared formula such as this 9/3/3 reference, keep the price setup and risk rule fixed, and compare candidates on later observations with trading costs included.

Is a KDJ golden cross enough to buy?

A K/D upward cross only describes the relationship between two calculated lines. It does not establish support, a stop or a favorable expected return. Define price confirmation, invalidation, size and exit rules before treating a cross as an entry condition.