Simple Levels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SamRecio

//@version=5
indicator("Simple Levels",overlay = true)
//User Inputs///////////////////////////////////////////////////////////////////
lvls = str.replace_all(input.string("", title = "Insert Levels ->", group = "SIMPLE LEVELS", tooltip = "Insert Levels, Separated by commas(,).", inline = "1", confirm = true)," ","")//Replaces all spaces with blanks
line_style = input.string("___", title = "Style", options = ["___","- - -",". . ."], group = "SETTINGS", inline = "2")
thickness = input.int(1, title = "Width", group = "SETTINGS", inline = "2")
low_color = input.color(color.rgb(0,124,150), title = "Support Color", group = "SETTINGS", inline = "3")
high_color = input.color(color.rgb(221,75,50), title = "Resistance Color", group = "SETTINGS", inline = "3")
lab_size = input.string("small", title = "Label Size", options = ["tiny","small","normal","large","huge"], inline = "4", group = "SETTINGS")
lab_offset = input.int(9, title = "Label Offset", inline = "4", group = "SETTINGS")

//Transforms Style input into actual line styles////////////////////////////////
linestyle(_input) =>
    _input == "___"?line.style_solid:
     _input == "- - -"?line.style_dashed:
     _input == ". . ."?line.style_dotted:
     line.style_solid
//Splits levels input into an array to read later//////////////////////////////
split = str.split(lvls,",")
//ERROR MESSAGE/////////////////////////////////////////////////////////////////
if array.size(split) == 0 //If the array has no values then the box is empty. Please input values.
    runtime.error("Please input Levels.")
//Variable initialization///////////////////////////////////////////////////////
var line lvl_line = na
var label lvl_lab = na
//Delete all lines & Labels
a_allLines = line.all
if array.size(a_allLines) > 0
	for i = 0 to array.size(a_allLines) - 1
		line.delete(array.get(a_allLines, i))
a_allLabels = label.all
if array.size(a_allLabels) > 0
	for i = 0 to array.size(a_allLabels) - 1
		label.delete(array.get(a_allLabels, i))
//Loops for every entry in the array above and draws a line with the appropriate color and label.
for i = 0 to array.size(split) - 1
    num = str.tonumber(array.get(split,i)) //The array values are 'string'(text) values, this grabs that text value and makes it into a number.
    col = (num>close)?high_color:(num<close)?low_color:color.gray //Compairing our number to the current close price to see if its above or below, and assigning a color value.
    lvl_line := line.new(bar_index,num,bar_index+1,num, extend = extend.right, color = col, style = linestyle(line_style), width = thickness)
    lvl_lab := label.new(bar_index + lab_offset,num,text = str.format("{0,number,currency}",str.tonumber(array.get(split,i))), color = color.new(color.black,100), size = lab_size, textcolor = col, style = label.style_label_lower_left)