OpenSecond
OpenSecond returns the second at which the current bar opened, 0 to 59. Use Second for the second of the bar's close and CurrentSecond for the clock now.
Syntax
OpenSecondHow it works
OpenSecond returns the second within the minute at which the bar being processed opened, from 0 to 59. It reads the timestamp of the open of each bar, so it changes along the time axis as the calculation walks from bar to bar.
OpenSecond is the open-based member of the second trio. Its siblings are Second, which reads the second of each bar's close, and CurrentSecond, which reads the second of the clock at the moment the code executes and is identical on every bar. The value is meaningful mainly on second-based or tick-based charts, where bars can open at a non-zero second; on minute and higher timeframes bars usually open at second 0.
The constant takes no parameters and no bracket offset. It is a precision tool for intraday work where the exact opening second of a candle matters.
Examples
Example 1, Opening second readout (Indicator)
// Report the second at which the current bar opened
mySecond = OpenSecond
RETURN mySecondThe indicator plots the opening second of each bar. On a minute chart it stays flat at 0; on a seconds chart it steps through the opening seconds of successive candles.
Example 2, Scan for whole-minute opens (ProScreener)
// Match instruments whose latest bar opened exactly on a minute boundary
onMinute = OpenSecond = 0
SCREENER[onMinute AND close > Average[20](close)] (OpenSecond AS "OpenSec")The screener returns instruments whose most recent bar opened at second 0, with the open second shown alongside, useful for confirming clean minute alignment.
Example 3, Second-aligned entry (ProOrder)
// Only allow entries on bars that opened in the first half of a minute
DEFPARAM CumulateOrders = false
earlyOpen = OpenSecond < 30
IF earlyOpen AND close CROSSES OVER Average[20](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIFOn a seconds chart the strategy only takes signals on bars whose open falls in the first half of the minute, a fine-grained timing filter for high-frequency ideas.
Common errors and gotchas
- Open, not close. OpenSecond reads the second of the bar's open. For the close use
Second. The two differ by the bar duration. - Not the wall clock. OpenSecond is a per-bar value that changes along the chart. For the second of the moment the code runs, use
CurrentSecond. - Often zero on higher timeframes. On minute and larger bars the open usually lands on second 0, so
OpenSecond = 0rarely discriminates. It earns its keep on seconds or tick charts. - No bracket offset.
OpenSecond[1]does not compile. To reach an earlier bar's second useSecond[N].
Related instructions
Second, second of the close of each bar.CurrentSecond, second of the clock at execution time.OpenMinute, minute at the open of each bar.OpenHour, hour at the open of each bar.OpenTime, opening time of each bar 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.
