I am trying to create a line from an exact time that I will enter as input for each day (for 5 days) but I cant make it work. The following code is one part of it that seems to work correctly by putting lines at correct places but even though I meant to create only one line (one day) it is repeating for everyday possible. I commented out the remaining part of the code which is the repeat of the last part by creating targetTime1, targetTime2 and etc. because I was trying to figure out where is the problem.
I tried to do this in a loop too, it failed exactly like this. If you could help me find why it is repeating for everyday even though I use a timestamp including year, month, day I would really appreciate it.
I am also trying to make this available for all timeframes and if the entered time is not on the table then it may not show its okay.
the following code is what I have right now, and the picture is somewhat what I am going for:
//@version=5
indicator("Price Lines for Last 5 Days", overlay=true)
// Input for custom time (adjustable)
inputHour = input.int(defval=12, title="Hour (24-hour format)", minval=0, maxval=23)
inputMinute = input.int(defval=0, title="Minute", minval=0, maxval=59)
// Color array for 5 different lines
colorArray = array.new_color(5)
array.set(colorArray, 0, color.red)
array.set(colorArray, 1, color.green)
array.set(colorArray, 2, color.blue)
array.set(colorArray, 3, color.orange)
array.set(colorArray, 4, color.purple)
// Function to get the timestamp for a specific day and time
get_target_time_for_day (int dayOffset) =>
timestamp("GMT+3", year, month, dayofmonth - dayOffset, inputHour, inputMinute)
targetTime0 = get_target_time_for_day(0)
// Only draw the line if we're on or past the time for that specific day
if (time == targetTime0)
linePrice = ta.valuewhen(time == targetTime0, close, 0)
// Create and store a new line for that day
newLine = line.new(bar_index, linePrice, bar_index + 400, linePrice, color=array.get(colorArray, 0), width=2)