Support & Resistance Parser
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CaptainBrett 

//@version=5
indicator("S&R Parser", overlay=true)

supportString = input.string("", title = "Support: ")
supportColor = input.color(color.red, title = "Support Color")
resistanceString = input.string("", title = "Resistance: ")
resistanceColor = input.color(color.green, title = "Resistance Color")

labelAlignment = input.int(10, "Label Align (-: left, +: right)", minval=-1000, maxval=1000, step=5)

if barstate.islast
    // Parse comma seperated strings
    supportArray = str.split(supportString, ",")
    resistanceArray = str.split(resistanceString, ",")

    // Draw lines for each array
    if array.size(supportArray) > 0
        for i = 0 to array.size(supportArray) - 1
            supportNumber = str.tonumber(array.get(supportArray, i))
            line.new(bar_index, supportNumber, bar_index+1, supportNumber, extend = extend.both, color = supportColor)
            label.new(bar_index+labelAlignment, supportNumber, text=str.tostring(supportNumber) + " S", style=labelAlignment>=0?label.style_label_left:label.style_label_right, color = supportColor, textcolor = color.new(color.white, 0), size = size.small)

    if array.size(resistanceArray) > 0
        for i = 0 to array.size(resistanceArray) - 1
            resistanceNumber = str.tonumber(array.get(resistanceArray, i))
            line.new(bar_index, resistanceNumber, bar_index+1, resistanceNumber, extend = extend.both, color = resistanceColor)
            label.new(bar_index+labelAlignment, resistanceNumber, text=str.tostring(resistanceNumber) + " R", style=labelAlignment>=0?label.style_label_left:label.style_label_right, color = resistanceColor, textcolor = color.new(color.white, 0), size = size.small)

