Hi i have a script that automatically draw open price of 00:00 and 08:30 candles. The problem is the code only mark for current day, not for historical data. Can anyone help me modify the code so that it can also mark these point in previous day. Thank you in advance
//@version=5
indicator("Daily Open Price Markers", overlay=true, max_bars_back=2880)
// Define timezone as New York time
time_zone = "America/New_York"
// Variables to store open prices and timestamps
var float open_0000 = na
var float open_0830 = na
var int time_0000 = na
var int time_0830 = na
var int time_1100 = na
// Function to get the time of 11:00 AM New York time
f_get_1100_time() =>
// Search for the 11:00 AM New York time bar within the last 720 bars
var int eleven_am_time = na
for i = 0 to 719
if (hour(time[i], time_zone) == 11 and minute(time[i], time_zone) == 0)
eleven_am_time := time[i]
break
eleven_am_time
// Loop through bars to find and mark the open prices of 00:00 AM and 08:30 AM candles
if (bar_index > 0)
current_day = dayofmonth(time[0], time_zone)
// Find and set open and timestamp for 00:00 AM New York time candle
if (hour(time, time_zone) == 0 and minute(time, time_zone) == 0)
open_0000 := open
time_0000 := time
// Find and set open and timestamp for 08:30 AM New York time candle
if (hour(time, time_zone) == 8 and minute(time, time_zone) == 30)
open_0830 := open
time_0830 := time
// Get the 11:00 AM New York time
time_1100 = f_get_1100_time()
// Draw lines if we have all necessary times
if not na(open_0000) and not na(time_0000) and not na(time_1100)
line.new(x1=time_0000, y1=open_0000, x2=time_1100, y2=open_0000, color=color.red, width=1, xloc=xloc.bar_time)
if not na(open_0830) and not na(time_0830) and not na(time_1100)
line.new(x1=time_0830, y1=open_0830, x2=time_1100, y2=open_0830, color=color.blue, width=1, xloc=xloc.bar_time)
This is what I get from the above code. The black line represent the day seperator
text
New contributor
superduper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.