Skip to content
GetProfitable
Search
Sessions and time

Time Left on Bar

A corner table counting down the time until the current bar closes, which takes the guesswork out of waiting for a candle to finish instead of acting halfway through it.

indicator
//@version=6
indicator("Time Left on Bar", "Timer", overlay = true)

warnSeconds = input.int(10, "Warn under seconds", minval = 1, group = "Settings")
labelCol = input.color(#787B86, "Labels", group = "Style")
readyCol = input.color(#26A69A, "Time remaining", group = "Style")
warnCol = input.color(#EF5350, "Closing soon", group = "Style")

msLeft = math.max(time_close - timenow, 0)
secondsLeft = int(math.floor(msLeft / 1000))
closingSoon = secondsLeft <= warnSeconds
countdown = str.format_time(int(msLeft), "HH:mm:ss", "UTC")
valueCol = closingSoon ? warnCol : readyCol

var table panel = table.new(position.bottom_right, 2, 2, border_width = 1)

if barstate.islast
    table.cell(panel, 0, 0, "Bar closes in", text_color = labelCol, text_size = size.small)
    table.cell(panel, 1, 0, countdown, text_color = valueCol, text_size = size.small)
    table.cell(panel, 0, 1, "Seconds left", text_color = labelCol, text_size = size.small)
    table.cell(panel, 1, 1, str.tostring(secondsLeft), text_color = valueCol, text_size = size.small)
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • The countdown only updates when a new tick arrives, so on a quiet symbol it sits still and then jumps several seconds at once.
  • It is meaningful only on the last bar in real time. On historical bars the close time has already passed and the reading is zero.
  • On weekly and monthly charts the time remaining exceeds a day and the clock display wraps, so read it on intraday charts.
  • Waiting for a bar to close is a choice about your own process. The countdown says nothing about what price will do next.

Written from this description

Show a small table in the corner with the time and the seconds remaining until the current bar closes, and colour the countdown once it drops under a chosen number of seconds.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.