Skip to content

Commit a80c623

Browse files
luisleo526claude
andauthored
Pine adapter: recover the per-bar cost of the margin, sizing and admission rules (#336)
* Pine adapter: the retired-row sweep reads the placement rows in place On a gathered chart (a script timeframe above the input timeframe), pin K5 keeps every entry row of the run, so the sweep at each bar open (erase_retired_rows) walked a table that grows with the run, re-finding each row and binary-searching the askable origins before reading the row's own pin: the per-bar cost rose with every entry placed. The sweep now reads the rows straight off the table's storage, in the same incarnation order (PlacementTable::visit_rows), and tests a row's own pin before the searches. It keeps and erases exactly the rows it did. Alongside, each value-identical: decimal_grid_exponent forms its nineteen powers once, by the same expressions; gain_loss_regime and slipped_long_margin_scope read the configuration before the run; on_bar_open takes the point-order scan only under the point order; the narrow-scope margin and admission helpers stay out of line (two) or out of line and cold (six), and thirteen of their scope tests are hinted rare. The recovery is for gathered charts. With the script timeframe equal to the input timeframe the table stays small, the sweep is cheap anyway, and the cost the margin, sizing and admission rules added since 14b05c9 remains (native example batch median +5.7 %); the next commit takes it. No decision, order of operations, hashed field or floating-point value moves: against the admission change (#335) the witness harvests (every pinned state hash), a per-trade dump of all 21 Trade fields (%.17g, every run pass), the no-hash digests and the tape suites are byte-identical, and release ctest passes with the receipt rows. Doc citation digits re-anchored. Timing, measured on the admission change (#335) before its final rebase (same library): Xeon 8375C, CPU 2, 61 rotating blocks x 3 independent builds per tree x 5 runs, paired block bootstrap; every 95% interval within 0.21 points, * = it covers 0. percent vs native ta-sma bracket udt vcp batch median, gathered (1 m input, 3 m script) 14b05c9 +0.05* -0.05* -1.95 -0.38 -0.29 #335 (parent) -4.31 -2.56 -2.98 -3.63 -2.07 batch median, ungathered (1 m input, 1 m script) 14b05c9 +5.70 -0.33 +0.07* +4.19 +2.09 #335 (parent) -1.06 -3.01 -1.24 -1.00 -2.25 stream p95, gathered 14b05c9 +0.89 -0.18 -0.90 +2.77 +3.41 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Pine adapter: margin and admission scopes answer from the configuration; no sort or copy for a lone command The margin and admission scopes are asked several times a bar, and on a run outside them -- no power-of-ten lot step, a commission, pyramiding above one -- the configuration alone answers. Those conjuncts are now formed when the configuration is set (set_configuration and set_staged_configuration, the only writers of config_ and staged_), so such a bar answers each scope with one read instead of a call; inside a scope its own tests run as before, and the rule switches are still read at every ask. The unified admission at resolve_terms moves out of line unchanged, and the realized-money fold returns at once when nothing was booked since the last one. Alongside, on the same per-bar path: the same-bar command flush no longer stable-sorts a one-command queue (std::stable_sort still took a temporary buffer and moved the command, its whole placement snapshot included, through it and back) and keeps the queue's storage for the next bar; cancel_bracket_siblings and apply_fx_opening_margin_slice decide before copying the filled row; close_all records the close-first fact from the point and position it has already read; on_bar_open forms the opening print only under the point order; the retired-row sweep's visitors are inlined. No decision, order of operations, hashed field or floating-point value moves. Against the previous commit: the whole-suite dump (every closed and range-end trade with all 21 Trade fields at %.17g, every recorded per-bar, broker and stream state hash) is byte-identical on 659 of 663 process files (4 of them matched by content: their name hashes a temp-path argument), and the other 4 differ by run, not by tree (a timing-calibrated row, a stack-address row, two concurrent writers identical when run alone, twice in each tree); the 30 witness harvests (no re-pin) and 176 tape and witness executables are byte-identical; release ci_verify 859/859 with the receipt rows; corpus 312/312, moved 0. The seven new members are functions of the folded configuration and are waived as such. Doc citation digits re-anchored. Timing (Xeon 8375C, CPU 2; 4 independent builds per tree resampled as a random effect, blocks paired; percent against 14b05c9, 95% CI; largest build-to-build A/A 0.11 % / 0.27 % on the whole-batch median): whole-batch median stream mean per call stream p95 script timeframe = input timeframe (81 blocks) native example -1.5 [-1.5,-1.4] -2.8 [-2.8,-2.7] -2.1 [-2.2,-2.1] ta-sma-dual-cross -1.9 [-2.0,-1.9] -0.5 [-0.5,-0.4] +0.4 [+0.4,+0.5] bracket-aurora +0.2 [+0.1,+0.2] -0.7 [-0.8,-0.7] +1.0 [+1.0,+1.1] udt-regime-stack +0.4 [+0.4,+0.5] -0.8 [-0.9,-0.8] +0.4 [+0.3,+0.5] composite-vcp +2.6 [+2.5,+2.6] +1.6 [+1.5,+1.6] +2.2 [+2.1,+2.3] 1-minute input under a 3-minute script (41 blocks) native example -5.2 [-5.3,-5.0] -4.4 [-4.5,-4.3] -5.0 [-5.1,-4.9] ta-sma-dual-cross -2.2 [-2.3,-2.1] -1.2 [-1.3,-1.1] +0.2 [+0.1,+0.5] bracket-aurora -3.6 [-3.7,-3.5] -3.3 [-3.4,-3.2] -5.8 [-5.9,-5.7] udt-regime-stack -2.6 [-2.8,-2.5] -2.3 [-2.4,-2.2] -0.4 [-0.7,-0.1] composite-vcp † -0.4 [-0.5,-0.2] +0.4 [+0.3,+0.4] +2.0 [+2.0,+2.2] † Not a property of this commit: this row moves with the size of the process environment. setenv("TZ") (src/timezone.cpp) costs one heap trim and re-grow per run, about 85 us over 5,003 bars, and the row reads -0.3 to -0.6 with some environment sizes and +1.5 (+1.9 against the previous commit) with others. Whole-batch differences under 0.5 % read as at par. In the same runs the previous commit stood at +5.6, -0.3, +0.1, +4.2, +2.0 (script timeframe = input timeframe) and -0.2, -0.1, -2.0, -0.4, -0.1 (3-minute script) on the whole-batch median, and the admission change (#335) at +6.7, +2.9, +1.4, +5.2, +4.4 and +4.5, +2.6, +1.1, +3.4, +2.0. composite-vcp's remaining gap is the session clock in src/session_time.cpp (time() with a session argument every bar), which this commit does not touch. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Tests: run the lookup-index and live-state scaling rows serially in Release Under a parallel ctest the lookup-index scaling row once read 6.15 against its 5.0 bound, and 4.08 when run alone; the live-state scaling row failed the same way under load. RUN_SERIAL keeps other rows off the box while these two time their legs, in Release, where their ratios gate. A whole Release suite at -j 28 read 3.99-4.01 with it and 3.82-4.83 without, for about a minute more wall time. No source or behaviour change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 6b77f06 commit a80c623

7 files changed

Lines changed: 524 additions & 291 deletions

File tree

‎docs/adr/0001-kernel-adapter-boundary.md‎

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

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

Lines changed: 87 additions & 87 deletions
Large diffs are not rendered by default.

‎docs/native-refactor-progress.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ them for the record only. "Linux aarch64" is the maintainers' Cortex-A725 host.
173173

174174
| Item | What it is | Measured size | Deferred by | Prototype and evidence | Reopens when |
175175
| --- | --- | --- | --- | --- | --- |
176-
| D2-B, the quiet-bar protocol and one receipt read per bar | PERF-D2's lane: a per-bar bar-open request, a bulk fold of quiet driver points, the adapter's quiet-open predicate with lazy open bookkeeping, and a gate before the receipt poll. D2-A landed the hook declarations and the O(1) `has_command_after` (`src/native_execution_consumer.hpp:269`). PERF-L4 gated the read inside `observe_terminal_receipts` (`src/source/pine_adapter.cpp:6031`), which still runs about three times a bar | PERF-D2, Linux aarch64 (Cortex-A725), callgrind and GBench: about ×0.88 on the 14 probes (an estimate from a measured −13 to −14 % floor bound for the bar-open request alone); after PB the receipt poll still costs about 250 instructions a bar on the no-order floor. On this tree the quiet-bar probe asks the receipt gate 40,996 times and each once-per-bar-open gate 13,248 times: 3.09 reads a bar, 82 % of them stopped at the gate (macOS arm64, AppleClang 17, Release) | "R5 PERF-D2 DONE 2026-09-24 19:56" (D2-B after V19-D); "R5 SUPERVISOR RULING 2026-09-25 00:15 Taipei": "D2-B (quiet-bar protocol) waits for PERF-D3's verdict"; TRIAGE1 §D | An unpublished prototype branch and its patches. PERF-D3's S1 (next row) prototyped the request and the lazy opening | A post-release performance epoch. Done when the receipt gate is asked as often as the once-per-bar gates |
176+
| D2-B, the quiet-bar protocol and one receipt read per bar | PERF-D2's lane: a per-bar bar-open request, a bulk fold of quiet driver points, the adapter's quiet-open predicate with lazy open bookkeeping, and a gate before the receipt poll. D2-A landed the hook declarations and the O(1) `has_command_after` (`src/native_execution_consumer.hpp:269`). PERF-L4 gated the read inside `observe_terminal_receipts` (`src/source/pine_adapter.cpp:6105`), which still runs about three times a bar | PERF-D2, Linux aarch64 (Cortex-A725), callgrind and GBench: about ×0.88 on the 14 probes (an estimate from a measured −13 to −14 % floor bound for the bar-open request alone); after PB the receipt poll still costs about 250 instructions a bar on the no-order floor. On this tree the quiet-bar probe asks the receipt gate 40,996 times and each once-per-bar-open gate 13,248 times: 3.09 reads a bar, 82 % of them stopped at the gate (macOS arm64, AppleClang 17, Release) | "R5 PERF-D2 DONE 2026-09-24 19:56" (D2-B after V19-D); "R5 SUPERVISOR RULING 2026-09-25 00:15 Taipei": "D2-B (quiet-bar protocol) waits for PERF-D3's verdict"; TRIAGE1 §D | An unpublished prototype branch and its patches. PERF-D3's S1 (next row) prototyped the request and the lazy opening | A post-release performance epoch. Done when the receipt gate is asked as often as the once-per-bar gates |
177177
| S1a, kernel quiet-bar driving (PERF-D3) | A bar with nothing live, a flat book and a declined opening is driven in a quiet form: the kernel writes the bookkeeping its four price points would leave (ordinals, the last two driver marks, the floor, the point epochs) without walking them or calling the bar-open callback. Additive host cadence declarations; C hosts declare from their callback table; one C symbol under the PF_API checklist | PERF-D3, Linux aarch64 (Cortex-A725), GBench time and `perf stat` instructions, on the L3 tree `b33ea659`, S1a with S1b: no-order floor 0.764 / 0.660 in time (0.718 / 0.656 in instructions), 14 probes 0.958 / 0.921 (0.892 / 0.856), 100 slots 0.972 / 0.956 per slot. A bare kernel host that opts in: idle 0.545× (35 % fewer instructions a bar), market 0.81×, bracket 0.92×. Byte-identical: corpus 312/312, the 132-configuration battery with its hash columns | "FINDING PERF-D3 (filed for a post-release epoch per the owner's cap)" (ledger, 2026-09-24 16:58 UTC); "OWNER DECISION 2026-09-25 00:20 Taipei"; TRIAGE1 §D: "PERF-D3 S1/S2 (post-release epoch)" | An unpublished prototype branch (five commits on L3's tree) and its patches | The post-release epoch, with the owner calls PERF-D3 lists (the API under the existing ruling, the restated gate count) |
178178
| S1b, the Pine lazy opening | The Pine host records what its skipped opening and its uncalled input callback would have written, at the bar's first host callback. Member functions only, no layout change | Measured with S1a. A quiet bar then asks 15 gates, not 30, so the quiet-bar cost check `CHECK(asked >= 20 * o.boundary.size())` (`tests/test_adapter_quiet_bar.cpp:1054`) must be restated | As S1a | As S1a. The in-script hash witnesses caught the prototype's one miss (`awaiting_legacy_script_open_ms_`) | As S1a |
179179
| S1c, the held-position wake band | S1 for bars that hold a position with nothing live, 41 % of the median public slot's bars. The host declares a price band, and the kernel calls the opening only when the bar's range leaves it. The adapter derives the band from its margin model and declines when it cannot bound it | PERF-D3, a measurement-only upper bound without the band, which is not sound in general: 100 slots 0.776 / 0.716 per slot, 14 probes 0.830 / 0.761, cumulative against L3 with S1, S2 and D2-A | As S1a; the owner call "Fund the price band" | An unpublished measurement-only script | As S1a. Size L, parity risk high: TradingView's margin money rules |
@@ -183,7 +183,7 @@ them for the record only. "Linux aarch64" is the maintainers' Cortex-A725 host.
183183
| Compact journal records and a history ring buffer (L3) | Smaller command records and a ring buffer for the request core's history. `WorkingRequestCore::history` (`include/pineforge/native_order.hpp:1709`) hands out the whole vector and the core holds `history_` (`include/pineforge/native_order.hpp:2197`) inside `native_order_v7`, so both are a layout and API change | L3, Linux aarch64 (Cortex-A725), `perf` call graphs, inclusive shares: at most 3.68 % of bracket, 11.99 % of re-issue, 4.26 % of market and 3.42 % of the 14 probes (retiring the history alone: 1.64, 4.51, 2.53 and 1.00 %); only part is realisable, since records must still be written | "R5 L3 DONE + ACCEPTED 2026-09-24 22:10 Taipei", ruling 1: "DEFERRED to the PERF-D3 structural plan"; TRIAGE1 §D: "compact journal records" | Lane L3's code, merged by INT22 (#285); its profiles are unpublished | A `native_order` layout epoch |
184184
| A checked-values handoff for executions (L3) | `execution_values` runs twice, in `check_execution` (`src/native_order.cpp:4791`) and again in `apply_execution` (`src/native_order.cpp:4805`); handing the checked values across needs a public type, an API addition with no layout change | L3, as above: 2.21 % of bracket for the two together, about 1.1 % recoverable | L3 ruling 2: "a public checked-values handoff for executions (~1.1% bracket) -> DEFERRED" | As above | An owner decision on the API addition |
185185
| A chunked `trades_` store (L3) | Closed trades in chunks rather than one vector; `trades_` (`include/pineforge/engine.hpp:546`) is protected `BacktestEngine` state, so script ABI | L3, as above: on bracket, vector growth 0.64 %, `Trade` moves 0.74 % and `record_close_trade` 0.43 % (at most about 1.4 %); at most 0.35 % on the 14 probes | L3 ruling 4: "chunked trades_ store (ABI) -> DEFERRED" | As above | An `engine_script_run` epoch that changes the engine's protected layout |
186-
| A zoned chart-day memo (D2-D finding 4) | On a chart with a timezone, `libc_chart_day_key` (`src/source/pine_adapter.cpp:16314`) takes the process timezone lock through `ScopedTimezone` and calls `localtime_r` on every bar, because `on_bar_open` (`src/source/pine_adapter.cpp:20036`) reads `chart_day_key` (`src/source/pine_adapter.cpp:20257`) unconditionally. The non-UTC monthly Sharpe/Sortino walk, `month_key_local` (`src/engine_metrics.cpp:33`), pays one `localtime_r` per equity point. UTC charts use D2-D's memo, `civil_chart_day_key` (`src/source/pine_adapter.cpp:16298`) | Not measured on a zoned chart. The UTC path cost 134 instructions a bar before D2-D's memo and 68 after (D2-D, Linux aarch64, callgrind on the floor). PERF-K1: `ScopedTimezone` copies the zone name, which allocates for names of 16 or more characters under libstdc++ | TRIAGE1 §D: "D2-D finding 4 (the timezone `localtime_r` memo)", under the owner's cap. D2-D's report: an exact zoned memo "would need the zone's transition table, which belongs in `timezone.cpp`" | None; the UTC memo's witness is `tests/test_chart_day_memo.cpp` | A lane that owns `src/timezone.cpp` and builds an exact zone-transition memo (PERF-K1's Sitka case shows why a shortcut is not exact), byte-identical, with the zoned keys of `test_chart_day_memo` still equal to the computed ones |
186+
| A zoned chart-day memo (D2-D finding 4) | On a chart with a timezone, `libc_chart_day_key` (`src/source/pine_adapter.cpp:16377`) takes the process timezone lock through `ScopedTimezone` and calls `localtime_r` on every bar, because `on_bar_open` (`src/source/pine_adapter.cpp:20199`) reads `chart_day_key` (`src/source/pine_adapter.cpp:20420`) unconditionally. The non-UTC monthly Sharpe/Sortino walk, `month_key_local` (`src/engine_metrics.cpp:33`), pays one `localtime_r` per equity point. UTC charts use D2-D's memo, `civil_chart_day_key` (`src/source/pine_adapter.cpp:16361`) | Not measured on a zoned chart. The UTC path cost 134 instructions a bar before D2-D's memo and 68 after (D2-D, Linux aarch64, callgrind on the floor). PERF-K1: `ScopedTimezone` copies the zone name, which allocates for names of 16 or more characters under libstdc++ | TRIAGE1 §D: "D2-D finding 4 (the timezone `localtime_r` memo)", under the owner's cap. D2-D's report: an exact zoned memo "would need the zone's transition table, which belongs in `timezone.cpp`" | None; the UTC memo's witness is `tests/test_chart_day_memo.cpp` | A lane that owns `src/timezone.cpp` and builds an exact zone-transition memo (PERF-K1's Sitka case shows why a shortcut is not exact), byte-identical, with the zoned keys of `test_chart_day_memo` still equal to the computed ones |
187187
| Thread-local reads that remain per call | D2-C moved the three scopes' writes onto the pump's block, `pump_ambient` (`src/native_execution_consumer.hpp:444`). A reader still reaches the block through `tl_runtime_ambient` (`src/ta_extremes_volume.cpp:29`): `bar_context` (`src/ta_extremes_volume.cpp:82`), read by every `ExtremeRing::update` (`src/ta_extremes_volume.cpp:117`), which backs `ta.highest`, `ta.lowest`, `ta.highestbars` and `ta.lowestbars` and, through an embedded `Highest` and `Lowest`, `ta.stoch`, `ta.wpr` and `ta.range`; and `matching_day_partition` (`src/timeframe.cpp:605`), read by the default-anchored `ta.vwap` through `session_day_index`, by `crosses_boundary` on a DAY period (`timeframe.change("D")`) and by the session-period helpers. `decompose_ms_local` (`src/session_time.cpp:250`) reads two thread-locals per call on a zoned clock, and the prepared order storage's `free_blocks` (`src/native_order.cpp:605`) one per prepared mutation. `ema_na_warmup_flag` is read once per EMA, at its first compute | One thread-local access per reader call. AUDIT4, macOS arm64, a dlopen'd tutorial-MACD probe, counted by `_tlv_get_addr` breakpoints and by descriptor patching: 1.000 a bar for one `ta::Highest` and for one default `ta::VWAP`, 1.999 for one `pine_hour` on a New York clock, 0.000 on the no-order floor and with orders. On Linux a TLS-descriptor call costs about 20 instructions: D2-C's 13 → 4 calls a bar was 260 → 80 instructions (Linux aarch64, GCC 13, callgrind). INT23: 2.00 a bar on the zoned probe 064, 0.08 on probe 008 | None for the TA and day-partition readers: "RULING: INT23 ACCEPTED" (ledger, 2026-09-24 23:30 UTC) reads "dlopen TLS 13->0/bar", and INT23's report names only the timezone and order-core residuals. This row is their record | Unpublished (AUDIT4's scratch) | A byte-identical lane that hands these readers the pump's block without a thread-local read. `ta::bar_context()` is script ABI, so its public declaration stays as it is |
188188
| "audit-off mode", "LTO", "data-oriented layout" | Named in "OWNER DECISION 2026-09-25 00:20 Taipei" among the post-release structural items: "S1 bulk quiet bars, S2 per-strategy specialization, audit-off mode, LTO+PGO, data-oriented layout". No engine or campaign document defines, designs or measures the three | None | The owner decision | None | Struck from this inventory until a design note defines one of them |
189189

@@ -199,7 +199,7 @@ unless the retention is Full, and `presize_logs`
199199
(`src/native_execution_consumer.cpp:9460-9471`) sizes no journal under Window.
200200
`NativeRunSpec::event_retention` (`include/pineforge/native_run_spec.hpp:714`)
201201
defaults to Window, and the Pine adapter declares
202-
`NativeEventRetention::Window` (`src/source/pine_adapter.cpp:2705`). K4 still
202+
`NativeEventRetention::Window` (`src/source/pine_adapter.cpp:2760`). K4 still
203203
sizes Full runs (driver log and journal) and Commands runs (journal), and its
204204
witness, `tests/test_native_batch_log_presize.cpp`, runs under Full. PERF-K24's
205205
replay figure (14.9 % less CPU on Linux aarch64) describes the tree before V19-B. In
@@ -210,7 +210,7 @@ or more, and the same run under Full holds 66,000 points in one block of
210210
**PERF-L4 reads the receipts about three times a bar, not once.** PERF-L4's
211211
brief asked it to "read the receipts ONCE per bar instead of three times". The
212212
lane gated the read instead: `observe_terminal_receipts`
213-
(`src/source/pine_adapter.cpp:6031`) returns at its receipt gate when no
213+
(`src/source/pine_adapter.cpp:6105`) returns at its receipt gate when no
214214
command lies above its cursor. `every_gate_is_taken_both_ways`
215215
(`tests/test_adapter_quiet_bar.cpp:1061`) prints
216216
`gate ReceiptRead asked 40996 quiet 33552 live 7444`, against `asked 13248`
@@ -241,7 +241,7 @@ Mac's 489 and 412 and 1003 of 1249, and no Mac output moved.
241241

242242
- **PERF-L4's retired reader slots.** `event_high_water_reader_` and
243243
`terminal_receipt_high_water_reader_`
244-
(`include/pineforge/source/pine_adapter.hpp:2136-2137`), with their type
244+
(`include/pineforge/source/pine_adapter.hpp:2161-2162`), with their type
245245
`ReceiptHighWaterReader`, are storage nothing reads or writes since PERF-L4:
246246
they keep `PineExecutionAdapter`'s layout, which is part of
247247
`PineStrategyHost`'s and so of the generated script's ABI. They go at the next

‎include/pineforge/source/pine_adapter.hpp‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,24 @@ class PlacementTable {
576576
const auto next = next_after(incarnation);
577577
return const_iterator(this, next.first, next.second);
578578
}
579+
// Every row in incarnation order -- the order begin() walks: the older
580+
// rows, then the window's -- read straight off the storage rather than
581+
// re-found at every step. `visit(incarnation, row)` returns true to stop.
582+
// For a whole-table read: no row is inserted or erased while it runs.
583+
template<class Visit>
584+
[[gnu::always_inline]] void visit_rows(Visit&& visit) const {
585+
for (const auto& entry : old_) {
586+
if (visit(entry.first, static_cast<const PlacementSnapshot&>(*entry.second))) return;
587+
}
588+
for (std::size_t index = head_; index < window_.size(); ++index) {
589+
const auto& slot = window_[index];
590+
if (slot
591+
&& visit(base_ + static_cast<std::uint64_t>(index - head_),
592+
static_cast<const PlacementSnapshot&>(*slot))) {
593+
return;
594+
}
595+
}
596+
}
579597

580598
#if PINEFORGE_PLACEMENT_AUDIT
581599
iterator find(std::uint64_t incarnation, unsigned line = __builtin_LINE()) noexcept {
@@ -1884,23 +1902,30 @@ class PineExecutionAdapter {
18841902
bool submit_tv_money_long_margin_call(const Bar&, const NativeDecisionContext&,
18851903
int* fired_waypoint = nullptr);
18861904
void fold_source_money();
1905+
void fold_source_money_through(const PineStrategyHost& pine, std::uint64_t count);
18871906
bool gain_loss_regime() const;
1907+
bool gain_loss_run_regime() const;
18881908
double gain_loss_signal_equity(double mark) const;
18891909
double gain_loss_mirror_equity(double mark) const;
18901910
std::optional<double> pooc_fee_units(const PineSizingSnapshot&) const;
18911911
double tv_pooc_fee_grossed_unit(double price) const;
18921912
bool unified_admission_scope(const PlacementSnapshot&, bool market_or_stop,
18931913
double signed_units, double units) const;
1914+
bool unified_admission_terms(const PlacementSnapshot&, const NativeExecutionTermsFacts&,
1915+
bool market_or_stop, bool opposite,
1916+
native_order::ExecutionTerms& result, bool& admitted) const;
18941917
bool unified_fill_admits(const PlacementSnapshot&, double units, double quote) const;
18951918
void record_close_first(bool whole_position);
18961919
void credit_pyramiding_record(const SourceId& id, std::uint64_t incarnation, double units);
18971920
void book_pyramiding_records(const SourceId& id, std::uint64_t armed_for, double units);
18981921
std::optional<std::size_t> open_ledger_records() const;
1922+
std::optional<std::size_t> held_ledger_records() const;
18991923
std::uint64_t entry_incarnation_of(const SourceId& from_entry) const;
19001924
bool exit_tombstoned(const SourceId& exit_id, const SourceId& from_entry) const;
19011925
bool unified_placement_book_clear() const;
19021926
bool pinned_lot_grid() const;
19031927
bool slipped_long_margin_scope() const;
1928+
bool slipped_long_book_scope() const;
19041929
double slipped_long_margin_units(double quote) const;
19051930
bool slipped_long_unit_shortfall(double quote) const;
19061931
bool close_all_at_next_point(
@@ -2513,6 +2538,28 @@ class PineExecutionAdapter {
25132538
}
25142539
};
25152540
RetiredRowScratch retired_row_scratch_;
2541+
// The configuration's part of the margin and admission scopes, which the
2542+
// per-bar path asks several times a bar: each a conjunction of reads of
2543+
// config_ and staged_ alone, formed again whenever either is set
2544+
// (set_configuration, set_staged_configuration), the only way either
2545+
// changes. Not state: a function of config_ and staged_. A run outside a
2546+
// scope answers it here without the call; inside, the scope's own tests
2547+
// run as before.
2548+
struct StagedScopeFacts {
2549+
bool positive_grid = false; // a lot step above 0
2550+
bool unit_grid = false; // a lot step in (0, 1]
2551+
bool unit_point_money = false; // point value 1, no FX series
2552+
bool unit_money = false; // and an account FX rate of 1
2553+
bool mintick = false; // a finite positive mintick
2554+
};
2555+
StagedScopeFacts staged_scopes_{};
2556+
bool lot_grid_pinned_ = false; // pinned_lot_grid()
2557+
bool gain_loss_configured_ = false; // gain_loss_regime()'s configuration
2558+
bool slipped_long_configured_ = false; // slipped_long_margin_scope()'s
2559+
bool unified_configured_ = false; // unified_admission_scope()'s
2560+
bool ledger_records_configured_ = false; // the pyramiding records'
2561+
bool pooc_fee_configured_ = false; // pooc_fee_units()'s
2562+
void refresh_configuration_scopes(const PineStrategyConfig& config) noexcept;
25162563
// R5 lane W6: after a source evaluation, queue this bar's marketable
25172564
// flat entries in TradingView's order at their shared fill point.
25182565
void order_same_point_entries();

0 commit comments

Comments
 (0)