TradingView indicator guides

Know Sure Thing indicator: check the KST calculation

KST combines four smoothed ROC values with weights of 1, 2, 3 and 4, then compares their sum with a signal average. Use the component values to explain the total before treating a crossing as a trading rule.

The example uses four lookback lengths on the current chart. It does not fetch four different timeframes. Copy the code, inspect its Data Window outputs, and verify a closed bar against the arithmetic below.

KST = C1 + C2 + C3 + C4

Ci = weight × SMA(ROC(close, ROC length), SMA length)

Signal = SMA(KST, signal length)

Four components, nine adjustable lengths

TradingView documents the default lengths below. ROC measures 100 × (close / close[N] - 1); smoothing applies to that ROC series, not to close first. The signal uses a 9-bar SMA of the completed KST series. TradingView KST reference

Default inputs and the fixed weight applied after smoothing
ComponentROC barsSMA barsWeightFirst valid price bar*
11010120
21510225
32010330
43015445

*Derived for continuous valid closes and nonzero reference prices, counting the first loaded price bar as 1. All nine length inputs in the example accept integers from 1 to 500. Weights are fixed.

A weight of 4 is a multiplier, not a promise that component 4 contributes 40% of the result. Contributions depend on the smoothed values and can cancel. The sum is not divided by 10, so KST is not a portfolio return or a weighted average percentage.

Worked example: two positive components, negative KST

Assume the four SMA outputs on one closed bar are +2%, +1%, -0.5% and -1%. These are hypothetical smoothed inputs for checking the sum, not measured market data or a reconstructed price history.

ComponentSmoothed ROC (%)WeightContribution
C1+2.0×1+2.0
C2+1.0×2+2.0
C3-0.5×3-1.5
C4-1.0×4-4.0
KST = 2 + 2 - 1.5 - 4-1.5

If the previous eight KST values total -18, the current signal is (-18 - 1.5) / 9 = -2.1667. KST is therefore 0.6667 above its signal while remaining below zero. That describes a state; a crossover also requires the previous bar to be at or below its previous signal.

Change only the fourth smoothed input from -1 to -0.25 and its contribution changes from -4 to -1. KST becomes +1.5. This sensitivity check explains why inspecting the raw component matters: a 0.75-point change in that input moves the aggregate by 3 points.

Warm-up: first KST on bar 45, signal on bar 53

For a ROC length N, the first ROC needs N + 1 prices. Averaging M consecutive ROC values adds M - 1 bars. Each component therefore needs N + M prices. With the defaults, the fourth component sets the maximum: 30 + 15 = 45.

  1. Price bar 45 provides the first complete KST value: all four components are available.
  2. Price bars 45 through 53 provide nine KST values for the first signal average.
  3. Price bar 54 provides the first pair of adjacent valid KST/signal readings for the example's crossing test. It need not contain a crossing.

These are minimum data requirements, not estimates of market lag. Changing an input changes the count: max(ROC length + SMA length) + signal length - 1 is the first signal bar under the same assumptions.

Do not replace warm-up values with zero. That changes the averages and can manufacture a crossing. Zero reference prices make percentage change undefined; missing values and unusual price series need a separate policy before comparing this baseline with production data.

Pine Script v6 with component outputs

This indicator preserves the four-ROC calculation and exposes all nine lengths as inputs. The pane shows teal KST, red Signal and a gray zero line. Contributions and KST minus Signal appear in the Data Window; triangles mark only confirmed crossings.

Pine Script v6

//@version=6
// KST calculation example. No strategy orders or performance claims.
indicator("Know Sure Thing: component audit", overlay = false, precision = 4)

rocLen1 = input.int(10, "ROC length 1", minval = 1, maxval = 500)
rocLen2 = input.int(15, "ROC length 2", minval = 1, maxval = 500)
rocLen3 = input.int(20, "ROC length 3", minval = 1, maxval = 500)
rocLen4 = input.int(30, "ROC length 4", minval = 1, maxval = 500)
smaLen1 = input.int(10, "SMA length 1", minval = 1, maxval = 500)
smaLen2 = input.int(10, "SMA length 2", minval = 1, maxval = 500)
smaLen3 = input.int(10, "SMA length 3", minval = 1, maxval = 500)
smaLen4 = input.int(15, "SMA length 4", minval = 1, maxval = 500)
signalLen = input.int(9, "Signal SMA length", minval = 1, maxval = 500)

p_ta_smaroc(simple int rocLen, simple int smaLen) =>
    ta.sma(ta.roc(close, rocLen), smaLen)

// Each contribution includes its weight exactly once.
c1 = p_ta_smaroc(rocLen1, smaLen1)
c2 = 2.0 * p_ta_smaroc(rocLen2, smaLen2)
c3 = 3.0 * p_ta_smaroc(rocLen3, smaLen3)
c4 = 4.0 * p_ta_smaroc(rocLen4, smaLen4)
kst = c1 + c2 + c3 + c4
signal = ta.sma(kst, signalLen)

plot(kst, "KST", color = color.teal, linewidth = 2)
plot(signal, "Signal", color = color.red, linewidth = 2)
hline(0, "Zero", color = color.gray)
plot(c1, "Contribution 1 (weight 1)", display = display.data_window)
plot(c2, "Contribution 2 (weight 2)", display = display.data_window)
plot(c3, "Contribution 3 (weight 3)", display = display.data_window)
plot(c4, "Contribution 4 (weight 4)", display = display.data_window)
plot(kst - signal, "KST minus Signal", display = display.data_window)

