About
Forex trades around the clock, but not evenly: volume and ranges change with the centres that are open. This indicator tells a strategy, on every bar, whether Sydney, Tokyo, London and New York are open, whether London and New York overlap, and for one session you choose: whether the bar is in it, whether it is its first bar, the minutes since it opened, its high and low so far, and the high and low of the last finished session.
Every session is kept on its own city's clock: Sydney 07:00 to 16:00, Tokyo 09:00 to 18:00 (no daylight saving), London 08:00 to 17:00, New York 08:00 to 17:00. These are common conventions; the FX market has no official session hours. London and New York change their clocks on different Sundays, up to three weeks apart in March and one week apart in late October or early November, and in those weeks the overlap is an hour longer in UTC. Because the times are local, the indicator gets those weeks right, and the Monday Sydney session starts on Sunday evening in UTC, where the FX week opens.
Parameters
| Name | Type | Default | Range or options | Description |
|---|---|---|---|---|
session | choice | "london" | sydney, tokyo, london, new_york, custom | The session to follow; custom uses open, close and tz below. |
open | text | "08:00" | Custom session only: the opening time on the clock of tz, like 09:00. | |
close | text | "17:00" | Custom session only: the closing time; at or before open, the session runs past midnight. | |
tz | text | "Europe/London" | Custom session only. A time zone name (IANA), like Europe/Berlin or America/New_York. | |
weekdays | choice | "mon_fri" | mon_fri, every_day | The local days a session may open on: Monday to Friday, or every day for markets that trade at the weekend. Applies to the four FX flags too. |
Use it in a strategy
pythonses = ctx.plugin_indicator("trading_sessions", "sessions", {"session": "london"})
bars = ctx.bars(1)
if ses is not None and bars and ses.overlap and ses.prev_high is not None:
if bars[-1].close > ses.prev_high:
ctx.signal("LONG")
elif bars[-1].close < ses.prev_low:
ctx.signal("SHORT")The indicator library has this as sessions: ctx.ind("sessions", session="london") reads it in a strategy, and the chart, Blocks, Rust and the Rust core have it too, with the same four sessions on their own clocks. This template stays as an example of a plugin indicator; only it takes custom hours in any time zone.
What it provides
valueValue | 1.0 when the bar is in the followed session, else 0.0. |
in_sessionValue | True when the bar's start time is inside the followed session (open included, close excluded). |
session_openValue | True on the first bar of a new session (also on the first bar of the data when it starts inside a session; check minutes_since_open). |
minutes_since_openValue | Minutes from the session's open to the bar's start time; None outside the session. |
high, lowValue | The high and low of the running session so far, this bar included; None outside the session. |
prev_high, prev_lowValue | The high and low of the last finished session; None until one has finished. |
sydney, tokyo, london, new_yorkValue | True while that centre's session is open, on its own clock. |
overlapValue | True while London and New York are both open. |
Limits
- A bar counts by its start time. A bar that starts before the open but ends after it is not in the session, so pick a timeframe that lines up with the session times (H1 or finer for the four FX sessions).
- Holidays are not known: a session opens on every weekday that has bars. When the data starts in the middle of a session, its high and low count from the first bar.
- A plugin indicator is not drawn on the chart and is not available in Blocks, Pine, Rust or C#; it runs on the run's own instrument only.