Hey I don’t know how to use pinescript at all. I want to create a text editable horizontal ray(and editable color of the text) that shows the high and low price of different specified time ranges? Ex. yesterday 6am-9:59am, yesterday 9:30am-11:59am, yesterday 12pm-4:59pm, today 12am-6am.
It would function and look kinda like this. https://www.tradingview.com/x/W65Ad970/
I shamefully tried to get an output using chat gpt which was just BAD even after several interactions. Is this something that’s even possible? I want it to show on all timeframes <=60 min.
This was the code:
//@version=5
indicator("Time Range High-Low Rays", overlay=true)
// Input for editable text
input_text_yest_6_10 = input.string("Yesterday 6am-10am", title="Text for Yesterday 6am-10am")
input_text_yest_10_12 = input.string("Yesterday 10am-12pm", title="Text for Yesterday 10am-12pm")
input_text_yest_12_5 = input.string("Yesterday 12pm-5pm", title="Text for Yesterday 12pm-5pm")
input_text_today_12_6 = input.string("Today 12am-6am", title="Text for Today 12am-6am")
// Variables to hold high and low values for different time ranges
var float high_yest_6_10 = na
var float low_yest_6_10 = na
var float high_yest_10_12 = na
var float low_yest_10_12 = na
var float high_yest_12_5 = na
var float low_yest_12_5 = na
var float high_today_12_6 = na
var float low_today_12_6 = na
// Function to get the previous day's date
prev_day = timestamp(year, month, dayofmonth - 1, 0, 0)
// Functions to update high and low values for each time range
if (hour == 6 and minute == 0)
high_yest_6_10 := na
low_yest_6_10 := na
if (hour == 10 and minute == 0)
high_yest_6_10 := high
low_yest_6_10 := low
if (hour == 10 and minute == 30)
high_yest_10_12 := na
low_yest_10_12 := na
if (hour == 12 and minute == 0)
high_yest_10_12 := high
low_yest_10_12 := low
if (hour == 12 and minute == 30)
high_yest_12_5 := na
low_yest_12_5 := na
if (hour == 17 and minute == 0)
high_yest_12_5 := high
low_yest_12_5 := low
if (hour == 0 and minute == 0)
high_today_12_6 := na
low_today_12_6 := na
if (hour == 6 and minute == 0)
high_today_12_6 := high
low_today_12_6 := low
// Functions to draw lines and labels for each time range
draw_range(start_time, end_time, high_price, low_price, label_text) =>
line.new(x1=start_time, y1=high_price, x2=end_time, y2=high_price, xloc=xloc.bar_time, extend=extend.right, color=color.red)
line.new(x1=start_time, y1=low_price, x2=end_time, y2=low_price, xloc=xloc.bar_time, extend=extend.right, color=color.green)
label.new(x=end_time, y=high_price, text=label_text, xloc=xloc.bar_time, style=label.style_label_right, textcolor=color.white, color=color.red, textalign=text.align_right)
label.new(x=end_time, y=low_price, text=label_text, xloc=xloc.bar_time, style=label.style_label_right, textcolor=color.white, color=color.green, textalign=text.align_right)
// Calculate start times for the ranges
timestamp_yest_6_10_start = timestamp("GMT-5", year, month, dayofmonth - 1, 6, 0)
timestamp_yest_10_12_start = timestamp("GMT-5", year, month, dayofmonth - 1, 10, 30)
timestamp_yest_12_5_start = timestamp("GMT-5", year, month, dayofmonth - 1, 12, 0)
timestamp_today_12_6_start = timestamp("GMT-5", year, month, dayofmonth, 0, 0)
// Calculate end times for the ranges
timestamp_end_of_day = timestamp("GMT-5", year, month, dayofmonth, 23, 59)
// Draw ranges if high and low values are not na
if not na(high_yest_6_10) and not na(low_yest_6_10)
draw_range(timestamp_yest_6_10_start, timestamp_end_of_day, high_yest_6_10, low_yest_6_10, input_text_yest_6_10)
if not na(high_yest_10_12) and not na(low_yest_10_12)
draw_range(timestamp_yest_10_12_start, timestamp_end_of_day, high_yest_10_12, low_yest_10_12, input_text_yest_10_12)
if not na(high_yest_12_5) and not na(low_yest_12_5)
draw_range(timestamp_yest_12_5_start, timestamp_end_of_day, high_yest_12_5, low_yest_12_5, input_text_yest_12_5)
if not na(high_today_12_6) and not na(low_today_12_6)
draw_range(timestamp_today_12_6_start, timestamp_end_of_day, high_today_12_6, low_today_12_6, input_text_today_12_6)
Ryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.