Skip to content

Commit bc866e5

Browse files
committed
H-MEASURE: measure the margin retentions against the kernel and TradingView
AUDIT4 X14 rows G2-09 (M7), G2-10 (M8), G2-12 (M10), G2-13 (M11) and the E20 f1 probe-tail pin. tests/test_adapter_margin_schedule_differential.cpp runs the same bars and orders through the Pine adapter and through a bare kernel host whose margin hooks answer TradingView's money and slice (the twin's), so only the kernel's own scheduling, check kinds and opening gate differ; every section prints both sides and pins the measured difference: - M7: the kernel's AfterApplied point after a leveraged opening or a mid-bar add, and its BarOpen point on a carried commissioned POOC short, are points margin_check_allowed refuses. - M8: a gap-open breach is a market execution at the open, sized on the open's money; no kernel check kind books that row. - M10: the pre-open slice's own x4 parts from the kernel's AfterApplied point (and from ab9714b) on the one-contract band, the +1e-6 restore floor and the frozen signal-time units. - M11: AdmitWithHostMargin and initial_margin_fraction part both ways. - E20 f1 (ruled 2026-09-22): the probe-suppressed tail books the kernel's path liquidation and the adapter's post-script margin call. M7 is also measured against TradingView: four lab tv tapes (tests/fixtures/margin_entry_bar, BINANCE:ETHUSDT.P 15m, rangeProof covered) book the margin call of a leveraged opening ON ITS ENTRY BAR at that bar's low, as the kernel's AfterApplied point does; the adapter books it a bar late or not at all. That is a TradingView-visible divergence, pinned as recorded (not fixed here: the lane measures). Docs made true: ADR-0001 "Margin" (the pre-open slice does have a kernel point beside it) and its initial_margin_fraction row, native-engine.md's margin paragraph, pine-to-native.md and contributing-llm.md (M11), live-surface.md §3.2 (the tail's two routes; the dispatch_bar paragraph named helpers that no longer exist), design rows MG4 and MG15; two design anchors into native-engine.md re-anchored for the moved lines. No src/ or include/ change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit bafefba06cebfc6989313e91c4a97e1a815a7239) INT26 pick note: the ADR and design pages conflicted on citation digits only (int16_digit_merge: 5 blocks, no text refused). The resolution is PAR-MARGIN's 6574de6d, the same pick onto the same tree (83d1ca7): its two design citations of native-engine.md carried through the exact line map (2941-3009 -> 2963-3031). hunkcheck: every hunk of bafefba0 carried; the two pages differ from its diff in anchor digits only.
1 parent 0d76a09 commit bc866e5

26 files changed

Lines changed: 1437 additions & 19 deletions

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,22 @@ kernel and own these quirks, each at its site:
248248
margin since F7), while the roll point measures at the remaining path's adverse mark (MG-FX:
249249
0.4116 @ 97 there against TradingView's 0.3996 @ 100). What has no kernel check point at all
250250
stays adapter-side: the `process_orders_on_close` chronology exception
251-
(`non_pooc_commissioned_short` `pine_adapter.cpp:16804`), the pre-open admission slice and
251+
(`non_pooc_commissioned_short` `pine_adapter.cpp:16804`) and
252252
the 1x-long money call — plus the TV admission scopes
253253
(`src/compat/pine/market_admission.cpp:33-46`) and the review fold they feed (`:67-72`,
254-
`:79-136`).
254+
`:79-136`). The pre-open admission slice stays too, though the kernel's `AfterApplied` point
255+
after the open fill measures the same bar. Measured by R5 lane H-MEASURE
256+
(`tests/test_adapter_margin_schedule_differential.cpp`: the same bars and orders through the
257+
adapter and through a bare host whose hooks answer TradingView's money and slice): the pre-open
258+
slice parts from the kernel's point, and from `ab9714be`, on the one-contract band, on the
259+
restore's `+1e-6` floor and on the frozen signal-time units; a gap-open breach executes at the
260+
open, sized on the open's money, where no kernel check kind does; the opening gate declines a
261+
1x long whose entry fee `AdmitWithHostMargin` admits, and admits a gap-up add the adapter
262+
refuses against its signal-time equity. The scheduling also misses one class the kernel
263+
reaches: a leveraged opening is never checked on its own entry bar. Four `lab tv` tapes
264+
(`tests/fixtures/margin_entry_bar`) book TradingView's margin call on that bar at its low, as
265+
the kernel's `AfterApplied` point does; the adapter books it a bar late or not at all — a
266+
recorded divergence, open.
255267
- **Calculation timing.** The cadence itself is the kernel's: a `calc_on_order_fills` strategy
256268
projects `NativeCalculationTrigger::BarCloseAndFills` with TradingView's guard literal as
257269
`max_recalculations_per_point`. What stays are the specifics COOF adds on top —
@@ -566,7 +578,7 @@ Every line number in this section names its symbol on this tree, which
566578
| `risk` | **native-only** | all of `strategy.risk.*` but the direction: `update_risk_state` (`pine_adapter.cpp:13867`), `SourceDayLedger`, `submit_intraday_loss_close` (`pine_adapter.cpp:14922`), `chart_day_key` (`pine_adapter.cpp:13764`), `compat::pine::IntradayCap` with `IntradayOrderBudget` (337 lines) | Structural first: Pine's risk calls are per-bar statements, so a limit reaches the adapter on script bar 0, after `project()` (`pine_strategy_host.cpp:324`) and `configure_native` (`pine_strategy_host.cpp:325`) have fixed and digested the spec. In substance (lane N12, `tests/test_adapter_risk_relower.cpp`, 62 checks over nine paired scenarios): the drawdown latch samples at the close only and still admits a reversal; the loss-day streak counts trades, not days; the intraday loss closes at the path's adverse extreme, refuses every placement and withdraws the book; the fill cap charges slots, transfers quota and closes at the bar's better extreme on the chart timezone's day. With the kernel seeded on the corpus, 3 of 4 cap probes diverge (3840 of 3916, 312 of 604, 2370 of 2384 rows). `strategy.risk.allow_entry_in` is the one rule that is the kernel's already (`allowed_open_directions`). Design §3.6 | `examples/native/native_risk_limits_strategy.cpp`, `examples/native/native_trail_risk_strategy.cpp`, `tests/test_native_risk_limits.cpp`, `tests/test_native_c_api.c` |
567579
| `max_abs_units` | **adapter-policy** | `strategy.risk.max_position_size` as a gate on the LIVE book before the fill (`max_position_size` `pine_adapter.cpp:13226-13227`): an entry is refused once the book already holds the limit | design row MG2 (R5-1): the resulting-book cap is the generic one. Measured by N12's scenario `PS` in `tests/test_adapter_risk_relower.cpp`: two-unit entries against a limit of 3 leave the adapter at 4 and the kernel cap at 2 | `tests/test_native_resting_matching_contract.cpp`, `tests/test_native_run_spec.cpp` |
568580
| `max_open_lots` | **adapter-policy** | Pine pyramiding is a per-cycle entry count in the adapter's command policy; a resting source entry must not consume a physical-lot cap before it fills, so `project()` leaves the cap unset (`max_open_lots` `pine_adapter.cpp:2360-2362`) | design row MG3 (R5-1); the contract comment in `project()` | `tests/test_native_resting_matching_contract.cpp`, `tests/test_native_margin_model.cpp` |
569-
| `initial_margin_fraction` | **adapter-policy** | TradingView's ten-significant-digit money admission against the signal-time tuple, answered as `AdmitWithHostMargin`; the `margin` model the adapter does declare is maintenance-only (`NativeMarginModel` `pine_adapter.cpp:2387-2395`, `margin.maintenance_long` `pine_adapter.cpp:2402`) | design row MG4 and the wave-4 ruling recorded in `project()`: a positive initial requirement would decline openings TradingView takes | `tests/test_native_precommit_view.cpp`, `tests/test_native_margin_model.cpp` |
581+
| `initial_margin_fraction` | **adapter-policy** | TradingView's ten-significant-digit money admission against the signal-time tuple, answered as `AdmitWithHostMargin`; the `margin` model the adapter does declare is maintenance-only (`NativeMarginModel` `pine_adapter.cpp:2387-2395`, `margin.maintenance_long` `pine_adapter.cpp:2402`) | design row MG4 and the wave-4 ruling recorded in `project()`: a positive initial requirement would decline openings TradingView takes. Measured both ways by R5 lane H-MEASURE (`tests/test_adapter_margin_schedule_differential.cpp`, M11): the kernel's gate declines a 1x long whose entry fee the adapter admits (`InitialMargin`), and admits a gap-up add the adapter refuses against its signal-time equity; `ab9714be` books the adapter's answer both times | `tests/test_native_precommit_view.cpp`, `tests/test_native_margin_model.cpp` |
570582
| `report_open_position_at_end` | **adapter-policy** | TradingView's range-end report re-marks the curve's last point and re-folds every extreme from it (`scheduler_record_range_end`): report shape, not a mark-to-market row (`sha256:71a6a8622f560fca3a27d37e098ea8b6f68f831abcca0b6c46ad004d3ffe9358` pine_adapter.cpp:2334-2341) | design row RP5; the kernel reads the field under `KernelRecorded` only, which `scripts/check_adapter_spec_shadowing.py` gates | `examples/native/native_sized_report_strategy.cpp`, `tests/test_native_report_truth.cpp` |
571583
| `open_bar_view` | **adapter-policy** | `Complete`: TradingView's bar-open scheduling and its `calc_on_order_fills` callback read the whole script bar (`pine_adapter.cpp:2325-2327`) | design rows CT4 and E5: the open-only view is opt-in because the adapter needs the full bar | `examples/native/native_calc_on_fills_strategy.cpp`, `tests/test_native_calc_timing.cpp` |
572584
| `subscriptions` | **adapter-hook** | `declare_timeframe_subscriptions` from the begin-time hook (`pine_strategy_host.cpp:1583`): a plain `request.security` site is a kernel subscription | lane R3b over the L6c hook: 21 of the corpus's 23 `request.security` probes run their sites on the kernel, byte-identical; the sites the predicate leaves out (lower timeframe, lookahead, auxiliary, streams) keep the source evaluator | `examples/native/native_htf_strategy.cpp`, `tests/test_native_htf_subscriptions.cpp` |

0 commit comments

Comments
 (0)