OPEN-SOURCE SCRIPT
更新済

Sessions Extended

753
Sessions Extended

Based on the original "Sessions" indicator by LuxAlgo, this script is a complete
rewrite and substantial expansion. It is built for traders who want control
over session visualization, deep volume analytics, and a live dashboard that works
on any chart timeframe from 1 minute up to 1 week.

スナップショット

=============================================================================
WHAT CHANGED COMPARED TO THE ORIGINAL "SESSIONS" INDICATOR
=============================================================================

SESSIONS
Original: 4 fixed sessions (New York, London, Tokyo, Sydney)
Extended: 11 fully independent sessions labeled A through K, each with its own
complete settings group. The default setup covers the major forex windows:
Asia, London, New York, Sydney, Tokyo I, Hong Kong, Singapore I, Tokyo II,
Singapore II, EU pre-London, and US pre-NY.

PER-SESSION STYLING
Original: One shared background color and transparency, border always dotted,
no width control.
Extended: Per-session background color and transparency, fully independent of
the border color. Per-session border style (Dotted / Dashed / Solid) and border
width (1 to 4 pixels). Every session box can have a completely unique appearance.

SESSION LABELS
Original: One fixed label per session, always tiny, always at the session high.
Extended: Per-session label color and size (Tiny / Small / Normal / Large / Huge).
A numeric "Name Offset" input shifts the label upward by a chosen number of
blank lines, keeping label height constant regardless of zoom level. An optional
second label shows the actual session open and close times in HH:mm format with
its own independent offset, color, and size.

OVERLAYS PER SESSION
Each of the 11 sessions independently supports seven overlay types:

Range Box — High/Low box drawn for each session occurrence
Trendline — Linear regression line (best-fit straight line through closes)
Std Band — Dashed lines at +1σ and -1σ around the regression line.
Works independently — Trendline does not need to be active.
Bars outside the bands indicate unusual price movement.
Mean — Cumulative average of all closing prices within the session,
drawn as a connected line. Equal weight per bar, no volume
influence. See "Understanding Mean vs VWAP" below.
VWAP — Volume-Weighted Average Price. Institutional benchmark.
See "Understanding Mean vs VWAP" below.
Max/Min — Short horizontal tick marks at session High and Low
Midpoint — Horizontal line at the 50% level of the session High/Low range

スナップショット

EXTENDED HIGH/LOW LINES
Each session can project its previous High and Low as horizontal lines extending
to the right of the chart — classic support and resistance reference levels.
Fully configurable per session:
- Line color (independent from the session border color)
- Line style: Solid, Dashed, or Dotted
- Line width: 1 to 4 pixels
- Optional end-of-line label showing session name and date (dd.MM.yy)
- Label text color, background color, and background transparency

A global "Max Extended H/L Lines" setting (Range Settings group, default 10)
caps the total number of line pairs visible across all sessions combined.

DAYS BACK FILTER
Each session has a "Last N sessions" input. When set to 0 (default), all
available history is shown. When set to 1–50, only the N most recent occurrences
are drawn. The pruning applies consistently to boxes, labels, Max/Min lines,
Midpoint lines, Mean lines, VWAP plots, and Extended H/L lines.

TIMEZONE
A "Use Exchange Timezone" checkbox follows the exchange timezone automatically
(syminfo.timezone). When unchecked, a UTC Offset field (−12 to +14) enables
manual adjustment. This is particularly useful for handling Daylight Saving Time
transitions without needing to touch any session time strings.

=============================================================================
THE DASHBOARD — COMPLETE REFERENCE
=============================================================================

スナップショット

ENABLING AND POSITIONING
Find the Dashboard group in Settings. Toggle "Show Dashboard" to show or hide
the panel. Choose from four positions (Top Left, Top Right, Bottom Left,
Bottom Right) and four sizes (Tiny, Small, Normal, Large).

DASHBOARD MODES
The dashboard has three display modes, selected via the "Volume & Sigma columns"
and "Show Buy/Sell Volume" toggles:

Standard mode (both off):
Session | Trend

Advanced mode (Volume & Sigma on):
Session | Volume | Sigma | Trend

Advanced + Buy/Sell mode (both on):
Session | Volume | Sigma | ▲Buy ▼Sell | Trend

COLUMN DESCRIPTIONS

Session
The session name (e.g. ASIA, LONDON, NEW YORK). The cell background
changes color to reflect the session state:
Active background color — session currently open
Inactive background color — session closed today (snapshot visible)
Dimmed border color — session not yet started today or yesterday data

Volume
Total traded volume for the session's measurement window. Updates live
while the session is open. Freezes as a snapshot when it closes.
Calculated at 1-minute resolution via request.security — accurate on
any chart timeframe.

Sigma (σ)
Standard deviation of closing prices within the session. Measures how
much price spread around its average. A high Sigma indicates a volatile,
wide-ranging session. A low Sigma indicates tight, consolidating price
action. Updates live, freezes on session close.

