OPEN-SOURCE SCRIPT
Mis à jour

CQ_(-)_MTF Countdown Table

210
================================================================================
CQ_(-)_MTF COUNTDOWN TABLE — USER MANUAL
© CQuevedo345
================================================================================

Pine Script v6 | Overlay Indicator | Multi-Timeframe Candle Timer


────────────────────────────────────────────────────────────────────────────────
OVERVIEW
────────────────────────────────────────────────────────────────────────────────

The CQ MTF Countdown Table is a real-time, multi-timeframe candle progress
monitor that displays how far into — and how far from the close of — each
major candle period you currently are. It renders a compact table directly
on your chart showing elapsed time, remaining time, and progress percentages
for up to four timeframes simultaneously: 1H, 4H, 1D, and 1W.

The table updates live on every bar close and on the last bar using timenow,
so the countdown is always accurate to the second.


────────────────────────────────────────────────────────────────────────────────
FEATURE SUMMARY
────────────────────────────────────────────────────────────────────────────────

• Multi-Timeframe Coverage
Tracks candle progress across 1H, 4H, 1D, and 1W simultaneously.
Each timeframe can be independently shown or hidden.

• Elapsed Percentage Column
Shows what percentage of the current candle has already elapsed,
displayed as a whole number (e.g. 73%). The cell background uses a
color gradient that transitions from a user-defined "low" color at 0%
to a user-defined "high" color at 100%, giving an instant visual read
of candle age at a glance.

