Skip to content

Instantly share code, notes, and snippets.

@eminarslan
Created July 11, 2018 13:45
Show Gist options
  • Save eminarslan/497cad7ed236cc349d918a49953830ca to your computer and use it in GitHub Desktop.
Save eminarslan/497cad7ed236cc349d918a49953830ca to your computer and use it in GitHub Desktop.
Stochastic Divergence
//@version=3
study("Stochastic Divergence",overlay=false)
length = input(14, "Stoch Length")
lb = input(30, "Lookback")
k = (close - lowest(low, length)) / (highest(high, length) - lowest(low, length)) * 100
price_high = highest(close, 1) >= highest(close, lb)
stoch_nothigh = k > 80 and highest(k, 1) < highest(k, lb)
bearish= price_high and stoch_nothigh
price_low = lowest(close,1) <= lowest(close, lb)
stoch_notlow = k < 20 and lowest(k, 1) > lowest(k, lb)
bullish = price_low and stoch_notlow
a = plot(k)
x = plot(0)
fill(x, a,color=#9bedff, transp=65)
bgcolor(bearish?#ffd3e0:bullish?green:na, transp=30)
col = bullish?lime:bearish?red:na
plotshape(bullish or bearish?k:na, color=col, style=shape.xcross, location=location.absolute,transp=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment