Overbought & Oversold Tracker
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © taufan_ganas

//@version=5
indicator("OBS Tracker", overlay = true)

//Stochastic

grp_1 = 'STOCHASTIC SETTINGS' 

periodK = input.int(14, title='K', minval=1, group = grp_1)
periodD = input.int(3, title='D', minval=1, group = grp_1)
smoothK = input.int(3, title='Smooth', minval=1, group = grp_1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

Oversoldlevel = input.int(25, title = 'k Line Value for Oversold', minval = 0, maxval = 100, group = grp_1)
Overboughtlevel = input.int(75, title = 'k Line Value for Overbought', minval = 0, maxval = 100, group = grp_1)

//Condition Support Line

supportT0 = ta.crossover(d, k) and k >= Overboughtlevel ? low : ta.crossover(k, d) and k <= Overboughtlevel ? low : na
linecolor = ta.crossover(d, k) and k >= Overboughtlevel ? color.red : ta.crossover(k, d) and k <= Oversoldlevel ? color.blue : na

if(supportT0)
    supportT0_line = line.new(bar_index, low, bar_index[1], low,
       color =  linecolor,
       style=line.style_dashed,
       extend = extend.left,
       width=1)
    line.delete(supportT0_line[1])

grp_2 = 'OTHER SETTINGS'
    
//Breakout Support

bearBO = ta.valuewhen(supportT0,low,0)
bar = ta.crossover(bearBO,close) ? color.red: na
barcolor(color = bar, title='Support Broken', show_last=input(title='Last Candles Done - Show Red Candle', defval=5, group = grp_2))
plotshape(supportT0, size = size.tiny, style = shape.triangleup, location = location.belowbar, color = linecolor, show_last=input(title='Last Candles Done - Show Triangle', defval=5, group = grp_2))

