OPEN-SOURCE SCRIPT
Vertical Lines Every 12 Hours

//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)
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)
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。