Remaining seconds until bar close - pine script

943 Views Asked by At

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.

Picture

Can anyone help?

1

There are 1 best solutions below

3
PineCoders-LucF On

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.