▲Buy ▼Sell (optional, "Show Buy/Sell Volume")
Volume split by bar direction. Up-bars (Close ≥ Open) count as buy volume,
down-bars count as sell. Note: this is an approximation — Pine Script
cannot access TradingView's internal tick-level buy/sell data.

Open / High / Low (optional, "Show O/H/L + Change")
The session's opening price, highest traded price, and lowest traded price.
These are permanent historical facts and remain visible (dimmed) even after
the session closes and after the trading day resets.

Chg (optional, "Show O/H/L + Change")
The change from session Open to session Close: Close − Open.
Display format:
+1.234 green — session closed above its open (bullish)
-1.234 red — session closed below its open (bearish)
±0.000 grey — session closed exactly at its open (neutral)
The three colors (up, down, flat) are independently configurable.

Trend (r²)
The R-squared value of the linear regression for the session. Ranges from
−1.00 to +1.00. Positive values indicate an upward trend, negative values
a downward trend. Values near 0 indicate a sideways/choppy session.
The cell background is colored green (bullish) or red (bearish) based on
the sign, making trend direction scannable at a glance.

Timer (optional, "Show Timer column")
Countdown to the next relevant session event:
▼ HH:MM — session is currently open, counting down to close
▲ HH:MM — session is closed, counting up to next open
▲ Xd HH:MM — session opens in more than 24 hours (e.g. weekend gap)
The timer is updated in real time using timenow. It is visible at all
times, including when the market is closed. Weekend gaps are handled
correctly: sessions that open Monday morning show 2d+ on Friday evening,
while sessions still opening later on Friday show the same-day countdown.
The timer text is colored with the active session color when open, or
dimmed when the session is waiting to open.

DAY TOTAL ROW
When one or more sessions have "In Day Total" checked in their settings,
a Day Total row appears at the bottom of the dashboard. It shows:
- The sum of all Volume values from today's In-Day-Total sessions
- The average Sigma across those sessions

Critically, Day Total counts only sessions that have actually run since the
last anchor-session reset — not yesterday's data. If ASIA (the default anchor)
opened at 18:00 EST and New York has not yet run today, New York's data from
the previous day will appear in its row (dimmed) but will not be included in
Day Total.

YESTERDAY ROW
When all sessions have closed, a Yesterday row appears showing the prior
trading day's totals for comparison. This row disappears once the new
trading day begins.

STALE DATA — THREE BRIGHTNESS LEVELS
The dashboard uses text brightness to communicate data age at a glance:

