Lines disappear when toggling others
05:17 06 Jun 2026

By looking at other scripts and the Pine user manual I managed to get quite far but there is one little bug in can't get rid of.

This indicator shows (is the goal) vertical lines on a specific time on both previous days and the following instance of the current day.

For previous days I'm using

xloc = xloc.bar_index

For the upcoming line on the current day I'm using UNIX with

xloc = xloc.bar_time

The problem is that previous lines disappear when 'Show future Line' is togled on.

I thought that using the same variable ShowLine1 as condition for both previous and future lines was the reason but no and I'm now stuck.

One other issue with the script (or maybe the cause) is that the script doesn't check whether the UNIX timestamp for the line has already been passed by the live time resulting in both the bar_index and bar_time lines being drawn on top of each other.

//@version=6
indicator("Vertical Lines Past+Future", "V_Lines", overlay = true)

// Timezone
timezoneInput = input.string("UTC-4:00", "Time zone", tooltip = "See bottom right corner. Also accepts America/New_York ect.")

ShowLine1 = input.bool(true, title="1", inline= "1", group="Vertical Lines")
Time_HH1 = input.int(7, "Hour", minval=0, maxval=23, inline= "1", group="Vertical Lines")
Time_mm1 = input.int(00, "Minute", minval=0, maxval=59, inline="1", group="Vertical Lines")
Color1 = input.color(#272C3B, "Color", inline="1", group="Vertical Lines")

InputStyle =  input.string("Solid", "Line Style", options = ["Solid", "Dashed", "Dotted"], inline="6", group="Vertical Lines")
lineStyle = switch InputStyle
    "Solid"  => line.style_solid
    "Dashed" => line.style_dashed
    "Dotted" => line.style_dotted
 //   => line.style_solid

LineWidth = input.int(1, "Line Width", options = [1,2,3,4,5], inline="6", group="Vertical Lines")

InputFutureLines = input.bool(true, "Show Future Lines", group="Vertical Lines")

// ───── Culculations ─────
// Previous Lines
barHour = hour(time, timezoneInput)
barMinute = minute(time, timezoneInput)

// Conditions
PreviousLines1 = ShowLine1 and barHour == Time_HH1 and barMinute == Time_mm1

// Current Day Lines
// Get the midnight timestamp of the current real-world day (using timenow)
int currentYear  = year(time, timezoneInput)
int currentMonth = month(time, timezoneInput)
int currentDay   = dayofmonth(time, timezoneInput)

// Construct the midnight timestamp (ms)
int UNIXmidnight = timestamp(timezoneInput, currentYear, currentMonth, currentDay, 0, 0, 0)

// Assign the number of milliseconds in hourly and minute units to "const" variables for calculations.
const int ONE_HOUR   =   3600000
const int ONE_MINUTE =     60000

UNIXperiod1  = (Time_HH1 * ONE_HOUR) + (Time_mm1 * ONE_MINUTE)

CurrentDayTime1 = UNIXmidnight + UNIXperiod1

// Conditions
ShowFutLine1 = ShowLine1

ShowFutureLine1 = ShowFutLine1 and InputFutureLines

// ───── Draw Lines ─────
// Previous Days
if PreviousLines1
    line.new(bar_index, low, bar_index, high, xloc = xloc.bar_index, extend = extend.both, color = Color1, style = lineStyle, width = LineWidth)

// Current Day
if ShowFutureLine1
    line.new(CurrentDayTime1, low, CurrentDayTime1, high, xloc = xloc.bar_time, extend = extend.both, color = Color1, style = lineStyle, width = LineWidth)
pine-script pine-script-v6