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
| Component | ROC bars | SMA bars | Weight | First valid price bar* |
|---|---|---|---|---|
| 1 | 10 | 10 | 1 | 20 |
| 2 | 15 | 10 | 2 | 25 |
| 3 | 20 | 10 | 3 | 30 |
| 4 | 30 | 15 | 4 | 45 |
*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.
| Component | Smoothed ROC (%) | Weight | Contribution |
|---|---|---|---|
| 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.
- Price bar 45 provides the first complete KST value: all four components are available.
- Price bars 45 through 53 provide nine KST values for the first signal average.
- 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.
//@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
- Paste the code into TradingView Pine Editor and add it to a standard candle chart.
- Add TradingView's built-in KST. Match the symbol, chart interval and all nine lengths.
- Choose a closed bar after sufficient history. Sum Contribution 1 through Contribution 4 in the Data Window.
- Check that KST equals that sum, then average the latest signal-length KST readings. Compare unrounded values where possible.
- 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 condition | What it establishes | What it leaves open |
|---|---|---|
| KST > 0 | The weighted sum is positive. | Individual components can be negative. |
| KST crosses above Signal | The difference changes from ≤ 0 to > 0. | KST itself can remain below zero. |
| KST crosses zero | The aggregate changes sign. | The next price move and execution outcome. |
| Price/KST divergence | Selected 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 AgentKST questions
Sources and related guides
Official references checked October 17, 2026. Warm-up counts and contribution examples are derived from the displayed code under their stated assumptions.
- TradingView: KST defaults and formula
- TradingView: Rate of Change formula
- Pine Script: bar confirmation
- Pine Script: calculation and plotting techniques
Rate of Change
Check the underlying percentage-change calculation.
MACD
Compare a different two-line momentum calculation.
True Strength Index
Inspect a double-smoothed momentum measure.