Skip to content

Commit cfbe677

Browse files
luisleo526claude
andcommitted
Docs: the session flags end a session where TradingView ends it (R5 lane E26, item 3)
Row OT7 in native-feature-parity.md carried lane E25's open clause — "TradingView ends a session at the session day, which no path sees on a regular-hours or 24x7 feed". It is closed, with what TradingView actually does spelled out: the flag belongs to the last chart bar whose successor belongs to another session day, session.isfirstbar is its dual, and the ordinal is the exchange-timezone day that rolls at the symbol's day stamp. The measured result goes with it (255/255, 255/255, 370/370 against the three tapes, on the chart-timeframe and the aggregated path alike, from 1, 0 and 1), and so does the one residue left: a bar with no successor at all — a live tail or realtime bar — steps the calendar by one timeframe width and cannot see an early close the session string does not declare. The row's `scheduler_set_session_bar_state` anchor follows its line. Three other pages made claims this changes: - pine_v6_coverage_detail.md: the two flag rows said "per-bar lookahead in engine_run.cpp" and left the rule unsaid. They name the writer that exists (src/source/pine_strategy_host.cpp) and state the session-day rule. - pages/live-surface.md: §3.1 effect 2 said non-24x7 lanes need the v2 SessionCalendar for early closes and that session.islastbar/isfirstbar scripts stay blocked until then. That is now true only of the FORMING tail bar — a historical bar reads an early close from the session day itself, which the three NYSE:F half days in the tapes prove — so the caveat is narrowed to where it still holds instead of being dropped. - cheatsheet-runtime-and-execution.md: "session.islastbar is always false under the magnifier" was left stale by lane E25, and the entry said nothing about what the flag means. Both corrected. pages/pine-to-native.md is unchanged: its session rows describe the decision context and the risk-limit day ordinal, and neither claim moves. Verification: scripts/check_doc_anchors.py — 1566 anchors, 0 bad (the OT7 anchor was the single bad one before this commit); scripts/check_doc_lint.py — 0 offenders; ctest rows test_doc_anchors, test_doc_lint, test_native_feature_rulings and test_kernel_residuals pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 59428356c561fc270c78f02eded29b0496af1867)
1 parent b531a8d commit cfbe677

4 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎docs/cheatsheet-runtime-and-execution.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,12 @@ Audited gaps a forward/real-time executor must know (beyond per-order fills).
377377
- The **simple `run(bars,n)`** entry point does NOT set session predicates
378378
(`session.ismarket/isfirstbar/islastbar` stay false) — use the TF-aware
379379
overload if the script uses sessions.
380-
- `session.islastbar` is always `false` under the magnifier; in simple mode it's
381-
computed by **next-bar lookahead** — a live feed has no `i+1`, infer from the
382-
session string instead.
380+
- `session.islastbar` is the last bar of a session **day**: in-session, and its
381+
next chart bar is out of session or belongs to another session day
382+
(`session.isfirstbar` is the dual). It is read by **next-bar lookahead** on
383+
every path — chart timeframe, aggregated, magnified (R5 lanes E25/E26; it
384+
used to be permanently `false` under the magnifier) — and from the bucket
385+
calendar where there is no next bar to peek at (the live tail, a stream).
383386

384387
## 3.4 Timeframe aggregation (input_tf < script_tf)
385388

