the way current day sessions  labels and lines are plotted, in the same way plot lines where sessions labels are plotted and the line should only be till the end of day candle not extended ahead of it, plot lines with break. //@version=5
indicator("Session Opening Price Lines", shorttitle="Session Opens", overlay=true)

// Input settings for session visibility
show_session = input.string("All", "Show Sessions", options=["All", "Sydney", "Tokyo", "London", "New York"], group="Sessions")
show_all_lines = input.bool(true, "Show All Lines and Titles", group="Sessions")
show_historical_lines = input.bool(true, "Show Historical Lines", group="Sessions")

// Line styles and colors
sydney_color = input.color(color.new(color.purple, 0), "Sydney Color", group="Styling")
tokyo_color = input.color(color.new(color.red, 0), "Tokyo Color", group="Styling")
london_color = input.color(color.new(color.blue, 0), "London Color", group="Styling")
newyork_color = input.color(color.new(color.green, 0), "New York Color", group="Styling")

line_style = input.string("Solid", "Line Style", options=["Solid", "Dashed", "Dotted"], group="Styling")
line_width = input.int(1, "Line Width", minval=1, maxval=5, group="Styling")

// Convert line style
get_line_style() =>
    switch line_style
        "Dashed" => line.style_dashed
        "Dotted" => line.style_dotted
        => line.style_solid

// Check if current timeframe is intraday
is_intraday = timeframe.in_seconds() < 86400 // Less than 1 day

// Function to check if current time is session start
is_session_start(start_hour, start_minute) =>
    hour == start_hour and minute == start_minute

// Session start times (UTC)
sydney_start = is_session_start(21, 0)
tokyo_start = is_session_start(23, 0)
london_start = is_session_start(7, 0)
newyork_start = is_session_start(12, 0)

// Variables to store opening prices
var float sydney_open = na
var float tokyo_open = na
var float london_open = na
var float newyork_open = na

// Variables to store line references
var line sydney_line = na
var line tokyo_line = na
var line london_line = na
var line newyork_line = na

// Function to create session line
create_session_line(session_open, color_input, show_session) =>
    if is_intraday and show_session and show_all_lines and not na(session_open)
        line.new(bar_index, session_open, bar_index[1], session_open, color=color_input, style=get_line_style(), width=line_width)

// Function to extend existing line
extend_session_line(line_ref, session_open, show_session) =>
    if is_intraday and show_session and show_all_lines and not na(line_ref) and not na(session_open)
        line.set_xy2(line_ref, bar_index, session_open)

// Determine visibility based on dropdown selection
show_sydney = (show_session == "All" or show_session == "Sydney") and show_all_lines
show_tokyo = (show_session == "All" or show_session == "Tokyo") and show_all_lines
show_london = (show_session == "All" or show_session == "London") and show_all_lines
show_newyork = (show_session == "All" or show_session == "New York") and show_all_lines

// Update opening prices and create/extend lines
if sydney_start and is_intraday
    sydney_open := open
    if show_sydney
        if not na(sydney_line)
            line.delete(sydney_line)
        sydney_line := create_session_line(sydney_open, sydney_color, show_sydney)

if tokyo_start and is_intraday
    tokyo_open := open
    if show_tokyo
        if not na(tokyo_line)
            line.delete(tokyo_line)
        tokyo_line := create_session_line(tokyo_open, tokyo_color, show_tokyo)

if london_start and is_intraday
    london_open := open
    if show_london
        if not na(london_line)
            line.delete(london_line)
        london_line := create_session_line(london_open, london_color, show_london)

if newyork_start and is_intraday
    newyork_open := open
    if show_newyork
        if not na(newyork_line)
            line.delete(newyork_line)
        newyork_line := create_session_line(newyork_open, newyork_color, show_newyork)

// Extend lines during the session (only if not at session start)
if is_intraday and not sydney_start and show_historical_lines
    extend_session_line(sydney_line, sydney_open, show_sydney)

if is_intraday and not tokyo_start and show_historical_lines
    extend_session_line(tokyo_line, tokyo_open, show_tokyo)

if is_intraday and not london_start and show_historical_lines
    extend_session_line(london_line, london_open, show_london)

if is_intraday and not newyork_start and show_historical_lines
    extend_session_line(newyork_line, newyork_open, show_newyork)

// Optional: Add labels for session identification
if sydney_start and is_intraday and show_sydney and show_all_lines
    label.new(bar_index, sydney_open, "SYD", style=label.style_label_down, color=sydney_color, textcolor=color.white, size=size.small)

if tokyo_start and is_intraday and show_tokyo and show_all_lines
    label.new(bar_index, tokyo_open, "TKY", style=label.style_label_down, color=tokyo_color, textcolor=color.white, size=size.small)

if london_start and is_intraday and show_london and show_all_lines
    label.new(bar_index, london_open, "LON", style=label.style_label_down, color=london_color, textcolor=color.white, size=size.small)

if newyork_start and is_intraday and show_newyork and show_all_lines
    label.new(bar_index, newyork_open, "NYC", style=label.style_label_down, color=newyork_color, textcolor=color.white, size=size.small)

// Plot invisible lines for reference (optional)
plot(is_intraday and show_sydney ? sydney_open : na, color=color.new(sydney_color, 90), linewidth=1, title="Sydney Open Reference")
plot(is_intraday and show_tokyo ? tokyo_open : na, color=color.new(tokyo_color, 90), linewidth=1, title="Tokyo Open Reference")
plot(is_intraday and show_london ? london_open : na, color=color.new(london_color, 90), linewidth=1, title="London Open Reference")
plot(is_intraday and show_newyork ? newyork_open : na, color=color.new(newyork_color, 90), linewidth=1, title="New York Open Reference")