Skip to content

Commit 2bbdd48

Browse files
luisleo526claude
andauthored
Floor an explicit close quantity to the quantity step (#839)
* Build an N-day chart on the year-restart N-day grid A strategy whose chart timeframe is N days (2D, 3D, 5D ...) built from daily bars ran on the days-since-1970 grid, and the chart's bar count, last_bar_index, barstate.islast and open-trade row came from the wrong bars. TradingView builds an N-day chart from N consecutive trading dates counted from the first trading date of each calendar year (the last bucket of a year is cut at its end), and its last_bar_index, barstate.islast and open-trade row follow that chart's own last bar. The engine already had that partition for request.security; this change installs it for the chart itself. The scheduler creates the existing partition source for an aggregated chart with a day count of two or more and hands it to the execution consumer, whose script bucket cursor, interval lookup, chart close and chart-time offsets read it. Only this chart path drops a leading bucket that opens before the input range and seals the final historical bucket. The calendar gains an interval overload that takes the partition's adjacent opens. The epoch-key paths, request.security, the D, W and M charts, intraday charts and runs whose input and chart timeframes are equal do not change, and a run without a partition adds nothing to the state hash. A day count whose seconds do not fit the legacy int conversion is calendar-only. Limits: a live stream keeps the previous chart path, and a selected window on a generated N-day chart partition is refused with the existing coded stop window_mode_unsupported (capability selected_window_chart_timeframe), because the window planner reconstructs the nominal calendar. Time offsets, exchange calendars and intraday input are not measured against TradingView. tests/test_n_day_chart_timeframe.cpp holds the rows on synthetic daily bars: the 3D grid, the last bar index, barstate.islast, the open row at the end, the 2D and 5D grids, the stream and refusal rows, the time offsets and the controls that must not move. It is registered through tests/cr150.d/n-day-chart-timeframe.cmake. scripts/check_native_cpp_versions.py lists the new reads of the retained input bars in the scheduler. TradingView tapes (sha256): 3D chart 1b2ef41a6f1ba4096e6659e12d5ef3f03c8bf2a51e4bb0d8331d814d9aade262, 2D chart ea679d91cbc0cd078c80604e2c73b3c9bb3104ff8d1989695da6abecb8b9e174, 5D chart 5342be10bdda8185b12b2c6a95b9b26101334cd1f58663ceb1f28c42197cb5dc, last_bar_index 05617c83d33cbd8be7a0d64356dc8f40e5b8d2ab20baa1b74b08b8aa66a07d25, barstate.islast 4ae8e0a932b7da6ffb4e0bcd5de9ee4d514cd6b78dbbb3fa4207aba1a2c6420d. Refs #811. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Re-anchor the line citations of the published pages (digits only) The N-day chart commit moved code in src/native_execution_consumer.cpp, src/native_execution_consumer.hpp, src/source/pine_strategy_host.cpp, src/source/pine_scheduler_native.cpp and src/timeframe.cpp, so the file:line citations of the published pages that point into them went stale, and scripts/check_doc_anchors.py reported 212 bad anchors. This commit changes digits only: the line numbers inside file:line citations of nine pages (145 changed lines, 233 changed numbers) and nothing else. No sentence, word, content pin or table is edited. The numbers were moved with the repository's own tools: scripts/check_doc_anchors.py --fix (the cited symbol sits on exactly one line) and scripts/reanchor_doc_citations.py --ref 360c4ab (a line map from the commit before the N-day chart change, where the pages were correct). The last six citations, which claim no symbol, were carried across the same line map by hand: the cited code line is the same text at its new number. scripts/check_doc_anchors.py reports no bad anchor on the result, and scripts/check_doc_reverts.py reports nothing, since a re-anchor is not an edit. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Floor an explicit close quantity to the quantity step strategy.close(id, qty = X) with an X that is not a multiple of the declared quantity step (qty_step, or mincontract when no qty_step is declared) placed no closing order: the quantity reached the native order layer unchanged, and that layer refuses explicit units that are off the grid. TradingView floors such a quantity to the step and closes that much; a quantity that floors to zero, or is larger than the position, closes the whole position. An explicit close quantity now goes through the same floor as an explicit entry quantity, including its handling of a quantity a hair under a step multiple, before the order is made. A quantity that floors to zero closes the whole exposure of the id when there is any. An explicit strategy.exit quantity is floored the same way before its units are reserved; one below a single step is ignored, so the exit covers the whole position (with the default qty_percent), as TradingView does. Runs that declare no quantity step are unchanged. The new test runs the adapter on synthetic bars with a step of 0.00001 and pins the quantities TradingView closed on BTCUSDT 1-hour bars: a half close of 0.03683 takes 0.01841 and leaves 0.01842, a close of 0.000004 or 0.123456 takes the whole position, a limit exit of 0.000004 or 0.123456 takes the whole position at its limit, and a limit exit of 0.018415, a short side and a reducing order floor the same way. One more row checks that a close quantity a hair under a step multiple (0.018409999999999) closes 0.0184, the same as an entry of that quantity opens, and leaves 0.01843. The lines added to src/source/pine_adapter.cpp move the lines the documentation cites below them; the anchors that follow them are re-pointed by the number of lines added (digits only, no sentence changes). Refs #716. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Re-anchor the line citations of the published pages (digits only) Merging main moved code in src/native_execution_consumer.cpp, src/source/pine_strategy_host.cpp, src/source/pine_scheduler_native.cpp and the other files the N-day chart change touches, so the file:line citations of the published pages that point into them went stale, and scripts/check_doc_anchors.py reported 208 bad anchors on the merge. This commit changes digits only: the line numbers inside file:line citations of nine pages (140 changed lines) and nothing else. No sentence, word, content pin or table is edited. The numbers were moved with the repository's own tools: scripts/check_doc_anchors.py --fix (the cited symbol sits on exactly one line) and scripts/reanchor_doc_citations.py --ref e163980 (a line map from main, where the pages are correct). The last six citations, which claim no symbol, were carried across by hand: the cited code line is the same text at its new number (one of them, the cursor constructor, gained a parameter on its line). Co-Authored-By: Claude Opus 5.5 <[email protected]> * Fail the run when a timezone lookup cannot be carried out The check that accepts a timezone name written in a script looks the name up in the timezone database with realpath, open and read, and it treated every failure of those calls as "no such zone". When the process had no file descriptor or memory left, or a read failed, a valid name such as America/New_York was refused with pine_timezone_error (class strategy, not retryable) and TradingView's text for an incorrect timezone; a database directory that could not be resolved refused every zone name the same way. The lookup now tells an absent name from a lookup that could not be carried out. ENOENT, ENOTDIR, ELOOP, ENAMETOOLONG and EISDIR still mean that the name denotes no zone file and keep pine_timezone_error. ENOMEM raises out_of_memory. Every other error raises engine_unclassified_error with the errno kept and the failed call named in the message. When the database directory itself cannot be resolved, a missing directory included, the run fails the same way and the message names the directory. In this check an interrupted call is tried up to three times, and a header read that returns fewer than four bytes is continued. Only the argument check of script timezones raises, through the internal timezone_lookup_accepted; the installed native_calendar::timezone_accepted keeps its false result, so its callers, the selected-run admission among them, refuse as before. A name that is also a complete POSIX definition, such as EST5EDT, stays accepted when its optional file lookup fails. A failed lookup is not remembered as an accepted name. tests/test_timezone_lookup_failure.cpp interposes realpath, open and read to fail each call of the lookup with each class of error, and checks the failure code, the errno and the call named in the message, that the name is looked up again afterwards and a clean run then books the same trades, that one interrupted call does not change the run, the file header (wrong magic, end of file, a read split in two), the database directory, the selected-run admission, and a TZDIR that is not a directory, where UTC offsets and POSIX definitions still run. Documentation sentences this change removes or rewrites: - docs/coverage.md, the pine_str_format_time row: "The message is TradingView's text with the engine's bar prefix, `Error on bar N: `, or `Error before the first bar: ` when no bar is being executed, and the arguments carry `bar_index`." It now begins "The error message for a refused name is", after a new sentence on the lookup failures. The allocation-bound manifest lists one new group, the message string of the lookup refusal in the native calendar (ceiling 1418 -> 1419, pinned count 1356 + 63 + 184), and its site inventory is re-emitted. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Test the void setter record under consecutive allocation failures A failed void C setter records its failure in the handle's run consumer. If a handle had no consumer, recording would first allocate one, and a failure of that allocation would leave only the status, without the code or the text. That state cannot be reached: the engine's only constructor binds the consumer, and the native host can be neither copied nor moved. These tests pin that, and show that the record survives a second allocation failure, without a change to the engine. - Every host type of the test starts with its consumer: storing a selected-window descriptor allocates nothing and does not return the allocation refusal -4. - When a setter's own string and then the rendering of the record's bar prefix are both refused, the setter's out_of_memory record is read without any allocation and its text falls back to "setter failed"; the next run start fails once with that record and publishes no report, and the start after it produces the report of a clean run. A setter refusal that carries its own code keeps that code when the rendering fails. - A sweep refuses two, and then three, consecutive allocations starting at every allocation index of a configured run (the setters, preparation, the bar callbacks and the report). Each injected run ends in a typed setup refusal before the first bar, in out_of_memory after it, or in a report byte-identical to the clean run, and the sweep prints how many refusals each run received: a pair at 256 indexes (Debug 258), a triple at 37 (Debug 39); the other 234 end at the first refusal. tests/fail_alloc_seam.hpp gains arm_span(first, count), which refuses count consecutive allocation attempts, and refusals(), the number of refusals delivered; arm(nth) is arm_span(nth, 1). Co-Authored-By: Claude Opus 5.5 <[email protected]> * Keep a sub-step exit quantity when qty_percent is below 100 The explicit strategy.exit quantity floor sent every quantity that floors to zero to percentage sizing. TradingView was measured only with the default qty_percent = 100, where a quantity below one step leaves the exit covering the whole position. With a qty_percent below 100 (not measured) the fallback sized the exit from the percentage instead of the script's quantity: on a one-lot position an explicit 0.5 with qty_percent 50 armed the whole lot, against the existing control in tests/test_integer_lot_percent_exit_min_step_l4b.cpp that keeps 0.5. Now a qty_percent of 100 or more, or none, takes the fallback; below 100 a sub-step quantity is kept as the script gives it, as before the floor. Quantities of one step or more still floor to the step. The changelog entry and the SZ11 row of docs/pages/pine-to-native.md now say the same. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 9f8309f commit 2bbdd48

9 files changed

Lines changed: 352 additions & 58 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ version number follows semantic versioning over the surfaces the
3232
being ignored or reset to AUTO. An invalid `mintick` is refused as `symbol_feeds_refused` with reason
3333
`syminfo_mintick_invalid`; an invalid point value uses the existing symbol metadata error, `symbol_metadata_rejected` with field `point_value`.
3434
- A percent-of-equity default quantity above 100 percent is now capped at 100 percent of equity when `margin_long` and `margin_short` are both 0 (#805).
35+
- `strategy.close(qty = ...)` now floors the quantity to the declared quantity step and closes that much, as TradingView does; a quantity that floors to zero or exceeds the entry id's position closes that whole position. Positive explicit `strategy.exit(qty = ...)` quantities now floor to the declared step; a quantity below one step is ignored unless `qty_percent` is below 100, so with the default `qty_percent = 100` the exit covers the whole position, as TradingView does; with `qty_percent` below 100 such a quantity is kept as given, as before. Measured against TradingView on one instrument and lot (a 0.00001 step, pyramiding 1, the default close rule, one entry id); not measured: `close_entries_rule = "ANY"`, pyramided entry ids, whole-unit steps, lots that are not a power of ten, and a sub-step `strategy.exit` quantity with `qty_percent` below 100 (#716).
3536
- With `process_orders_on_close` and the default FIFO close rule, the named `strategy.exit` calls of a reversing `strategy.entry` with an explicit quantity, placed in the same execution after a `strategy.close` of the old position, are now sized from the new entry's own quantity: a percentage exit takes its share of the new entry and an absolute-quantity exit keeps its quantity, instead of being sized from a basis reduced by the old position (#803).
3637
- Without `process_orders_on_close`, the named `strategy.exit` calls placed with a reversing `strategy.entry` of explicit quantity now take their percentage from the new entry when its size differs from the position it replaces, and a take-profit given as an absolute quantity now fires; before, the percentage was taken from the position being replaced and an absolute-quantity take-profit never fired (#803).
3738
- `strategy.risk.max_drawdown` is now tested at the order fills that close units, on the equity at that fill with open positions included, against the highest equity at such fills (the equity at an opening fill or at a bar close does not raise it), and a breach closes every open position at that fill's price (exit text "Close Position (Max Drawdown)"), cancels the pending orders and blocks later entries; before, it was measured once per bar close and only refused new entries (#804).

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ kernel and own these quirks, each at its site:
213213
- **Seams the adapter overrides.** The kernel is driven, not patched. `PineStrategyHost` overrides
214214
`resolve_execution_terms` (`pine_strategy_host.cpp:1184`) for TV sizing and fill spelling;
215215
`validate_execution_precommit` (`pine_strategy_host.cpp:1209`), whose
216-
`validate_precommit` (`pine_adapter.cpp:17083`) returns `AdmitWithHostMargin`
217-
(`pine_adapter.cpp:17318`) to own the opening margin decision; `on_native_tick`
216+
`validate_precommit` (`pine_adapter.cpp:17099`) returns `AdmitWithHostMargin`
217+
(`pine_adapter.cpp:17334`) to own the opening margin decision; `on_native_tick`
218218
(`pine_strategy_host.cpp:901`) / `on_native_applied` (`pine_strategy_host.cpp:973`) for
219219
`calc_on_order_fills` re-entry. It does not own lot excursions: since the adapter state consolidation it keeps
220220
the kernel's `owns_lot_excursions()` default, so the kernel's sampler books every Pine lot's
@@ -237,9 +237,9 @@ kernel and own these quirks, each at its site:
237237
(`select_exit_activation` src/compat/pine/exit_activation.cpp:44, `select_exit_suspension` src/compat/pine/exit_lifecycle.cpp:11, `select_replacement_revival_definition` src/compat/pine/exit_lifecycle.cpp:51) and historical birth reach
238238
(`order_birth.cpp` `src/compat/pine/order_birth.cpp:5-14`).
239239
- **Trail and tick conventions.** The half-tick arm threshold measured against tick-quantized
240-
extremes while the raw running best is retained (`has_trail_request` `pine_adapter.cpp:13108`); the half-tick
240+
extremes while the raw running best is retained (`has_trail_request` `pine_adapter.cpp:13124`); the half-tick
241241
trigger threshold (`source_trigger_threshold` pine_adapter.cpp:471) and raw-vs-booked fill spelling, behind the
242-
adapter's terms seam (`resolve_terms` `pine_adapter.cpp:15507`).
242+
adapter's terms seam (`resolve_terms` `pine_adapter.cpp:15523`).
243243
- **Money arithmetic.** Ten-significant-digit half-up money (`source_money_round`
244244
`pine_adapter.cpp:645-651`, twin `tv_money_round` `pine_policy_support.hpp:9-15`).
245245
- **Quantity dust.** After every applied execution the Pine host erases any lot of at most
@@ -260,8 +260,8 @@ kernel and own these quirks, each at its site:
260260
(`select_reservation_growth_sources` src/compat/pine/reservation_expansion.cpp:9).
261261
- **Margin.** The kernel owns the margin *mechanism* — the level solve, the check points, the
262262
kernel request, its re-pricing, the receipt — and the adapter answers its three policy hooks
263-
with TradingView's: `margin_check_allowed` (`pine_adapter.cpp:18540`) for the scheduling,
264-
`resolve_margin_requirement` (`pine_adapter.cpp:18609`) for the ten-significant-digit money,
263+
with TradingView's: `margin_check_allowed` (`pine_adapter.cpp:18556`) for the scheduling,
264+
`resolve_margin_requirement` (`pine_adapter.cpp:18625`) for the ten-significant-digit money,
265265
and `resolve_margin_call_units` for the lot-floored 4x restore. That hook answers every call
266266
on purpose (the margin and cancellation comparison): TradingView floors the restore onto the lot grid before the multiple,
267267
so on a gridded tape the kernel's own `ShortfallMultiple 4` books 5 lots where TradingView
@@ -272,7 +272,7 @@ kernel and own these quirks, each at its site:
272272
margin since F7), while the roll point measures at the remaining path's adverse mark (MG-FX:
273273
0.4116 @ 97 there against TradingView's 0.3996 @ 100). What has no kernel check point at all
274274
stays adapter-side: the `process_orders_on_close` chronology exception
275-
(`non_pooc_commissioned_short` `pine_adapter.cpp:24934`) and
275+
(`non_pooc_commissioned_short` `pine_adapter.cpp:24950`) and
276276
the 1x-long money call — plus the TV admission scopes
277277
(`explicit_pair_scope` `src/compat/pine/market_admission.cpp:34-47`) and the review fold they feed
278278
(`awaits_pair_review` `:68-73`, `fold_admission_history` `:83-140`).
@@ -719,8 +719,8 @@ Every line number in this section names its symbol on this tree, which
719719
| `NativeRunSpec` field | ruling | what the adapter runs instead | measurement and ruling of record | executed native consumers |
720720
|---|---|---|---|---|
721721
| `price_grid`, `grid_rounding` | **native-only** | TradingView's per-order-kind tick rules on top of `None`: `source_trigger_threshold` (`pine_adapter.cpp:471`), `source_level_on_price_grid` (`:454`), `nearest_tick` (`:361`) / `source_bar_fill_tick` (`:382`) / `directional_tick` (`:414`), behind the terms seam | R5-3 and design risk E7 ruled `None` for the adapter before the lane ran; lanes R7 and N13 measured the alternative anyway (raw levels submitted, `QuantizeFillsAndTriggers` with `HalfUp` declared). L8b closed the first blocker (no run aborts). The second has no remedy on either side: TradingView quantizes per order kind (stop and limit legs and a trail's activation on the quantized bar; the trail stop, the running best, stop-limit entries and the `calc_on_order_fills` cursors raw), the grid is one rule for the run, and the old N13 trial moved 30 pinned checks in 4 units; this is historical evidence, not a current-head result; a per-kind mask would spell that inconsistency into the kernel. The corpus cannot arbitrate (every probe runs a 0.01 tick on an on-grid feed; 5 of 312 differ in an engine-only column). Permanent witness: `tests/test_adapter_grid_relower.cpp`, whose section 5 pins the trail stop the grid fires a bar early. Design row PG and §3.6 | `examples/native/native_price_grid_strategy.cpp`, `examples/native/native_price_grid_c.c`, the private test `test_native_price_grid` |
722-
| `risk` | **native-only** | all of `strategy.risk.*` but the direction: `update_risk_state` (`pine_adapter.cpp:18197`), `SourceDayLedger`, `submit_intraday_loss_close` (`pine_adapter.cpp:21570`), `chart_day_key` (`pine_adapter.cpp:18094`), `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:678`) and the kernel's `configure` (`pine_strategy_host.cpp:694`) have fixed and digested the spec. In substance (the risk-lowering comparison, `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; re-derived by `scripts/check_seeded_risk_experiment.sh` since the kernel/adapter differential study). `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` |
723-
| `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:17203`): 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` |
722+
| `risk` | **native-only** | all of `strategy.risk.*` but the direction: `update_risk_state` (`pine_adapter.cpp:18213`), `SourceDayLedger`, `submit_intraday_loss_close` (`pine_adapter.cpp:21586`), `chart_day_key` (`pine_adapter.cpp:18110`), `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:678`) and the kernel's `configure` (`pine_strategy_host.cpp:694`) have fixed and digested the spec. In substance (the risk-lowering comparison, `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; re-derived by `scripts/check_seeded_risk_experiment.sh` since the kernel/adapter differential study). `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` |
723+
| `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:17219`): 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` |
724724
| `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 (the `max_open_lots` setting spelling is at `pine_adapter.cpp:2836`) | design row MG3 (R5-1); the contract comment in `project()`. Measured against TradingView by the kernel/adapter differential study (the private test `test_pyramiding_count_differential`, 15 scenarios on three `lab tv` tapes): TradingView checks an entry once, at its first eligible point, against the trades then open, and does not check a resting entry again at its fill; the kernel's cap books 14 of the 15 as TradingView does, the adapter's per-cycle count 13 (it keeps a slot a close or another entry's exit drained; since the resting-entry signal-state correction a resting LIMIT entry no longer counts, and one the count admitted fills over the cap, and since the residual-margin correction's SB the later market entries of a flat bar are refused at the fill once the book holds the cap, as on TradingView's tapes). A recorded divergence: the retention stands until a re-lowering decision. The adapter state consolidation tried the lowering and kept the count: on the kernel's cap four corpus probes moved away from TradingView, for want of the first-eligible-point rule (the kernel/adapter differential study's P4b); it fixed the reservation divergence measured beside it (P10), so a default `strategy.exit(from_entry)` under FIFO now reserves its entry's own quantity, the oldest lots first, as TradingView does | `tests/test_native_resting_matching_contract.cpp`, `tests/test_native_margin_model.cpp` |
725725
| `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:3075`, `margin.maintenance_long` `pine_adapter.cpp:3090`) | design row MG4 and the wave-4 ruling recorded in `project()`: a positive initial requirement would decline openings TradingView takes. Measured both ways by the kernel/adapter differential study (the private test `test_adapter_margin_schedule_differential`, 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` |
726726
| `report_open_position_at_end` | **adapter-policy** | The Pine host owns TradingView's range-end shape: batch re-marks the stored final point and re-folds extremes, while REALTIME retains ordinary marks and `PineStrategyHost::present_report` re-marks only the caller-owned copy before generic metric derivation; the stream hash excludes that terminal extreme fold (`scheduler_record_range_end` pine_strategy_host.cpp:2415): report shape, not a mark-to-market row (`KernelRecordedAtHostMarks` pine_adapter.cpp:3045) | 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` |

‎docs/design/arena-bound.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ indexPeak(k) = 24 * slots(k) # k > 32
344344
| Entry-rank AVL | (60+L)*J + 1[J>0] | `exit_rank_keys_` at `src/source/pine_adapter.cpp:6812-6813`; `Links` at `include/pineforge/detail/disk_id_table.hpp:165-182`, `end_` at `:349` |
345345
| Erased minima data | (40+L)*D + (40+2*L)*Q | `erased_minima_` at `include/pineforge/source/pine_adapter.hpp:961`; 40-byte header at `include/pineforge/detail/id_pair_store.hpp:69` |
346346
| Erased minima index | indexPeak(D+Q) | 16-byte slot at `include/pineforge/detail/id_pair_store.hpp:69`; replacement at `:642` |
347-
| Consumed partial-cycle data | (41+2*L)*Q | `include/pineforge/source/pine_adapter.hpp:2843`; joined key at `src/source/pine_adapter.cpp:25606` |
347+
| Consumed partial-cycle data | (41+2*L)*Q | `include/pineforge/source/pine_adapter.hpp:2843`; joined key at `src/source/pine_adapter.cpp:25622` |
348348
| Consumed partial-cycle index | indexPeak(Q) | `include/pineforge/detail/id_pair_store.hpp:642` |
349349
| Ordered consumed-cycle fold | 136*leaves + 2088*branches + 2096*savedPath | `include/pineforge/detail/id_pair_ordered_fold.hpp:161`, `:165`, `:172`, size assertion for `Leaf`, `Branch` and `Snapshot` at `:183` |
350350
| Successor-root rows | 16*R | `src/native_order.cpp:8220`, row assertion for `Row` at `:8281`, 64-row tail bound `kTailRows` at `:8286` |
@@ -381,7 +381,7 @@ root only when a newly issued definition has one. The 64-row RAM tail makes
381381
charging every issued row conservative. Partial closes create one trade
382382
row per affected lot: `src/engine_execution.cpp:1241`. Bracket definitions
383383
have limit, stop and trailing families; per-entry expansion is visible at
384-
`src/source/pine_adapter.cpp:14822`. A closed-trade count cannot bound
384+
`src/source/pine_adapter.cpp:14838`. A closed-trade count cannot bound
385385
unfilled placement history or the replacement-root history.
386386

387387
The ordered fold retains distinct-ever keys, including erased keys.

0 commit comments

Comments
 (0)