OPEN-SOURCE SCRIPT

Vertical Lines Every 12 Hours

52
//version=5
indicator("Vertical Lines Every 12 Hours", overlay=true)

// Get the current time in milliseconds since the Unix epoch
currentTime = time

// Calculate 12 hours in milliseconds (12 hours * 60 minutes/hour * 60 seconds/minute * 1000 milliseconds/second)
twelveHoursInMs = 12 * 60 * 60 * 1000

// Determine the timestamp of the last 12-hour mark
// We use 'time / twelveHoursInMs' to get the number of 12-hour blocks since epoch,
// then multiply by 'twelveHoursInMs' to get the start of the current 12-hour block.
// Adding 'twelveHoursInMs' ensures we plot at the *next* 12-hour mark.
// The modulo operator '%' helps us check if the current bar's time is exactly
// at a 12-hour interval relative to the start of the current day.
// This approach tries to align the lines consistently.

// A more robust way to do this is to check if the hour changes to 00:00 or 12:00 UTC (or your preferred timezone)
// and plot a line then. However, for "every 12 hours" relative to the chart's start,
// a simple time-based check is often sufficient.

// Let's refine the logic to hit specific 12-hour intervals like 00:00 and 12:00 daily (UTC as an example).
// You might need to adjust the timezone based on your chart's time zone settings and your preference.

// Get the hour of the day for the current bar's timestamp
hourOfDay = hour(time, "GMT") // "GMT" for UTC, adjust as needed (e.g., "America/New_York", "Asia/Jerusalem")

// Plot a vertical line if the hour is 0 (midnight) or 12 (noon)
if hourOfDay == 0 or hourOfDay == 12
line.new(x1=bar_index, y1=low, x2=bar_index, y2=high, extend=extend.both, color=color.blue, width=1)

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.