Quick 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("Quick Levels", overlay = true, max_lines_count = 500, max_labels_count = 500)

//Color & Style Functions///////////////////////////////////////////////////////
colorpicker(_input) =>
    _input == "RED"?color.red:
     _input == "ORANGE"?color.orange:
     _input == "YELLOW"?color.yellow:
     _input == "GREEN"?color.green:
     _input == "BLUE"?color.blue:
     _input == "PURPLE"?color.fuchsia:
     _input == "WHITE"?color.white:
     _input == "BLACK"?color.rgb(0,0,0):
     _input == "GRAY"?color.gray:
     chart.fg_color
stylepicker(_input) =>
    _input == "SOLID"?line.style_solid:
     _input == "DASHED"?line.style_dashed:
     _input == "DOTTED"?line.style_dotted:
     str.contains(_input,"SOLID")?line.style_solid:
     str.contains(_input,"DASHED")?line.style_dashed:
     str.contains(_input,"DOTTED")?line.style_dotted:
     line.style_solid
linestyle(_input) =>
    _input == "___"?"solid":
     _input == "- - -"?"dashed":
     _input == ". . ."?"dotted":
     _input == "___zone"?"solid_zone":
     _input == "- - -zone"?"dashed_zone":
     _input == ". . .zone"?"dotted_zone":
     na
////////////////////////////////////////////////////////////////////////////////
//Remove commas at start and end
remove_c(_string) => 
    var string s = str.replace_all(_string,";",",")
    in_len = str.length(s)
    if str.startswith(s,",")
        s := str.replace(s,",","",0)
    if str.endswith(s,",")
        s := str.replace(s,",","",in_len)
    s
//Inputs////////////////////////////////////////////////////////////////////////
lab_size = input.string("small", title = "Label Size", options = ["tiny","small","normal","large","huge"], inline = "2", group = "Settings")
lab_offset = input.int(10, title = "Label Offset", inline = "2", group = "Settings")
z_op = input.int(90, title = "Zone Opacity", minval = 0, maxval = 100, inline = "3", group = "Settings")
tog_lvl = input.bool(true, title = "Price Labels", inline = "3", group = "Settings")

symbol1 = input.symbol("", title  = "Ticker", group = "Group 1", inline = "2")
lvls1 = str.replace_all(input.string("", title = "Levels", group = "Group 1", inline = "2", tooltip = "LEVELS\nInsert as many levels as needed for this style of line & ticker.\nSeparate by commas (,)\nPlease No Semicolons (;)\nExample:\n100,100.5,101,102,103")," ","")
txt1 = input.string("", title = "Text", group = "Group 1", inline = "2")
col1 = input.string("default", title = "Color", options = ["default","red","orange","yellow","green","blue","purple","white","black","gray"], group = "Group 1", inline = "2")
style1 = input.string("___", title = "Style", options = ["___","- - -",". . .","___zone","- - -zone",". . .zone"], group = "Group 1", inline = "2")
width1 = input.int(1, title = "Thickness", minval = 0, maxval = 5, group = "Group 1", inline = "2")
tog_1 = lvls1 == ""?false:true
output1 = tog_1?(symbol1 == ""?syminfo.tickerid:symbol1) + "," + (col1=="default"?" ":col1) + "," + linestyle(style1) + "," + str.tostring(width1*-1) + "," + (txt1 == ""?" ":txt1) + "," + remove_c(lvls1) + ";":""

symbol2 = input.symbol("", title  = "Ticker", group = "Group 2", inline = "2")
lvls2 = str.replace_all(input.string("", title = "Levels", group = "Group 2", inline = "2")," ","")
txt2 = input.string("", title = "Text", group = "Group 2", inline = "2")
col2 = input.string("default", title = "Color", options = ["default","red","orange","yellow","green","blue","purple","white","black","gray"], group = "Group 2", inline = "2")
style2 = input.string("___", title = "Style", options = ["___","- - -",". . .","___zone","- - -zone",". . .zone"], group = "Group 2", inline = "2")
width2 = input.int(1, title = "Thickness", minval = 0, maxval = 5, group = "Group 2", inline = "2")
tog_2 = lvls2 == ""?false:true
output2 = tog_2?((symbol2 == ""?syminfo.tickerid:symbol2) + "," + (col2=="default"?" ":col2) + "," + linestyle(style2) + "," + str.tostring(width2*-1) + "," + (txt2 == ""?" ":txt2) + "," + str.replace_all(lvls2," ","") + ";"):""

