[AB] Support/Resistance Drawing Tool
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © akalibot1987

//@version=4
study("[AB] Support/Resistance Drawing Tool", max_lines_count=500, overlay=true)

src = input(close, title="Source")
step = input(0.1, title="Source Rounding")
len = input(500, title="Length (Array)")
lenSR = input(20, title="Sampled Support/Resistance Length")
skip = input(2, title="Sampling Skip")
transpSkip = input(5, title="Transparency Skip")
colorR = input(0, title="Color R")
colorG = input(0, title="Color G")
colorB = input(0, title="Color B")

custom_round(src, step)=>
    rounded = step*round(src/step)

rounded = custom_round(src, step)

resistance = highest(rounded, lenSR)
support = lowest(rounded, lenSR)

var arrayResistance = array.new_float(len)
var arraySupport = array.new_float(len)

array.shift(arrayResistance)
array.shift(arraySupport)
array.push(arrayResistance, resistance)
array.push(arraySupport, support)

for i = 0 to len-1 by skip
    rly = array.get(arrayResistance, i)
    sly = array.get(arraySupport, i)
    line.new(bar_index-len, rly, bar_index, rly, color=color.rgb(colorR,colorG,colorB,100-transpSkip))
    line.new(bar_index-len, sly, bar_index, sly, color=color.rgb(colorR,colorG,colorB,100-transpSkip))

plot(rounded)