Yes sir, you can definitely create a Stochastic Oscillator in Pine Script.
The Stochastic Oscillator mainly uses the current close compared with the highest high and lowest low over a selected period.
-> %K measures the current price position within that high-low range.
-> %D is a moving average of the %K line.
You can create a basic version using:
//@version=6
indicator("Custom Stochastic", overlay=false)
kLength = input.int(14, "%K Length")
kSmooth = input.int(3, "%K Smoothing")
dLength = input.int(3, "%D Length")
rawK = ta.stoch(close, high, low, kLength)
k = ta.sma(rawK, kSmooth)
d = ta.sma(k, dLength)
kPlot = plot(k, "%K")
dPlot = plot(d, "%D", color = color.orange)
overbought = hline(80, "Overbought")
MiddLine = hline(50, "Midline")
oversold = hline(20, "Oversold")
fill(overbought, oversold, color=color.new(color.blue, 90))
-> The %K line represents the current price position within the selected high-low range.
-> The %D line is a smoothed version of %K.
-> 80 is commonly used as the overbought level.
-> 20 is commonly used as the oversold level.
-> The input values allow to adjust the calculation from the indicator settings.
=> This gives you a configurable Stochastic Oscillator without depending on the built-in chart indicator.
So thatβs how you can create a basic Stochastic Oscillator in Pine Script.