I'm trying to calculate the remaining seconds in real time until the bar closes.
I did this:
" timeLeft = barstate.isrealtime ? (time_close - timenow) / 1000 : na
secLeft = floor(timeLeft)
plot(series=secLeft, title="Seconds left") "
But the problem is that timenow is not updated often enough (I have calc_on_every_tick=true) and because of that the seconds are not in real time.
Can anyone help?
Your technique is sound, but see the usrman on execution in the realtime bar.
Execution of Pine scripts in the realtime bar is event-driven. When no user action (like a change in the script's Inputs) causes a re-execution, it requires a price or volume update to be detected on the feed, which happens at random intervals.