← Back to Library
Momentum

Stochastic Oscillator

The Stochastic Oscillator compares a closing price to a range of its prices over a given period. It consists of the %K line and the %D signal line.

Pine Script V6
//@version=6
indicator('Stochastic', overlay=false)
periodK = input.int(14, '%K Length')
periodD = input.int(3, '%D Smoothing')
smoothK = input.int(3, '%K Smoothing')
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
plot(k, '%K', color=color.blue)
plot(d, '%D', color=color.orange)