So I have limited experience with coding and have been trying to make edits to an open-script that displays horizontal lines at user defined levels. Uses Pinescript v5.
I’ve provided the script below. I am trying to have each of the user defined levels for a given input to be displayed across specific days of the week and or time. Anyone have guidance on how I can do this?
I think I need to be incorporating the “ta.change(time(‘D’))” but am unsure of how to apply that. Any help is appreciated!
//@version=5
indicator("Juno's 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")
t_id = ticker.standard(syminfo.tickerid)
symbol1 = input.symbol("", title = "Ticker", group = "Group 1", inline = "2")
lvls1 = str.replace_all(input.string("", title = "Levels", group = "Group 1", inline = "2", tooltip = "LEVELSnInsert 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 == ""?t_id: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 == ""?t_id: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 == ""?t_id:symbol3) + "," + (col3=="default"?" ":col3) + "," + linestyle(style3) + "," + str.tostring(width3*-1) + "," + (txt3 == ""?" ":txt3) + "," + str.replace_all(lvls3," ","") + ";"):""
//Inputs/////////////////////////////////////////////////////////////////
input = str.upper(output1 + output2 + output3)
//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 == ticker.standard(t_id)) or (ssf == "n" + syminfo.ticker) or (ssf == "n" + ticker.standard(t_id))
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
lvl_num = str.tonumber(lvl)
txt = tog_lvl?array.get(small_split,4) +" "+ str.tostring(lvl_num):array.get(small_split,4)
if lvl_num > 0 and (z == false)
lvl_line := line.new(bar_index,lvl_num,bar_index+1,lvl_num, extend = extend.right, color = co, style = sty, width = int(thick))
lvl_lab := label.new(bar_index + lab_offset, lvl_num, 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.tostring(z_lvl2) + " - " + str.tostring(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))`