Skip to content

Trading Sessions, Exchanges and Time Zones

A daily bar has one honest interpretation. It covers a trading day, the day is named on the axis, and if the name is right nothing else about the timestamp matters much. An intraday bar has none of that protection. It carries a time, that time was assigned by somebody, and the analysis you build on top of it is only as sound as your knowledge of who assigned it and according to which convention.

That is the whole subject of this part. It is short, and it is the part of the real-time track that most often decides whether the rest of your intraday work means anything.

Three clocks are in play whenever an intraday bar reaches your screen, and no two of them are obliged to agree.

Where a bar's timestamp comes from

  1. The exchangeRuns a session in its own local time, changes its clocks on its own dates, and publishes its own calendar of holidays and short sessionsyou do not control this
  2. The data providerDecides whether a bar is stamped at the start or the end of its interval, and which time zone the stamp is expressed indocumented, sometimes
  3. The plugin and the databaseAmiBroker applies a time shift, filters sessions, and compresses bars into daily bars using a boundary you choseyou configure this
  4. Your computerHas a time zone and a daylight saving rule of its own, which Now() reports and the bar array knows nothing aboutyou configure this
  5. Your formulaCompares TimeNum() with a number you typed, and cannot tell you that the comparison stopped meaning what you intended

Nothing in that stack raises an error when two layers disagree. A wrong time zone produces bars. A wrong stamping convention produces bars. An hour of drift after a clock change produces bars. Charts draw, scans run, backtests report figures, alerts fire. The output is fluent and wrong, which is a far worse failure than a crash, because you keep using it.

Four pages, in a deliberate order.

The first lesson establishes the vocabulary and gives you a diagnostic: how AmiBroker timestamps a bar, what “start of interval” and “end of interval” actually mean for the same block of trading, and an exploration that tells you which convention your own database is using rather than which one you assume it uses.

The second lesson deals with sessions: the regular session, the extended sessions around it, sessions that begin on the previous calendar day, short trading days, and market holidays. It shows how to restrict a calculation to a session in AFL, and measures what happens to a daily bar when the extended sessions are included in it.

The third lesson takes on daylight saving. Two clock changes a year, on dates that differ between countries, applied by exchanges and by your operating system independently. AmiBroker’s time shift is a constant number of hours; the offset between two markets is not constant. The lesson shows what a one-hour displacement does to a session-anchored calculation, how to detect one in your own history, and how to write time handling that survives it.

The fourth page is a challenge. A working opening-range setup stops producing signals. You get the symptoms, the evidence, the broken formula and staged hints, and you find the root cause before reading it. The same fault is then traced through VWAP, alerts, intraday backtests and daily bar construction, because it never breaks only one thing.

An intraday database of some sort is genuinely necessary; Part 19 covers building one. Everything else is a text editor and a willingness to check rather than assume.

Timing bugs are not hard to fix. They are hard to notice, because the wrong answer looks exactly like the right one until you compare it against something external. Every formula in this part therefore prints the assumption it is relying on: which session start it found, how many bars carried the stamp it needed, how far the newest bar is behind the clock on the wall.

That habit generalises well beyond time zones, and it is worth taking from here into everything else you build.

Part20 of 36Level5 — Real-Time AmiBroker UserPages4Estimated time2.1 hours

4 of 4 pages in this part need the Professional edition or a live data feed, marked below. Every one of them has a Level A path that uses Bar Replay and historical data instead, so the part can be completed in full without a subscription.

0 / 4 lessons in this part completed