Stochastic [Tcs] | OSC
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zendrer

//@version=5
indicator("TCS • STOCH", overlay = false)

//••••••••••••••
//INPUT
//••••••••••••••
//----------------------------------------------------------------
length = input.int(15, 'Length', minval=1)
src = input(close, 'Source')
//----------------------------------------------------------------

//••••••••••••••
//FUNCTION
//••••••••••••••
//STOCH RSI
//----------------------------------------------------------------
rsi = ta.rsi(src,length )
rsima = ta.ema(rsi, length)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
k = ta.sma(ta.stoch(rsi, rsi, rsi, length), smoothK)
d = ta.sma(k, smoothD)
//----------------------------------------------------------------

//TRIGGER
//----------------------------------------------------------------
triggerx = (ta.ema(ta.rsi(ta.ema(src, length/2), length), length/2))
trigger = (ta.vwma(ta.stoch(triggerx, triggerx, triggerx, length), length))
trigger1 = (ta.vwma(ta.stoch(triggerx, triggerx, triggerx, length), length)) + 80
trigger2 = (ta.vwma(ta.stoch(triggerx, triggerx, triggerx, length), length)) - 80
trigma = ta.stoch(trigger,trigger,trigger,length)
//----------------------------------------------------------------

//••••••••••••••
//PLOT
//••••••••••••••
//----------------------------------------------------------------
A = plot(trigma, color= color.new(color.gray,80)) 
B = plot(trigger , color=color.new(color.white,80))
C = plot(trigger1 , "oversold", color=(trigger1) > 100 ? na : color.new(color.purple,100), editable=false)
D = plot(trigger2 , "overbought", color=(trigger2) < 0 ? na : color.new(color.lime,100), editable=false)
E = plot(0, color = color.new(color.white,100), editable=false)
F = plot(100, color = color.new(color.white,100), editable=false)
fill(E, D, color = (trigger2) < 0 ? na : (trigger2 > trigger2[1] ? color.new(color.lime,10) : color.new(color.lime,60)))
fill(F, C, color = (trigger1) > 100 ? na : (trigger1 < trigger1[1] ? color.new(color.purple,10) : color.new(color.purple,60)))
fill(A,B, color = trigger > trigma ? color.new(color.gray,30) :color.new(color.white,30))

hline(100)
hline(0)

plot(ta.crossunder(k,d)  and k > 60 and trigma > 99 and trigger > 90 ? trigger : na, color =  color.purple , style = plot.style_cross, linewidth = 3, editable=false)
plot(ta.crossover(k,d) and k < 40 and trigma < 1 and trigger < 35 ? trigger : na, color =  color.lime , style = plot.style_circles, linewidth = 3, editable=false)
plot(ta.crossunder(k,d)  and k > 60 and trigma > 99 and trigger > 65 ? trigger : na, color =  color.purple , style = plot.style_circles, linewidth = 3, editable=false)
//plot(trigger < 50 and ta.crossunder(trigger,trigma) or ta.crossover(trigger,0) and rsi > 55 and rsi > rsima and trigger < trigma and trigger1 > trigger1[1] and trigger1 < 100 ? trigger : na, color =  color.lime , style = plot.style_circles, linewidth = 3, editable=false)
//plot(trigger > 50 and ta.crossover(trigger,trigma)  or ta.crossunder(trigger,100) and rsi < 55 and rsi < rsima and trigger > trigma and trigger2 < trigger2[1] and trigger2 > 0 ? trigger : na, color =  color.purple , style = plot.style_circles, linewidth = 3, editable=false)
//plot(ta.crossover(trigma,trigger1) and rsi > 47 and rsi > rsima  ? trigger : na, color =  color.lime , style = plot.style_cross, linewidth = 3, editable=false)
//plot(ta.crossunder(trigma,trigger2) and rsi < 47 and rsi < rsima ? trigger : na, color =  color.purple , style = plot.style_cross, linewidth = 3, editable=false)
//----------------------------------------------------------------
//END