‎docs/design/native-feature-parity.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Columns: **Feature** (adapter mechanism, cited) · **Native today** (`yes` / `pa
175175
| OT4 | Cooperative abort | **yes** — `request_abort` engine.hpp:2271, `NativeAbortReporting` native_run_spec.hpp:41-44 | K | — | F:J4 | (single-source) |
176176
| OT5 | C-level run configuration, stream, FX curve, contract probe | **yes** — `strategy_configure_native_v1` c_abi.cpp:828, FX curve c_abi.cpp:828, probe c_abi.cpp:828, stream `strategy_stream_begin` c_abi.cpp:556 **Extended:** `pf_native_run_spec_ext_v1`'s policy tail now carries `intrabar`, `path_order`, `abort_reporting` and the slot-label / feed-tolerance policies (`PF_NATIVE_SPEC_EXT_INTRABAR`, `PF_NATIVE_SPEC_EXT_FEED_POLICY`), so nothing of `NativeRunSpec` but `identity` is unreachable from C (`tests/test_native_c_api.c`). | K | — | O:J4 | The v1 C spec `pf_native_run_spec_v1` pineforge.h:469 omitted `intrabar`, `path_order` and `abort_reporting`; they now travel in the extension's policy tail, `pf_native_abort_reporting_e` native_c_api.h:815 among them (F §2.iii) |
177177
| OT6 | C-level order submission + strategy callbacks | **no** — none of the 57 `PF_API` symbols; listed as a refusal native-engine.md:420 **Closed:** `strategy_native_host_create_v1` takes a C callback table and `strategy_native_submit_v1` / `_replace_v1` / `_cancel_v1` / `_cancel_all_v1` / `_cancel_where_v1` / `_execute_current_v1` command the same kernel under the same legality rule; the 32 symbols are a second, disjoint inventory beside the 57 codegen-facing ones (`tests/test_native_c_api.c`, `tests/test_native_c_api_frozen_header.cpp`). | K | L13 | F:J6 O:J5 | R5-7: post-v1. S covers it in its §2.3 without a row. |
178-
| OT7 | *(quirk)* Pine language state: series, barstate / session flags, position-view freezing (pine_language_state.hpp:12-68; pine_scheduler_native.cpp:223-258, pine_scheduler_native.cpp:512-624) | n/a | A | — | S:R1 | (single-source) **Closed (E25, lane E20's finding 2):** `session.islastbar` reads one script bar ahead on every driving path: the chart timeframe's next retained bar, an aggregated chart's next bucket (`next_aggregated_script_open` pine_scheduler_native.cpp:19), the calendar for the live tail's and a stream's realtime bar; since R4 slice C an aggregated or realtime bar read every in-session bar as last. The one writer of the three flags is `scheduler_set_session_bar_state` pine_strategy_host.cpp:1779 again (`tests/test_session_islastbar_aggregation.cpp`). Open: TradingView ends a session at the session day (`tests/fixtures/session_islastbar`), which no path sees on a regular-hours or 24x7 feed. |
178+
| OT7 | *(quirk)* Pine language state: series, barstate / session flags, position-view freezing (pine_language_state.hpp:12-68; pine_scheduler_native.cpp:223-258, pine_scheduler_native.cpp:512-624) | n/a | A | — | S:R1 | (single-source) **Closed (E25, lane E20's finding 2; E26, E25's findings 1 and 3):** `session.islastbar` reads one script bar ahead on every driving path: the chart timeframe's next retained bar, an aggregated chart's next bucket (`next_aggregated_script_open` pine_scheduler_native.cpp:19), the calendar for the live tail's bar and for every bar of a stream, warmup included — a stream continues past its replay, so only a batch run's final bar reads "last" from having no successor. Since R4 slice C an aggregated or realtime bar read every in-session bar as last. **What TradingView does:** it ends a session at the session DAY — the flag belongs to the last chart bar whose successor belongs to another session day, in session or not, and `session.isfirstbar` is its dual, the bar after a session's last one. The ordinal is `internal::session_trading_day_index` timeframe.hpp:145, the exchange-timezone day rolling at the symbol's day stamp (09:30 ET on NYSE RTH, midnight on 24x7, 17:00 ET on a 1700-1700 forex session), not local midnight; the unmerged form, since a fused holiday daily bar still holds two intraday sessions. The three `lab tv` tapes (`tests/fixtures/session_islastbar`) give that rule bar for bar with no disagreement, and the engine now holds 255/255 NYSE:F last bars, 255/255 first bars and 370/370 ETH last bars on the chart-timeframe AND the aggregated path (it held 1, 0 and 1 before). Early closes come with it: the three NYSE:F half days flag 12:45 ET without a holiday calendar, because the next bar is the next session day's. The one writer of the three flags is `scheduler_set_session_bar_state` pine_strategy_host.cpp:1820, which now takes both answers from the same lookahead (`tests/test_session_islastbar_aggregation.cpp`). Still open, and only for a bar with no successor at all: a live-tail or realtime bar steps the calendar by one timeframe width, so it cannot see an early close that the session string does not declare. |
179179
| OT8 | *(quirk)* Live-tail / probe-suppress harness flags (pine_strategy_host.cpp:270-272) | n/a — **contained since N14** (the flags were `BacktestEngine` members until then; now `source::PineStrategyHost` state behind two kernel virtual seams, §2.ii q) | A | N14 | F:J7 S:C5 | parity-campaign tooling |
180180

181181
---

‎docs/pages/live-surface.md‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ configuration**, not one-shot: it stays in effect until a caller passes
6363

6464
1. `barstate.islast` is false for that bar.
6565
2. `session.islastbar` is derived from the bucket calendar (no next bar to
66-
peek at, so it evaluates whether the next bucket — this bar's timestamp
67-
plus one script-TF step — falls out of session), pinned to agree with
68-
the `i+1` lookahead on every interior bar of the 24x7 lanes. Non-24x7
69-
lanes need the v2 `SessionCalendar` for early closes;
70-
`session.islastbar`/`isfirstbar` scripts stay blocked until then.
66+
peek at, so it asks whether the next bucket — this bar's timestamp plus
67+
one script-TF step — falls out of session, or belongs to another session
68+
day), pinned to agree with the `i+1` lookahead on every interior bar of
69+
the 24x7 lanes. Historical bars read early closes correctly from the
70+
session day alone, with no holiday calendar; a *forming* tail bar still
71+
cannot, because the calendar step it takes is one the session string
72+
declares as open. Non-24x7 tail bars therefore still need the v2
73+
`SessionCalendar` for early closes.
7174
3. `bar_index` stays put; `last_bar_index` is frozen at the horizon bar
7275
(`horizon_bars - 1`), when `horizon_bars > 0`. `last_bar_time` is exact
7376
when the horizon bar is in the script-bar array, one script-TF step per
@@ -97,10 +100,12 @@ at the session close — so the calendar lookahead answers "last" while
97100

98101
Read the tail bar's `session.islastbar` column: `1` is the calendar
99102
lookahead's answer, and the legacy expression could only have produced `0`.
100-
The one dispatch-path caveat that remains is not this flag's: a
101-
non-24x7 tape still needs the v2 `SessionCalendar` for early closes, so
102-
`session.islastbar`/`isfirstbar` scripts stay blocked until then, with or
103-
without the realtime tail.
103+
The one dispatch-path caveat that remains is not this flag's, and it is
104+
narrower than it was: every historical bar ends its session at the session
105+
day (R5 lane E26), so a non-24x7 tape's early closes are read from the tape
106+
itself. Only the forming tail bar is left — its calendar step cannot know a
107+
close the session string does not declare — so it still needs the v2
108+
`SessionCalendar`.
104109

105110
Default off (`on == 0`): every historical run stays byte-identical to
106111
before this flag existed.

‎docs/pine_v6_coverage_detail.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160

161161
| Identifier | Kind | Status | Backing | Notes |
162162
|---|---|---|---|---|
163-
| `session.isfirstbar` | var | ✅ Runtime | `session_isfirstbar_` on engine; per-bar lookahead in `engine_run.cpp`; on a 1D+ chart every bar (the bar is its whole session) | Sprint A |
163+
| `session.isfirstbar` | var | ✅ Runtime | `session_isfirstbar_` on engine, written by `scheduler_set_session_bar_state` (`src/source/pine_strategy_host.cpp`); the first bar of a session DAY — its predecessor was out of session or belonged to another session day; on a 1D+ chart every bar (the bar is its whole session) | Sprint A |
164164
| `session.isfirstbar_regular` | var | ✅ Runtime | Aliased to `session.isfirstbar` — engine has single session string, cannot distinguish RTH vs ETH (documented limitation) | Sprint A |
165-
| `session.islastbar` | var | ✅ Runtime | `session_islastbar_` on engine; per-bar lookahead; on a 1D+ chart every bar (the bar is its whole session) | Sprint A |
165+
| `session.islastbar` | var | ✅ Runtime | `session_islastbar_` on engine, same writer; the last bar of a session DAY — a one-bar lookahead whose successor is out of session or belongs to another session day, as TradingView's tapes flag it (`tests/fixtures/session_islastbar`); on a 1D+ chart every bar (the bar is its whole session) | Sprint A |
166166
| `session.islastbar_regular` | var | ✅ Runtime | Aliased to `session.islastbar` | Sprint A |
167167
| `session.ismarket` | var | ✅ Runtime | `pine_session_ismarket(session, tz, bar_ms, chart_tf)` in `session_time.hpp` (via `BacktestEngine::pine_session_ismarket`); always true on a 1D+ chart, as TradingView documents | Sprint A |
168168
| `session.ispostmarket` | var | ✅ Runtime | `pine_session_ispostmarket(...)` — standard ETH window `RTH_close-2000` local; always false on a 1D+ chart | Sprint A |

0 commit comments

Comments
 (0)