Candle Countdown Timer

TradingView Lab Tool

What is the Candle Countdown?

Displays a real-time countdown timer showing the time remaining until the current candle closes, with dynamic positioning based on candle direction.

  • Auto-adaptive: Supports all timeframes (1m, 5m, 1h, 1D, etc.).
  • Dynamic UI: Auto-positions to candle extremes or current price.
  • Visual Cues: Color-coded labels match your bullish or bearish candles.

πŸš€ Setup Instructions

1
Copy the Script: Click the "Copy Script" button below.
2
Open Pine Editor:  Pine Script Icon Access the tab at the bottom of your TradingView chart.
3
Install: Paste and click "Add to Chart."
Pro Tip: Use the Settings menu to toggle between anchoring to the price or candle extremes.
//@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
// ============================================================================
Common Issues:
β€’ Display Clipping: If the timer is cut off, ensure "Scale Price Chart Only" is checked in your chart settings.
β€’ Note on Timer Accuracy: As a TradingView indicator, this timer updates only when new market data is received. During low activity, it may appear to pause or "jump" to catch upβ€”this is expected platform behavior for Pine Script labels.
⚠️ Disclaimer: Trading involves the risk of financial loss. These scripts are provided for educational purposes and are not a recommendation to buy or sell securities. Always use stop losses and manage your risk.