Master this unique long-term momentum oscillator in TradingView's Pinescript that smooths multiple Rates of Change to identify significant trends and reversals.
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.
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.
//@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)
KST is designed to give a smoother, less noisy signal than individual ROCs, making it suitable for identifying significant, longer-term momentum.
//@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)
//@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)
//@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.")
To get the most from the Know Sure Thing (KST) in Pinescript:
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.
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.
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