symbol3 = input.symbol("", title  = "Ticker", group = "Group 3", inline = "2")
lvls3 = str.replace_all(input.string("", title = "Levels", group = "Group 3", inline = "2")," ","")
txt3 = input.string("", title = "Text", group = "Group 3", inline = "2")
col3 = input.string("default", title = "Color", options = ["default","red","orange","yellow","green","blue","purple","white","black","gray"], group = "Group 3", inline = "2")
style3 = input.string("___", title = "Style", options = ["___","- - -",". . .","___zone","- - -zone",". . .zone"], group = "Group 3", inline = "2")
width3 = input.int(1, title = "Thickness", minval = 0, maxval = 5, group = "Group 3", inline = "2")
tog_3 = lvls3 == ""?false:true
output3 = tog_3?((symbol3 == ""?syminfo.tickerid:symbol3) + "," + (col3=="default"?" ":col3) + "," + linestyle(style3) + "," + str.tostring(width3*-1) + "," + (txt3 == ""?" ":txt3) + "," + str.replace_all(lvls3," ","") + ";"):""

symbol4 = input.symbol("", title  = "Ticker", group = "Group 4", inline = "2")
lvls4 = str.replace_all(input.string("", title = "Levels", group = "Group 4", inline = "2")," ","")
txt4 = input.string("", title = "Text", group = "Group 4", inline = "2")
col4 = input.string("default", title = "Color", options = ["default","red","orange","yellow","green","blue","purple","white","black","gray"], group = "Group 4", inline = "2")
style4 = input.string("___", title = "Style", options = ["___","- - -",". . .","___zone","- - -zone",". . .zone"], group = "Group 4", inline = "2")
width4 = input.int(1, title = "Thickness", minval = 0, maxval = 5, group = "Group 4", inline = "2")
tog_4 = lvls4 == ""?false:true
output4 = tog_4?((symbol4 == ""?syminfo.tickerid:symbol4) + "," + (col4=="default"?" ":col4) + "," + linestyle(style4) + "," + str.tostring(width4*-1) + "," + (txt4 == ""?" ":txt4) + "," + str.replace_all(lvls4," ","") + ";"):""

symbol5 = input.symbol("", title  = "Ticker", group = "Group 5", inline = "2")
lvls5 = str.replace_all(input.string("", title = "Levels", group = "Group 5", inline = "2")," ","")
txt5 = input.string("", title = "Text", group = "Group 5", inline = "2")
col5 = input.string("default", title = "Color", options = ["default","red","orange","yellow","green","blue","purple","white","black","gray"], group = "Group 5", inline = "2")
style5 = input.string("___", title = "Style", options = ["___","- - -",". . .","___zone","- - -zone",". . .zone"], group = "Group 5", inline = "2")
width5 = input.int(1, title = "Thickness", minval = 0, maxval = 5, group = "Group 5", inline = "2")
tog_5 = lvls5 == ""?false:true
output5 = tog_5?((symbol5 == ""?syminfo.tickerid:symbol5) + "," + (col5=="default"?" ":col5) + "," + linestyle(style5) + "," + str.tostring(width5*-1) + "," + (txt5 == ""?" ":txt5) + "," + str.replace_all(lvls5," ","") + ";"):""

