Stochastic

Pine Script indicator by Chart GT · Published

Stochastic oscillator %K and %D.

Tags: momentum, oscillator

Source code

//@version=6
// @name Stochastic
// @description Stochastic oscillator %K and %D.
// @tags momentum,oscillator
indicator("Stochastic", overlay=false)
periodK = input.int(14, "%K length", minval=1)
smoothK = input.int(1, "%K smoothing", minval=1)
periodD = input.int(3, "%D smoothing", minval=1)
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)
hline(80, "Upper", color=color.gray)
hline(20, "Lower", color=color.gray)
alertcondition(ta.crossover(k, d), "%K crossed above %D", "Stochastic %K crossed above %D")
alertcondition(ta.crossunder(k, d), "%K crossed below %D", "Stochastic %K crossed below %D")

License: MPL-2.0

Open the chart to add it, or browse more community scripts.