I am trying to plot something on the chart based on some conditions. But I want it to be plotted for the last day candles only. I have written this code to find a condition which is true for the last day only based on the bar index. The condition is true mathematically but pine is considering it to be false for many candles. What am I missing here? You can see the last day has 24 bars and I have found the range of the bar_index for this day which is 20349 to 20373. But the labels show that this condition is false.
//@version=5
indicator(title = "Check", overlay = true)
newDay = dayofweek != dayofweek[1]
bars_since_newday = ta.barssince(newDay )
last_bar = last_bar_index
today = bar_index >= (last_bar - bars_since_newday)
l = label.new(bar_index, high, str.tostring(today), style = label.style_none, textcolor = color.white )
l1 = label.new(bar_index, low-50, "last index = " + str.tostring(last_bar) + "\n bars since newday = " + str.tostring(bars_since_newday) + "\n difference = " + str.tostring(last_bar - bars_since_newday), style = label.style_none, textcolor = color.white )
label.delete(l1[1] )