• Elapsed Time Columns (Days + Time)
For 1H, 4H, and 1D rows, the Days column is intentionally left blank
(those candles don't span multiple days) and the Time column shows
elapsed time formatted as MM m (1H) or HH h : MM m (4H, 1D).
For the 1W row, both the Days column (e.g. 03D) and the Time column
(e.g. 14h : 22m) are populated to reflect the full weekly structure.

• Remaining Time Columns (Days + Time)
Mirror of the elapsed columns, but counting down toward the candle
close. The 1W row shows remaining days and remaining intraday time
separately. The remaining columns have their own independent text-size
setting so they can be made larger or smaller than the rest of the
table without affecting other columns.

• Seconds Alert Column
When remaining time on any row drops below a user-configured threshold
(0–5 minutes), a dedicated RMNG SECS cell lights up showing the exact
remaining seconds (e.g. 47s). The cell and text color change to a
high-contrast alert style automatically. Above the threshold the cell
stays blank and dim.

• Bullish / Bearish TF Label Color
The leftmost cell of each row (the TF label: 1H, 4H, 1D, 1W) is
colored green or red depending on whether the current close is at or
above the candle's open (bullish) or below it (bearish). Colors are
fully customizable.

• Active Timeframe Marker
When the chart's current timeframe matches one of the table rows, that
row's label is prefixed with a ▶ arrow so you can instantly see which
row corresponds to the candle you are currently trading on.

• Gradient on Time Cells (Optional)
When the gradient toggle is enabled, elapsed time cells adopt the same
low→high gradient as the percentage column. Remaining time cells use
the inverse (high→low). When the gradient is enabled, the otherwise-
empty "Days" cells on 1H/4H/1D rows are also filled with the matching
gradient color, keeping the row visually cohesive instead of leaving
dead dark gaps. When the toggle is off, all time cells use a uniform
dim background.

• Orientation Toggle
The entire table can be switched between Horizontal (timeframes as
rows, columns as data fields — the default) and Vertical (timeframes
as columns, data fields as rows). All cell logic, merging, and
alignment adapts automatically.

• Position, Size, and Color Customization
Every visual aspect of the table is configurable: table position
(8 anchor points), global text size, remaining-column text size
(independent), title background, header background, text colors for
elapsed and remaining fields, gradient low/high colors, bullish and
bearish background colors, and seconds-alert text color.

• Week Anchor — Monday 00:00 UTC
The 1W candle is anchored to Monday midnight UTC regardless of the
broker or exchange session, matching TradingView's standard weekly
candle definition. The calculation uses timenow and UTC dayofweek to
derive the exact open timestamp of the current week dynamically.

• Accurate 4H and 1D Duration
Rather than assuming fixed 4-hour or 24-hour durations, the indicator
reads time_close from request.security for 4H and 1D so that DST
shifts, session gaps, and exchange-specific candle lengths are handled
correctly.


────────────────────────────────────────────────────────────────────────────────
TABLE LAYOUT
────────────────────────────────────────────────────────────────────────────────

Horizontal orientation (default):

┌─────────────────────────────────────────────────────────────────────┐
│ MTF ELAPSED/REMAINING CANDLE TIME │
├────────┬───────────┬────────────┬────────────┬───────────┬──────────┤
│ TF │ ELPSD % │ ELPSD DAYS │ ELPSD TIME │ RMNG DAYS │ RMNG TIME│ RMNG SECS
├────────┼───────────┼────────────┼────────────┼───────────┼──────────┤
│ 1H │ 73% │ │ 43m │ │ 17m │
│▶ 4H │ 18% │ │ 00h : 43m │ │ 03h : 17m│
│ 1D │ 62% │ │ 14h : 52m │ │ 09h : 07m│
│ 1W │ 44% │ 03D │ 14h : 22m │ 04D │ 09h : 37m│
└────────┴───────────┴────────────┴────────────┴───────────┴──────────┘

Column index reference:
Col 0 — TF label (bull/bear colored)
Col 1 — Elapsed percentage (gradient colored)
Col 2 — Elapsed days (1W only; gradient-filled on other rows if gradient ON)
Col 3 — Elapsed time (formatted per TF)
Col 4 — Remaining days (1W only; gradient-filled on other rows if gradient ON)
Col 5 — Remaining time (formatted per TF)
Col 6 — Remaining seconds alert (appears only near candle close)

In Vertical orientation the rows and columns are transposed: each
timeframe becomes a column and each data field becomes a row.


────────────────────────────────────────────────────────────────────────────────
INPUT SETTINGS REFERENCE
────────────────────────────────────────────────────────────────────────────────

── Timeframes ──

Show 1H Toggle the 1-hour row on or off.
Show 4H Toggle the 4-hour row on or off.
Show 1D Toggle the daily row on or off.
Show 1W Toggle the weekly row on or off.


── Display ──

Show Elapsed Time Shows/hides the Elapsed Days and Elapsed Time
(Col 2) columns (cols 2–3). When hidden both cells are
rendered as blank dim cells.

Show Remaining Time Shows/hides the Remaining Days and Remaining
(Col 3) Time columns (cols 4–5). When hidden both cells
are rendered as blank dim cells.

Seconds Alert Sets the threshold in whole minutes (0–5) below
Threshold (min) which the RMNG SECS column activates. At 0 the
seconds column never appears. At 5 it lights up
during the final 5 minutes of every candle.

Table Orientation Horizontal (default) — timeframes as rows.
Vertical — timeframes as columns.

Table Position Anchor point for the table on the chart.
Options: top-left, top-center, top-right,
middle-left, middle-right, bottom-left,
bottom-center, bottom-right.

Text Size Size of text in the title row and all data
cells except the remaining-time columns.
Options: tiny, small, normal, large.

Remaining Time Independent text size for cols 4, 5, and 6
Columns Text Size (remaining days, remaining time, seconds alert).
Options: tiny, small, normal, large.
Useful for making the countdown more prominent
without enlarging the rest of the table.


── Colors ──

Bullish Background Cell background for the TF label when
close >= open on that timeframe.

Bearish Background Cell background for the TF label when
close < open on that timeframe.

Elapsed % Low (0%) The gradient start color shown when a candle
has just opened (0% elapsed).

Elapsed % High (100%) The gradient end color shown when a candle is
nearly complete (100% elapsed).

Title Background Background of the merged title row.

Header Background Background of the column header row.

Text Color Default text color used across most cells.

Text Color (Elapsed) Color of elapsed header labels and elapsed cell
text values.

Text Color (Remaining) Color of remaining header labels and remaining
cell text values.

Seconds Alert Text Text color inside the RMNG SECS cell when the
alert threshold is active.

Use Gradient on OFF (default): elapsed and remaining time cells
Elapsed/Remaining use a uniform dim background regardless of
Time Cells candle progress.
ON: elapsed time cells use the same low→high
gradient as the % column. Remaining time cells
use the inverse high→low gradient. Additionally,
the empty "Days" cells on 1H, 4H, and 1D rows
are filled with the matching gradient color
(elapsed gradient for col 2, remaining gradient
for col 4) instead of staying as dark gaps.


────────────────────────────────────────────────────────────────────────────────
TIME FORMATTING REFERENCE
────────────────────────────────────────────────────────────────────────────────

1H elapsed / remaining → MM m (e.g. 43m, 17m)
4H elapsed / remaining → HH h : MM m (e.g. 00h : 43m)
1D elapsed / remaining → HH h : MM m (e.g. 14h : 52m)
1W days column → DD D (e.g. 03D, 04D)
1W time column → HH h : MM m (e.g. 14h : 22m)
Seconds alert → SS s (e.g. 47s)

All values are floored to whole minutes or seconds; no rounding up occurs
so the display never shows a value higher than the actual remaining time.


────────────────────────────────────────────────────────────────────────────────
NOTES AND TIPS
────────────────────────────────────────────────────────────────────────────────

• The table renders only on the last bar (barstate.islast). It does not
paint on historical bars and adds no visual noise to your chart history.

• timenow is used for all live calculations, so the indicator reflects
real wall-clock time even when the chart is not actively ticking (e.g.
outside regular session hours on session-limited instruments).

• The 1H row uses a simplified lookahead=off request to avoid peeking at
future hour opens. The 4H, 1D, and 1W rows use lookahead=on so that
time_close values are correctly available on the current bar.

• For instruments with irregular sessions (futures, crypto, forex) the
1D duration is derived from the actual time_close returned by the
exchange feed, so DST and session-length variations are handled
automatically.

• If all four timeframe rows are hidden the table will still render its
title and header row. Toggle at least one timeframe on for meaningful
output.

• Setting both "Show Elapsed Time" and "Show Remaining Time" to OFF will
leave only the TF label, percentage, and seconds alert columns visible,
producing a compact minimal layout useful for small screen areas.


────────────────────────────────────────────────────────────────────────────────
VERSION HISTORY
────────────────────────────────────────────────────────────────────────────────

v1.0 Initial release. 1H/4H/1D/1W timers, gradient %, bull/bear colors,
orientation toggle, seconds alert, elapsed/remaining columns.

v1.1 Added independent text size control for remaining-time columns
(cols 4, 5, 6). Gradient fill extended to empty "Days" cells on
1H/4H/1D rows when the gradient toggle is enabled, eliminating
dark gaps and keeping row backgrounds visually consistent.


────────────────────────────────────────────────────────────────────────────────
© CQuevedo345 — Mozilla Public License 2.0
================================================================================
Notes de version
Added an option to show Elaspsed time only, Remaining time Only or Both.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.