Full brightness — session is currently active (live data)
Dimmed — session ran and closed today (today's snapshot)
More dimmed — session has data from the previous day (no run today yet)
Near-invisible — session has no data at all (never run or newly enabled)

The dim percentage is configurable ("Stale data text dim", 0–90%).

RESET LOGIC — HOW THE TRADING DAY IS DEFINED
The dashboard needs to know when a new trading day begins. This is controlled
by "Reset Stats when Session starts" in the Dashboard group (default: A = ASIA).

When the selected anchor session opens:
- All "ran today" tracking flags are cleared
- Day Total recalculates from zero
- Sessions not yet run show their previous data dimmed until they run again

Snapshot data inside each session's measurement function persists until the
session runs again and overwrites it. This means US pre-NY data from 08:30
yesterday is still visible in the dashboard at 04:00 today, correctly dimmed,
and correctly excluded from Day Total.

VOLUME MEASUREMENT WINDOW
Each session has a separate "Vol window" session input. By default this matches
the display session, but you can narrow it. For example, you could display the
full 18-hour ASIA box but only measure volume for the first two hours of
activity. The Vol window does not affect the displayed box or overlays —
it only affects Volume, Sigma, Buy/Sell, and Trend statistics.

DASHBOARD COLORS (configurable)
Active cell background — highlight color for currently open sessions
Inactive cell background — color for closed sessions with today's data
Text color — all non-highlighted cell text
Border color — table grid lines
Background — dashboard panel fill and transparency
Change Up / Down / Flat — three independent colors for the Chg column
Stale data dim % — how strongly to dim closed and yesterday data

=============================================================================
UNDERSTANDING MEAN vs VWAP
=============================================================================

Mean is the simple average of all closing prices within the session:
(Close₁ + Close₂ + ... + Closeₙ) / N
Every bar contributes equally regardless of how much was traded. Mean shows
the geometric center of price over time — a neutral, unweighted reference.

VWAP (Volume Weighted Average Price):
Σ(Close × Volume) / Σ(Volume)
Bars with high volume pull the VWAP toward them. Institutions use VWAP as
the primary benchmark for execution quality. A price above VWAP signals that
the session is running bullish on a volume-weighted basis; below is bearish.

The practical difference: when a sharp directional move occurs on thin volume,
Mean shifts significantly because it counts each bar equally. VWAP barely
reacts because little volume participated in the move. This divergence — Mean
far from VWAP — can itself be a signal that the move lacks conviction.

=============================================================================
DEFAULT SESSION CONFIGURATION (UTC-5 / New York EST)
=============================================================================

A ASIA 18:00 – 02:00 In Day Total, Anchor Reset (enabled)
B LONDON 02:00 – 08:00 In Day Total (enabled)
C NEW YORK 08:00 – 17:00 In Day Total (enabled)
D Sydney 18:00 – 00:00 (enabled)
E Tokyo I 19:00 – 21:30 (enabled)
F Hong Kong 20:30 – 03:00 (enabled)
G Singapore I 20:00 – 23:00 (enabled)
H Tokyo II 22:30 – 01:00 (enabled)
I Singapore II 06:00 – 10:00 (enabled)
J EU pre-Lon 02:00 – 03:00 (enabled)
K US pre-NY 08:00 – 09:30 (enabled)

All times are in UTC-5 (New York EST). Adjust the UTC Offset setting or enable
"Use Exchange Timezone" to match your local time.

Sessions H through K are disabled by default. Enable them in their respective
settings group. Note that newly enabled sessions will show no data until
they have run at least once after being activated.

=============================================================================
SETUP GUIDE — GETTING STARTED
=============================================================================

Step 1 — Timezone
Open Settings → Timezone. If your instrument uses the exchange timezone
natively, enable "Use Exchange Timezone". Otherwise set UTC Offset to your
local offset (e.g. -5 for New York EST, +1 for Berlin CET). If your region
uses DST and TradingView does not adjust automatically, update this offset
manually at DST transitions.

Step 2 — Sessions
Sessions A (ASIA), B (LONDON), and C (NEW YORK) are enabled by default with
commonly used forex hours. Adjust the session time strings to match your
instrument's actual active hours. Enable additional sessions (D through K) as
needed from their settings groups.

Step 3 — Dashboard
Open Settings → Dashboard. Enable "Show Dashboard". Choose your preferred
position and size. Enable "Volume & Sigma columns" for full statistics.
Enable "Show Timer column" to see live countdowns. Configure which sessions
should contribute to Day Total via the "In Day Total" checkbox in each
session's group.

Step 4 — Overlays
For each session you want to analyze deeply, enable the overlays relevant
to your strategy. Recommended starting set: Range Box (always on), VWAP for
institutional context, Mean for a price-weighted counterpart, Std Band for
volatility context.

Step 5 — Extended H/L Lines
Enable "Ext H/L" in any session group to project that session's previous
High and Low forward as S/R references. Set "Max Extended H/L Lines" in
Range Settings to a comfortable number (default: 10 pairs total).

Step 6 — Days Back
If your chart history is long and performance is slow, set "Last N sessions"
in each session group to limit how many occurrences are drawn (e.g. 5 to 20).

=============================================================================
ALERTS
=============================================================================

22 alert conditions are available — one "Session Start" and one "Session End"
for each of the 11 sessions. Alerts fire only when the corresponding session's
"Show" toggle is enabled. Set alerts via the Add Alert dialog in TradingView,
selecting this indicator from the condition dropdown.

=============================================================================
LIMITATIONS AND KNOWN BEHAVIOR
=============================================================================

Buy/Sell volume approximation
Up-bar (Close ≥ Open) = Buy volume. Down-bar = Sell volume. True tick-level
data is not accessible in Pine Script. Treat this column as directional
sentiment, not precise order flow.

Initial load time
11 request.security calls at 1-minute resolution cause a delay when first
applying the indicator to a chart with long history. This is a Pine Script
constraint — the 1m resolution is required for accuracy on higher timeframes.

request.security usage
This script uses 12 of Pine Script's 40 allowed request.security calls
(11 session functions + 1 anchor-reset detector), leaving 28 available
if you build on top of this script.

Short sessions on high timeframes
Sessions shorter than the chart's bar duration (e.g. a 30-minute session on
a 4H chart) may not be detected. Use a lower timeframe for short sessions.

Timer and market holidays
The countdown timer uses calendar arithmetic, not an exchange trading calendar.
On public holidays the timer will count down to the session time as if it
were a normal trading day. Weekend detection (Friday evening, Saturday) is
handled correctly for standard Mon–Fri market hours.

Dashboard layout
Table positions are limited to the four corners as defined by Pine Script's
table API. Sub-corner pixel positioning is not supported.

=============================================================================
CREDITS
=============================================================================

Original indicator: Sessions by LuxAlgo
Sessions [LuxAlgo]


This derivative is an independent rewrite published under CC BY-NC-SA 4.0.
creativecommons.org/licenses/by-nc-sa/4.0/
Commercial use is prohibited. Derivatives must carry the same license and
credit the original work.
リリースノート
Small changes for little Bugs.
リリースノート
Code simplification.
リリースノート
Memory issues solved
リリースノート
Bug Fix
リリースノート
Changed process of bar counting and limits
リリースノート
Another Bug Fix

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。