Displays a real-time countdown timer showing the time remaining until the current candle closes, with dynamic positioning based on candle direction.
Access the tab at the bottom of your TradingView chart.
//@version=6
// ============================================================================
// Candle Countdown Timer
// ============================================================================
// Description: Displays a real-time countdown timer showing the time remaining
// until the current candle closes. The timer dynamically positions
// itself based on candle direction and user preferences.
//
// Features:
// - Auto-adapts to any timeframe (1m, 5m, 1h, 1D, etc.)
// - Dynamic positioning (candle high/low or current price)
// - Color-coded by candle direction (bullish/bearish)
// - Customizable font size and opacity
//
// Author: DayTradeLab
// Website: www.daytradelab.com
// ============================================================================
indicator("Candle CountdownTimer", overlay=true)
// ============================================================================
// CONSTANTS
// ============================================================================
var int millisInSecond = 1000
var int secondsInMinute = 60
var int minutesInHour = 60
var int hoursInDay = 24
// ============================================================================
// USER INPUTS (HIDDEN FROM HEADER)
// ============================================================================
fontSize = input.int(12, "Font Size",
minval=8, maxval=50,
group="Display Settings",
display=display.none)
textOpacity = input.int(0, "Text Opacity",
minval=0, maxval=100,
group="Display Settings",
display=display.none)
placement = input.string("Candle High/Low", "Placement",
options=["Candle High/Low", "Current Price"],
group="Display Settings",
display=display.none)
// ============================================================================
// TIME CALCULATION
// ============================================================================
timeLeft = time_close - timenow
secondsLeft = timeLeft / millisInSecond
hours = math.floor(secondsLeft / (secondsInMinute * minutesInHour))
minutes = math.floor((secondsLeft % (secondsInMinute * minutesInHour)) / secondsInMinute)
seconds = math.floor(secondsLeft % secondsInMinute)
// ============================================================================
// FORMAT TIMER
// ============================================================================
hoursStr = str.tostring(hours, "#")
minutesStr = str.tostring(minutes < 10 ? "0" : "") + str.tostring(minutes, "#")
secondsStr = str.tostring(seconds < 10 ? "0" : "") + str.tostring(seconds, "#")
countdownText = hours > 0 ? hoursStr + ":" + minutesStr + ":" + secondsStr : minutesStr + ":" + secondsStr
// ============================================================================
// COLOUR
// ============================================================================
isBullish = close > open
candleColor = isBullish ? color.green : color.red
finalTextColor = color.new(candleColor, textOpacity)
// ============================================================================
// POSITIONING
// ============================================================================
labelStyle = placement == "Current Price" ? label.style_label_left :
(isBullish ? label.style_label_down : label.style_label_up)
labelY = placement == "Current Price" ? close :
(isBullish ? high : low)
// ============================================================================
// FONT SIZE
// ============================================================================
actualSize = fontSize <= 10 ? size.tiny :
fontSize <= 14 ? size.small :
fontSize <= 18 ? size.normal :
fontSize <= 24 ? size.large :
size.huge
// ============================================================================
// LABEL
// ============================================================================
var label countdownLabel = na
if barstate.islast
label.delete(countdownLabel)
countdownLabel := label.new(
x=time_close + timeframe.in_seconds() * 1000,
xloc=xloc.bar_time,
y=labelY,
text=countdownText,
style=labelStyle,
color=color.new(color.black, 80),
textcolor=finalTextColor,
size=actualSize)
// ============================================================================
// END
// ============================================================================
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behaviour or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
DayTradeLab DOES NOT provide investment advice. The information contained within this websites, is provided for informational and educational purposes only. The information should not be construed as investment or trading advice, and is not meant to be a solicitation or recommendation to buy, sell, or hold any positions in any indices or financial markets mentioned.