Second
Second returns the seconds past the minute, 0 to 59, for the current candlestick's timestamp in ProBuilder. Relevant only on second-based intraday charts.
Syntax
SecondThe keyword takes no parameters. A history index in square brackets reads earlier bars, so Second[1] gives the seconds component of the previous bar's timestamp.
How it works
Every bar carries a timestamp, and Second isolates its seconds field. The result is always an integer between 0 and 59. On a 15-second chart the values of consecutive bars cycle through 15, 30, 45, 0, while on any chart whose timeframe is one minute or coarser the value is 0 on every bar, because such bars always close exactly on a minute boundary.
The precision of the output therefore depends entirely on chart granularity. Scripts that rely on Second only behave meaningfully on second-based intraday charts, which is where timing down to the second matters, for example around scheduled news releases.
Second describes the bar timestamp, which corresponds to the bar close. The seconds component of the bar open is available through OpenSecond, and the seconds field of the wall clock through CurrentSecond. Combined with Hour and Minute, the keyword can rebuild a complete HHMMSS value from its parts.
Examples
Example 1, Reading the seconds field of each bar (Indicator)
// Store the seconds portion of the current bar's timestamp
mySecond = Second
RETURN mySecondThe indicator plots the seconds component bar by bar, which is a quick way to verify chart granularity or to debug time-based logic.
Example 2, Rebuilding a full HHMMSS value (Indicator)
// Rebuild an HHMMSS time value from its components
fullTime = Hour * 10000 + Minute * 100 + Second
RETURN fullTimeMultiplying each component into its decimal position reconstructs the same composite format used by TIME, useful when the parts are manipulated separately first.
Example 3, Acting only on minute boundaries (ProOrder)
// On a 15-second chart, act only on bars closing exactly on the minute
IF Second = 0 AND NOT OnMarket THEN
IF close > Average[20](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIF
ENDIF
SET STOP PLOSS 20On a second-based chart the condition Second = 0 selects one bar out of every minute, thinning the signal frequency without changing the chart timeframe.
Common errors and gotchas
- Always zero on minute charts and above. On 1-minute, hourly, or daily charts, Second returns 0 on every bar. A condition such as
Second = 30can then never be true, and the surrounding block becomes dead code. - Bar timestamp versus wall clock. Second reads the bar's timestamp, not the current time of day. For the live clock,
CurrentSecondis the correct keyword; the two only coincide at the moment a bar closes. - Close versus open. The bar timestamp corresponds to the close of the bar. The seconds field of the opening moment requires
OpenSecond, and the two differ by the bar duration on second-based charts.
Related instructions
CurrentSecond, seconds field of the current wall-clock time.OpenSecond, seconds component of the bar opening time.Minute, minutes component of the bar timestamp.Hour, hours component of the bar timestamp.TIME, full closing time of a bar in HHMMSS format.Timestamp, Unix timestamp of the bar close in seconds.