symbol6 = input.symbol("", title  = "Ticker", group = "Group 6", inline = "2")
lvls6 = str.replace_all(input.string("", title = "Levels", group = "Group 6", inline = "2")," ","")
txt6 = input.string("", title = "Text", group = "Group 6", inline = "2")
col6 = input.string("default", title = "Color", options = ["default","red","orange","yellow","green","blue","purple","white","black","gray"], group = "Group 6", inline = "2")
style6 = input.string("___", title = "Style", options = ["___","- - -",". . .","___zone","- - -zone",". . .zone"], group = "Group 6", inline = "2")
width6 = input.int(1, title = "Thickness", minval = 0, maxval = 5, group = "Group 6", inline = "2")
tog_6 = lvls6 == ""?false:true
output6 = tog_6?((symbol6 == ""?syminfo.tickerid:symbol6) + "," + (col6=="default"?" ":col6) + "," + linestyle(style6) + "," + str.tostring(width6*-1) + "," + (txt6 == ""?" ":txt6) + "," + lvls6 + ";"):""

//Inputs/////////////////////////////////////////////////////////////////
input = str.upper(output1 + output2 + output3 + output4 + output5 + output6)
//No Level Message//////////////////////////////////////////////////////////////
if str.contains(input,syminfo.ticker) == false
    runtime.error("No levels for this ticker. Please input levels or change ticker. Current Ticker: " + syminfo.ticker)
//Variable initialization///////////////////////////////////////////////////////
var line lvl_line = na
var label lvl_lab = na
var line z1 = na
var line z2 = 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))
////////////////////////////////////////////////////////////////////////////////
//Line and label drawing
split = str.split(input,";")
for i = 0 to array.size(split) - 1 
    split_get = array.get(split,i)
    small_split = str.split(split_get,",")
    if array.size(small_split) > 5
        ssf = str.replace_all(array.get(small_split,0)," ","")
        if (ssf == syminfo.ticker) or (ssf == syminfo.tickerid)  or (ssf == "\n" + syminfo.ticker) or (ssf == "\n" + syminfo.tickerid)
            for e = 5 to array.size(small_split) - 1
                lvl = str.replace_all(array.get(small_split,e)," ","")
                co = colorpicker(str.replace_all(array.get(small_split,1)," ",""))
                sty = stylepicker(str.replace_all(array.get(small_split,2)," ",""))
                z = str.contains(str.replace_all(array.get(small_split,2)," ",""),"ZONE")
                thick = str.tonumber(str.replace_all(array.get(small_split,3)," ","")) < 0? str.tonumber(str.replace_all(array.get(small_split,3)," ","")) * -1:1
                txt = tog_lvl?array.get(small_split,4) +" "+ str.format("{0,number,currency}",str.tonumber(lvl)):array.get(small_split,4)
                if str.tonumber(lvl) > 0 and (z == false)
                    lvl_line := line.new(bar_index,str.tonumber(lvl),bar_index+1,str.tonumber(lvl), extend = extend.right, color = co, style = sty, width = int(thick))
                    lvl_lab := label.new(bar_index + lab_offset, str.tonumber(lvl), text = txt , color = color.new(color.black,100), size = lab_size, textcolor = co, style = label.style_label_lower_left)    
                if z and (array.size(small_split) == 7) and (e == 6)
                    z_lvl1 = math.max(str.tonumber(str.replace_all(array.get(small_split,5)," ","")),str.tonumber(str.replace_all(array.get(small_split,6)," ","")))
                    z_lvl2 = math.min(str.tonumber(str.replace_all(array.get(small_split,5)," ","")),str.tonumber(str.replace_all(array.get(small_split,6)," ","")))
                    z_txt = tog_lvl?array.get(small_split,4) +" "+ str.format("{0,number,currency}",z_lvl2) + " - " + str.format("{0,number,currency}",z_lvl1):array.get(small_split,4)
                    lvl_lab := label.new(bar_index + lab_offset, z_lvl1, text = z_txt , color = color.new(color.black,100), size = lab_size, textcolor = co, style = label.style_label_lower_left)   
                    z1 := line.new(bar_index,z_lvl1,bar_index+1,z_lvl1, extend = extend.right, color = co, style = sty, width = int(thick))
                    z2 := line.new(bar_index,z_lvl2,bar_index+1,z_lvl2, extend = extend.right, color = co, style = sty, width = int(thick))
                    linefill.new(z1,z2, color = color.new(co,z_op))
