Pine Script Know Sure Thing (KST)

Master this unique long-term momentum oscillator in TradingView's Pine Script that smooths multiple Rates of Change to identify significant trends and reversals.

Subscribe now @ $99/month

What is the Know Sure Thing (KST)?

The Know Sure Thing (KST), developed by Martin Pring, is a momentum indicator that effectively smooths and combines four different Rates of Change (ROC) from varying timeframes. This unique construction aims to provide a reliable measure of long-term momentum, filtering out short-term noise and giving clearer signals for major trend reversals. KST typically oscillates around a zero line and also includes a signal line (a smoothed version of KST itself).

In Pine Script, KST is a powerful tool for traders seeking a nuanced and smoothed view of market momentum, making it excellent for identifying significant shifts in trend direction and confirming price action over longer periods.

Components and Calculation

The calculation of KST is quite involved, combining four different ROC values, each smoothed by an SMA, and then adding them together. Finally, the KST line itself is smoothed to create a signal line.

  1. Four Rates of Change (ROC):
    • `ROC1 = ROC(close, 10)`
    • `ROC2 = ROC(close, 15)`
    • `ROC3 = ROC(close, 20)`
    • `ROC4 = ROC(close, 30)`
  2. Four Smoothed Rates of Change (SMA): Each ROC is then smoothed with a Simple Moving Average.
    • `SMAROC1 = SMA(ROC1, 10)`
    • `SMAROC2 = SMA(ROC2, 10)`
    • `SMAROC3 = SMA(ROC3, 10)`
    • `SMAROC4 = SMA(ROC4, 15)`
  3. KST Line Calculation: The KST line is the sum of these four smoothed ROCs.
    `KST = (SMAROC1 * 1) + (SMAROC2 * 2) + (SMAROC3 * 3) + (SMAROC4 * 4)`
    (Note: The weights 1, 2, 3, 4 are standard, but sometimes different weights are used depending on the source or specific implementation of Pring's methods.)
  4. KST Signal Line: A Simple Moving Average of the KST line.
    `Signal Line = SMA(KST, SignalLength)` (e.g., 9 periods)

This multi-faceted approach makes KST a highly reliable trend-following oscillator.

Basic Know Sure Thing (KST) Implementation in Pine Script

Pine Script v5 provides a built-in function `ta.kst()` for calculating the Know Sure Thing, simplifying its complex formula.

//@version=5
indicator("My Know Sure Thing (KST) Indicator", overlay=false) // overlay=false to plot in a separate pane

// Inputs for KST lengths (standard parameters by Martin Pring)
roc1Length = input.int(10, title="ROC1 Length", minval=1)
sma1Length = input.int(10, title="SMA1 Length", minval=1)
roc2Length = input.int(15, title="ROC2 Length", minval=1)
sma2Length = input.int(10, title="SMA2 Length", minval=1)
roc3Length = input.int(20, title="ROC3 Length", minval=1)
sma3Length = input.int(10, title="SMA3 Length", minval=1)
roc4Length = input.int(30, title="ROC4 Length", minval=1)
sma4Length = input.int(15, title="SMA4 Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)

// Calculate KST and its signal line using the built-in function
// ta.kst takes all the specific lengths for its internal calculation
[kstValue, signalValue] = ta.kst(close, roc1Length, sma1Length, roc2Length, sma2Length, roc3Length, sma3Length, roc4Length, sma4Length, signalLength)

// Plot the KST line
plot(kstValue, title="KST", color=color.blue, linewidth=2)

// Plot the Signal Line
plot(signalValue, title="Signal", color=color.orange, linewidth=2)

// Plot the Zero Line
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

Smoothed Momentum: KST is designed to give a smoother, less noisy signal than individual ROCs, making it suitable for identifying significant, longer-term momentum.

Practical KST Trading Strategies

1. KST and Signal Line Crossover

This is the primary way to generate trading signals with KST. A crossover between the KST line and its signal line indicates a shift in momentum, confirming trend direction.

//@version=5
strategy("KST Crossover Strategy", overlay=true)

// Inputs for KST lengths (standard parameters by Martin Pring)
roc1Length = input.int(10, title="ROC1 Length", minval=1)
sma1Length = input.int(10, title="SMA1 Length", minval=1)
roc2Length = input.int(15, title="ROC2 Length", minval=1)
sma2Length = input.int(10, title="SMA2 Length", minval=1)
roc3Length = input.int(20, title="ROC3 Length", minval=1)
sma3Length = input.int(10, title="SMA3 Length", minval=1)
roc4Length = input.int(30, title="ROC4 Length", minval=1)
sma4Length = input.int(15, title="SMA4 Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)

// Calculate KST and its signal line
[kstValue, signalValue] = ta.kst(close, roc1Length, sma1Length, roc2Length, sma2Length, roc3Length, sma3Length, roc4Length, sma4Length, signalLength)

// Plot KST and Signal in a separate pane for visualization
plot(kstValue, "KST", color.blue, display=display.pane_only)
plot(signalValue, "Signal", color.orange, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Define conditions for entries
longSignal = ta.crossover(kstValue, signalValue)
shortSignal = ta.crossunder(kstValue, signalValue)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)

2. KST Zero Line Crossover (Trend Confirmation)

The zero line provides a confirmation of the overall market bias. Crossing above zero indicates bullish momentum, and crossing below zero indicates bearish momentum.

//@version=5
strategy("KST Zero Line Crossover Strategy", overlay=true)

// Inputs for KST lengths
roc1Length = input.int(10, title="ROC1 Length", minval=1)
sma1Length = input.int(10, title="SMA1 Length", minval=1)
roc2Length = input.int(15, title="ROC2 Length", minval=1)
sma2Length = input.int(10, title="SMA2 Length", minval=1)
roc3Length = input.int(20, title="ROC3 Length", minval=1)
sma3Length = input.int(10, title="SMA3 Length", minval=1)
roc4Length = input.int(30, title="ROC4 Length", minval=1)
sma4Length = input.int(15, title="SMA4 Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1) // Signal not used for this strategy

// Calculate KST (signal line is not relevant for this zero-line strategy, but calculated by ta.kst)
[kstValue, signalValue] = ta.kst(close, roc1Length, sma1Length, roc2Length, sma2Length, roc3Length, sma3Length, roc4Length, sma4Length, signalLength)

// Plot KST in a separate pane
plot(kstValue, "KST", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Define conditions for entries
longSignal = ta.crossover(kstValue, 0)
shortSignal = ta.crossunder(kstValue, 0)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)

3. KST Divergence Strategy

Divergence between price and KST is a highly reliable signal for significant trend reversals. Because KST is so heavily smoothed, its divergence signals are often less frequent but more powerful.

//@version=5
indicator("KST Divergence Scanner", overlay=true)

// Inputs for KST lengths
roc1Length = input.int(10, title="ROC1 Length", minval=1)
sma1Length = input.int(10, title="SMA1 Length", minval=1)
roc2Length = input.int(15, title="ROC2 Length", minval=1)
sma2Length = input.int(10, title="SMA2 Length", minval=1)
roc3Length = input.int(20, title="ROC3 Length", minval=1)
sma3Length = input.int(10, title="SMA3 Length", minval=1)
roc4Length = input.int(30, title="ROC4 Length", minval=1)
sma4Length = input.int(15, title="SMA4 Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)

// Calculate KST and its signal line
[kstValue, signalValue] = ta.kst(close, roc1Length, sma1Length, roc2Length, sma2Length, roc3Length, sma3Length, roc4Length, sma4Length, signalLength)

// Plot KST and Signal in a separate pane
plot(kstValue, "KST", color.blue)
plot(signalValue, "Signal", color.orange)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This is a simplified example focusing on price vs KST divergence.

// Bullish Divergence (Price lower low, KST higher low)
bullishDivergence = close[2] > close[1] and close[1] > close and kstValue[2] < kstValue[1] and kstValue[1] < kstValue

// Bearish Divergence (Price higher high, KST lower high)
bearishDivergence = close[2] < close[1] and close[1] < close and kstValue[2] > kstValue[1] and kstValue[1] > kstValue

plotshape(bullishDivergence, title="Bullish Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDivergence, title="Bearish Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

alertcondition(bullishDivergence, "Bullish KST Divergence", "Potential bullish reversal based on KST divergence.")
alertcondition(bearishDivergence, "Bearish KST Divergence", "Potential bearish reversal based on KST divergence.")

Optimizing KST Performance

To get the most from the Know Sure Thing (KST) in Pine Script:

The "Sure Thing": The name "Know Sure Thing" reflects Pring's belief that by combining different ROCs, the indicator provides a more "certain" and reliable signal of the underlying trend compared to simpler momentum indicators.

Common KST Pitfalls

Conclusion

The Know Sure Thing (KST) is a sophisticated and highly insightful momentum indicator in Pine Script for TradingView. Its unique construction, which combines and smooths multiple Rates of Change, makes it particularly effective at identifying long-term trend shifts and reliable reversal signals through its crossovers and divergence patterns. By understanding its calculation, thoughtfully utilizing its standard parameters, and integrating it strategically within your comprehensive trading approach, you can leverage the KST to gain a deeper, noise-filtered understanding of market dynamics and enhance your trading decisions, especially for position or swing trading.

Enhance Your Trading

Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Subscribe now @ $99/month