I’m writing a pine script for TradingView (Indicator), and I have a specific session.
I want that the session will be drawn on the chart only on the previous day.
for example today is 03/05/24, I want that my code will be only drawn on 02/05/24.
This is my code:
my_session = input.session("0400-0430", '', group="Tests")
is_my_session = math.sign(nz(time("5", my_session)))
get_range(session, session_name, session_css)=>
var t = 0
var max = high
var min = low
var box bx = na
var label lbl = na
if session > session[1]
t := time
max := high
min := low
bx := box.new(n, max, n, min
, bgcolor = color.new(session_css, bg_transp)
, border_color = show_outline ? session_css : na
, border_style = line.style_dotted)
if show_txt
lbl := label.new(t, max, session_name
, xloc = xloc.bar_time
, textcolor = session_css
, style = label.style_label_down
, color = color.new(color.white, 100)
, size = size.tiny)
if session and session == session[1]
max := math.max(high, max)
min := math.min(low, min)
box.set_top(bx, max)
box.set_rightbottom(bx, n, min)
if show_txt
label.set_xy(lbl, int(math.avg(t, time)), max)
get_range(is_my_session, "My session", color.new(24,24,24))
I was trying comparing the time and timenow but it didn’t work.