crossUp = ta.crossover(kst, signal)
crossDown = ta.crossunder(kst, signal)
ready = not na(kst) and not na(signal) and not na(kst[1]) and not na(signal[1])
confirmedUp = ready and crossUp and barstate.isconfirmed
confirmedDown = ready and crossDown and barstate.isconfirmed
plotshape(confirmedUp, "Confirmed cross up", shape.triangleup, location.bottom, color.teal, size = size.tiny)
plotshape(confirmedDown, "Confirmed cross down", shape.triangledown, location.top, color.red, size = size.tiny)
alertcondition(confirmedUp, "KST crossed above Signal", "KST crossed above its signal on a closed chart bar.")
alertcondition(confirmedDown, "KST crossed below Signal", "KST crossed below its signal on a closed chart bar.")

Check one closed bar before adding trading rules

  1. Paste the code into TradingView Pine Editor and add it to a standard candle chart.
  2. Add TradingView's built-in KST. Match the symbol, chart interval and all nine lengths.
  3. Choose a closed bar after sufficient history. Sum Contribution 1 through Contribution 4 in the Data Window.
  4. Check that KST equals that sum, then average the latest signal-length KST readings. Compare unrounded values where possible.
  5. Inspect a marker's previous and current KST-minus-Signal values. An upward crossing requires previous ≤ 0 and current > 0.

The source passes the Pineify syntax checker. Numeric parity on a particular chart, alert delivery and strategy performance are separate checks.

Reading signals without assuming agreement

Observed conditionWhat it establishesWhat it leaves open
KST > 0The weighted sum is positive.Individual components can be negative.
KST crosses above SignalThe difference changes from ≤ 0 to > 0.KST itself can remain below zero.
KST crosses zeroThe aggregate changes sign.The next price move and execution outcome.
Price/KST divergenceSelected price and oscillator swings differ.Which swing rule applies and when it was confirmed.

The live lines update as close changes. The marker and alert conditions require barstate.isconfirmed, so an intrabar crossing that disappears before the close does not qualify. Create a TradingView alert from the desired condition; the code alone does not create a running alert. Bar-state documentation

Parameter changes and common mismatches

  • Changing a ROC length changes the historical comparison point. Changing its SMA length changes which ROC values are averaged. They are different operations.
  • Changing only the signal length leaves KST untouched but changes the comparison line and its warm-up.
  • Dividing KST by 10, scaling it by 100 again, or using an EMA signal produces a different numeric series.
  • A repeated crossing in a narrow range can create several events without a sustained price move. Define and test any entry filter separately.
  • A component with the largest weight need not dominate if its smoothed ROC is near zero. Do not infer contributions from weights alone.

Educational calculation example. No investment advice or forecast of returns.

KST, ROC and MACD answer different calculation questions

Use ROC to isolate one endpoint comparison. KST adds smoothing and weighted aggregation, so the component audit is needed to explain the total. MACD uses moving-average differences instead. Similar two-line displays do not make their values interchangeable.

Specify a KST modification in Pineify

Use the Pine Script AI Coding Agent to describe the inputs, outputs and confirmation rule you want to change. Keep a known calculation baseline so the generated result can be compared bar by bar.

Keep the KST formula in this example. Add a display option for the four weighted contributions. Preserve the default lengths, leave warm-up values missing, and mark crossings only when the current chart bar closes. Explain each change before adding strategy orders.

After reviewing the script, rerun syntax validation and numeric checks. If you want a strategy, separately specify the exit, size, stop, commission, slippage and fill timing; a crossover marker does not define those choices.

Open Pine Script AI Coding Agent

KST questions

KST is a weighted sum of four smoothed rates of change. It condenses several lookback lengths into one momentum reading. The name does not imply a certain outcome. A positive aggregate can contain negative components, so inspect the contributions before assuming that all four agree.

The example calculates every component from close on the current chart. On a daily chart, its lengths count daily bars; on an hourly chart, they count hourly bars. It contains no request.security call. Reading four separate timeframes would require a different script and explicit rules for confirming those requested bars.

Add the built-in Know Sure Thing indicator and this example to the same chart. Match all nine inputs and compare a closed bar after warm-up. In the Data Window, add the four weighted contributions and compare the total with KST. Then check the signal against the average of the latest nine KST values at default settings.

This page establishes a reproducible default baseline, not an optimal parameter set. Change one length at a time and record the effect on numeric values, warm-up and crossover timing. A setting chosen on past data needs separate testing with explicit entries, exits, costs and an unseen period before any performance conclusion.

With continuous valid closes and nonzero ROC reference prices, the default example first has KST on price bar 45 and a signal on bar 53, counting the initial price bar as bar 1. A crossing needs a previous valid signal too, so the first eligible comparison is bar 54. Missing or invalid inputs can change that schedule.

Yes. For example, KST moving from -3 to -1 while its signal moves from -2 to -1.5 meets the above-signal crossing condition. Both KST values remain negative. The event describes KST relative to its own average; it does not establish that every component is positive or that price will rise next.

The live KST and signal lines can change while the chart bar is open because close changes. The example waits for barstate.isconfirmed before drawing crossover markers or enabling its alert conditions. That confirms the current chart bar only. It is not a claim about revised market data or other scripts that request higher-timeframe data.

No. It plots values and marks confirmed crossings; it does not submit orders, choose position sizes or calculate returns. Converting the event into a strategy requires separate entry, exit, stop, execution and transaction-cost rules. The component table is a hypothetical arithmetic check, not a backtest.