indicator · own pane · open source
Stochastic
Running…
Loading chart…
About
Stochastic Oscillator plots where the close sits within the recent high-low range. %K is the raw oscillator; %D is the smoothed version.
- Above 80 = overbought, below 20 = oversold.
- %K crossing above %D in the oversold zone is the textbook buy.
- Raise
Lengthto filter noise, lower it for faster reversals.
Source code
//@version=5
indicator("Stochastic", overlay=false)
len = input.int(14, "%K Length", minval=2, maxval=200)
dlen = input.int(3, "%D Smoothing", minval=1, maxval=50)
src = input.source("close", "Source")
hh = ta.highest(high, len)
ll = ta.lowest(low, len)
k = 100.0 * (src - ll) / (hh - ll)
d = ta.sma(k, dlen)
hline(80, "Overbought", color=color.gray, linestyle=hline.style_dashed)
hline(20, "Oversold", color=color.gray, linestyle=hline.style_dashed)
p__K = plot(k, "%K", color=color.blue, linewidth=2)
p__D = plot(d, "%D", color=color.orange)
alertcondition(ta.crossover(k, d) and k < 20, "Stoch cross up in OS", "Stochastic %K crossed %D in oversold")
alertcondition(ta.crossunder(k, d) and k > 80, "Stoch cross down in OB", "Stochastic %K crossed %D in overbought")
No comments yet.
Sign in to comment.