CurrentSecond
CurrentSecond returns the second of the clock at execution time, 0 to 59, identical on every bar of the chart. Use Second to read the second of each bar's close.
Syntax
CurrentSecondHow it works
CurrentSecond reads the clock at the moment the code runs and returns the second within the current minute, from 0 to 59. The reference is the time zone of the instrument's market, which may differ from the local machine. The constant takes no parameters and no bracket offset.
The value belongs to the Current family of date and time constants, which describe the moment of execution rather than any bar on the chart. Every bar of a calculation therefore sees the same number: an indicator refreshed at 14:20:30 returns 30 on every historical bar. The per-bar sibling is Second, which returns the second of the close of each bar being processed and changes along the time axis. Sub-minute timing on historical data belongs with Second; CurrentSecond describes the wall clock now.
In a live ProOrder system CurrentSecond is meaningful, since the code executes in real time as bars arrive. In a backtest it reflects the second the test runs, which makes it unsuitable for historical entry or exit conditions.
Examples
Example 1, Half-minute flag (Indicator)
// Set the flag when the script executes at 30 seconds past the minute
mySecond = CurrentSecond
IF mySecond = 30 THEN
onHalfMinute = 1
ELSE
onHalfMinute = 0
ENDIF
RETURN onHalfMinuteThe indicator plots 1 across the whole chart when recalculated exactly at second 30 of the current minute, and 0 otherwise.
Example 2, Scan on early seconds (ProScreener)
// Return matches only in the first ten seconds of the minute
earlySecond = CurrentSecond < 10
SCREENER[earlySecond AND close > Average[20](close)] (close AS "Close")The screener returns an empty list once the clock passes second 10, a way to spread scheduled scans across a narrow window.
Example 3, Second-gated check (ProOrder)
// Only evaluate entries during the last seconds of a minute
DEFPARAM CumulateOrders = false
lateSecond = CurrentSecond >= 55
IF lateSecond AND close CROSSES OVER Average[20](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIFLive, the system only checks the signal in the final seconds of each minute. Backtests cannot exercise this branch meaningfully, because CurrentSecond holds the second of the test run on every bar.
Common errors and gotchas
- Same value on every bar. CurrentSecond describes the clock, not the chart, so a condition such as
CurrentSecond = 30is true or false for the entire calculation at once. Per-bar timing logic needsSecond. - Backtest blind spot. In a backtest CurrentSecond returns the second the test executes, so filters built on it pass or block wholesale and produce results that do not match live behavior.
- Narrow match window. An exact test such as
CurrentSecond = 30only holds during a single second of clock time, so a recalculation is unlikely to land on it. Ranges such asCurrentSecond < 10are more dependable. - No bracket offset.
CurrentSecond[1]does not compile. Only per-bar constants such asSecond[N]accept an index.
Related instructions
Second, second of the close of each bar, the per-bar sibling of this constant.OpenSecond, second at the open of each bar.CurrentMinute, minute of the clock at execution time.CurrentHour, hour of the clock at execution time.CurrentTime, full clock time at execution as an HHMMSS integer.Minute, minute of the close of each bar.TIME, closing time of each bar as an HHMMSS integer.Timestamp, UNIX time of the close of each bar.
