Neo's %K
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NeoDaNomad

//@version=5
indicator("%K")
int pd = input.int(14,"periods")
float max_lo=ta.lowest(low, pd)
float max_hi=ta.highest(high,pd)
float numer=close - max_lo
float denom=max_hi - max_lo
int percentageK= math.floor((numer/denom)*100)
_color = switch
    percentageK >= 80 => input.color(color.new(#801922, 0), "80 Col")
    percentageK <= 20 => input.color(color.new(#1B5E20, 0), "20 Col")
    percentageK > 20 or percentageK < 80 => input.color(color.new(#000000, 80), "21-79 Col")
_80 = hline(80, "80%", color.new(#801922,60), linestyle=hline.style_dotted)
_20 = hline(20, "20%", color.new(#801922,60), linestyle=hline.style_dotted)
plot(percentageK, "%K" ,color=_color,style=plot.style_columns)
