the way current day sessions labels and lines are plotted, in the same way plot lines…
- User
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")
- Assistant
Below is one example of how you might modify your script so that a “session line” is drawn only during the same trading day—i.e. the line is started at the session’s open and then extended only until the end‐of‐day bar. When a new day starts a new session’s line is begun and the previous day’s line remains “broken” (not extended into the new day).
In the code below we “remember” the year, month and day when each session starts. Then, when extending the session line on every new bar we update the line only if the current bar’s date matches the stored session date. (When the day changes the line is no longer updated.) You can adapt this example to your needs.
Below is the complete modified script:
//@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 the session’s date stamp (year, month, day) var int sydney_session_year = 0 var int sydney_session_month = 0 var int sydney_session_day = 0 var int tokyo_session_year = 0 var int tokyo_session_month = 0 var int tokyo_session_day = 0 var int london_session_year = 0 var int london_session_month = 0 var int london_session_day = 0 var int newyork_session_year = 0 var int newyork_session_month= 0 var int newyork_session_day = 0 // 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 that starts at the current bar and its endpoint is initially the same. // (Its endpoint will be updated on later bars—provided we are still in the same day.) 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, session_open, color=color_input, style=get_line_style(), width=line_width) // 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 // On session start, record the open price and the current date for that session, // and (if enabled) create a new line. if sydney_start and is_intraday sydney_open := open sydney_session_year := year(time) sydney_session_month := month(time) sydney_session_day := dayofmonth(time) 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 tokyo_session_year := year(time) tokyo_session_month := month(time) tokyo_session_day := dayofmonth(time) 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 london_session_year := year(time) london_session_month := month(time) london_session_day := dayofmonth(time) 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 newyork_session_year := year(time) newyork_session_month := month(time) newyork_session_day := dayofmonth(time) if show_newyork if not na(newyork_line) line.delete(newyork_line) newyork_line := create_session_line(newyork_open, newyork_color, show_newyork) // On every bar (except on the session-start bar) update (extend) the session line, // but only if the current bar’s date matches the session’s date. // (After the end-of-day candle, the date no longer matches and the line is not extended.) if is_intraday and show_historical_lines and not sydney_start and (year(time) == sydney_session_year) and (month(time) == sydney_session_month) and (dayofmonth(time) == sydney_session_day) if not na(sydney_line) and not na(sydney_open) line.set_xy2(sydney_line, bar_index, sydney_open) if is_intraday and show_historical_lines and not tokyo_start and (year(time) == tokyo_session_year) and (month(time) == tokyo_session_month) and (dayofmonth(time) == tokyo_session_day) if not na(tokyo_line) and not na(tokyo_open) line.set_xy2(tokyo_line, bar_index, tokyo_open) if is_intraday and show_historical_lines and not london_start and (year(time) == london_session_year) and (month(time) == london_session_month) and (dayofmonth(time) == london_session_day) if not na(london_line) and not na(london_open) line.set_xy2(london_line, bar_index, london_open) if is_intraday and show_historical_lines and not newyork_start and (year(time) == newyork_session_year) and (month(time) == newyork_session_month) and (dayofmonth(time) == newyork_session_day) if not na(newyork_line) and not na(newyork_open) line.set_xy2(newyork_line, bar_index, newyork_open) // Optional: Add labels at the session opening (the label is drawn on the same bar as the session start) 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) // Optionally, plot invisible reference plots (they will be drawn only for the current bar) 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")
How It Works
-
Session start detection and recording the date:
When the current bar’s time equals the session start (for example, 21:00 UTC for Sydney) the script records the session’s open price and also the year, month and day of that bar. Any previous line for the session is deleted and a new line is created starting at the current bar. -
Updating the session line until end-of-day:
On every subsequent bar, the script checks whether the current bar’s date (year, month and day) matches the saved session date. If so—and if “historical lines” are enabled—the line’s ending coordinate is updated to the current bar. When the day ends (i.e. a new day begins) the condition fails so the line stops updating. This creates a “break” at the end of the day (much like how labels are only plotted on the session start). -
Labels & Optional Reference Plots:
The script also adds labels at the session start and optional reference plots for your sessions.
Feel free to adjust the session start times, colors, styles and other settings for your specific needs.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.