Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-kst

$ Pinescript Know Sure Thing (KST)

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

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

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 Pinescript, 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.

02

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)
03

Basic Know Sure Thing (KST) Implementation in Pinescript

pine-script@terminal
//@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)
$ ✓ Compiled successfully
04

Smoothed Momentum

Smoothed Momentum

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

05

Practical KST Trading Strategies

06

1. KST and Signal Line Crossover

pine-script@terminal
//@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)
$ ✓ Compiled successfully
07

2. KST Zero Line Crossover (Trend Confirmation)

pine-script@terminal
//@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)
$ ✓ Compiled successfully
08

3. KST Divergence Strategy

pine-script@terminal
//@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.")
$ ✓ Compiled successfully
09

Optimizing KST Performance

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

  • Standard Parameters are Recommended: Martin Pring developed KST with specific default lengths (10,15,20,30 for ROCs and 10,10,10,15 for SMAs, plus 9 for the signal line). These parameters are generally well-tuned for identifying longer-term trends and are a good starting point. Adjusting them too much can alter the indicator's intended behavior.
  • Focus on Crossovers and Divergence: KST is particularly effective for KST/Signal line crossovers as trend confirmation and for divergence signals, which are often more reliable due to the indicator's smoothing.
  • Multi-Timeframe Analysis: KST is inherently designed for longer-term analysis due to its multiple ROC components. It's best used on higher timeframes (daily, weekly) for identifying dominant trends and then confirmed by price action or other indicators on lower timeframes for entry/exit timing.
  • Combine with Price Action: Always seek confirmation from price action. A KST signal gains credibility if it aligns with a break of support/resistance, a strong candlestick pattern, or a significant volume spike.
  • Not for Short-Term Noise: KST is designed to filter noise. It is less suited for very short-term or scalping strategies, as its signals will inherently lag more than faster oscillators.
10

The "Sure Thing"

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.

11

Common KST Pitfalls

  • Lag: Despite its complexity, KST is still a lagging indicator due to its multiple smoothing layers. It will not pick tops and bottoms precisely.
  • Not for Sideways Markets: In prolonged choppy or range-bound markets, KST can still generate false signals or hover around the zero line, providing little actionable insight. It performs best in trending environments.
  • Complex Calculation: While Pinescript simplifies it, understanding the multi-layered calculation is important for proper interpretation and advanced customization.
  • Divergence Can Be Early: As with most divergence signals, KST divergence can appear before a reversal fully takes hold, requiring patience and additional confirmation.
  • Not a Standalone Indicator: KST should always be used as part of a broader trading system, complementing other technical analysis tools for trend confirmation and risk management.
12

Conclusion

Conclusion

The Know Sure Thing (KST) is a sophisticated and highly insightful momentum indicator in Pinescript 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 Pinescript 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.

Get Pinescript Strategy