Repository navigation
Commit 14b05c9
Pine adapter: TradingView's exit-child order at one point and the callback lifecycle (trail tolerance, revived exits, tick-built limit reach) (#328)
* Pine adapter: same-point global exit children in TradingView's entry-id order, and the newborn stop
When one path point triggers the children of a strategy.exit that names no
entry, TradingView fills them one at a time in the order of its entry-id
table (a java.util.HashMap over the entry ids: String.hashCode spread over
16 buckets, 32 once the keys pass 13, the newest key first in a bucket; keys
are entry ids from their first fill plus one per waiting close order). Each
child is a transaction of its entry's quantity, settled against its own entry
under close_entries_rule ANY and against the oldest lots first otherwise, one
row per settled slice with its share of the ten-significant-digit fees.
The kernel fills such a leg once for the whole position. The host now re-cuts
that one fill's rows, while they are still the last rows and not final, into
the children's rows. Every shape the TradingView tapes do not reach keeps the
kernel's rows: a fill that is not the tail or leaves part of the position
open, a trailing leg, fewer than two ids, calc_on_order_fills,
process_orders_on_close or an intrabar feed, a non-unit account rate, a
cash-per-order or negative fee, a live leg of any other exit the price also
reaches, a table past 32 buckets or with a tie in a grown table, a waiting
strategy.order market order that would size the table differently, and a lot
quantity off ten significant digits. A re-cut that adds rows re-counts
strategy.wintrades / losstrades / eventrades and the gross sums; each kernel
member it writes has an ADR-0001 row.
A named stop whose limit entry fills at a point where the stop is already
through now fills at once at the entry's fill with the stop's slippage, not
at the level the bar crossed before the entry (no calc_on_order_fills, no
intrabar feed).
The entry-id table is hashed adapter state once it holds two ids or its peak
passes 13 keys, and is cleared per run. Nine source-layer witnesses are
re-pinned: seven hash-only, and two fuzz runs each move one trade by the
newborn-stop rule (quiet-bar Random28 with the magnifier off, publication
Config16).
tests/test_global_exit_children_tapes.cpp replays all 127 TradingView tapes
of the synthetic scripts: 93 asserted row for row, 34 recorded known
divergences with the rule each needs and the first departure, and six
unreached shapes pinned at the previous engine's own rows.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* Pine adapter: mintick trail tolerance, a killed exit revived on re-issue, and tick-built callback limit reach
Three TradingView rules, taped on synthetic scripts (4 identical exports
each), each behind its own switch in src/source/pine_n6_rules.hpp
(`PineN6Rule`, `set_pine_n6_rule` / `pine_n6_rule`, atomic flags, all on;
no public API, C ABI or strategy input, and no new durable state):
- trail_points become ceil(trail_points - 8e-3 * mintick) ticks: the
tolerance scales with mintick (ETH 0.01, XAUUSD 0.001, EURUSD 1e-5)
instead of the constant 5e-5 ticks, which stays as the no-mintick
fallback. Applied at every trail conversion site.
- A declined reversal kills the held position's stop and limit exits; a
later re-issue is a new live order. The replacement path already started
fresh legs for a changed re-issue; the unchanged-reissue shortcuts kept
the killed row. The revive applies to every side, sizing and stop or
limit exit, and only to the kill: a row held behind the entry/close pair
barrier keeps it. An exit issued once stays dead, as the declined-reversal
trail-leg tests pin. calc_on_order_fills keeps its own decline path.
- A limit exit born in a mid-leg calc_on_order_fills recalculation reaches
its leg's end only on that waypoint's tick-built print; the level stays
raw.
tests/fixtures/n6_callback_lifecycle commits all 82 tapes with their
generated strategies, plus five TradingView controls predicted before
export (the short mirror, a partial stop, fixed and cash sizing, and the
entry/close pair hold). test_n6_callback_lifecycle_tapes builds them into
one module, replays them row for row (66 equal, 21 known divergences with
their reason and first departure in known_divergences.json), clears each
switch in turn and requires exactly the departures rule_off_departures.json
records, and reads the pair-hold control's book to require that the stop
re-issued in the pair's calculation stays behind the barrier.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* Neutral names for the callback-lifecycle rule switches and tapes
A pure rename and comment rewording; no behaviour changes.
- The rule switches become PineCallbackLifecycleRule,
kPineCallbackLifecycleRuleCount, set_pine_callback_lifecycle_rule and
pine_callback_lifecycle_rule, with their storage callback_lifecycle_rules.
Their header moves to the private src/compat/pine/callback_lifecycle_rules.hpp,
so the compat unit that reads one no longer includes a src/source header; the
adapter includes it from there.
- The tape module, its generated include, entry-point prefixes, exported test
hooks, CMake variables, the ctest row and the fixture directory become
callback_lifecycle_tapes, callback_lifecycle_<tape>__,
callback_lifecycle_tapes_set_rule / _rule_count, _pf_clt_*,
test_callback_lifecycle_tapes and tests/fixtures/callback_lifecycle.
- Comments, fixture READMEs, generated fixture headers and the free-text
provenance fields name the TradingView tapes instead of internal campaign
labels. Every edited line keeps its place, so no documentation anchor moves.
The bytes TradingView ran (each tape's strategy.pine, its exports and the
metrics that pin their hashes) are unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>1 parent 54b3996 commit 14b05c9
1,073 files changed
Lines changed: 94207 additions & 661 deletions
File tree
- docs
- adr
- design
- pages
- include/pineforge
- compat/pine
- source
- src
- compat/pine
- source
- tests
- fixtures
- callback_lifecycle
- carried-static-stop
- carried-trail-13-895
- carried-trail-14
- coof-dual-short-first
- coof-dual-tagged
- coof-pp-high
- coof-pp-limit-mid
- coof-pp-limit-open
- coof-pp-low
- coof-pp-stop-high
- coof-pp-stop-mid
- declined-reissue-cash
- declined-reissue-fixed
- declined-reissue-short
- declined-reissue-stop
- dual-entry-carried
- dual-entry-coof
- dual-entry-inert-stop
- dual-entry-pyramid1
- dual-entry-reordered
- dual-entry-wrong-owner
- eur-trailpts-20p000001
- eur-trailpts-20p00003
- eur-trailpts-20p02
- eur-trailpts-20p0
- eur-trailpts-20p2
- long-high-ceil
- long-high-floor
- long-high-raw
- long-high-rounded
- long-limit-minus-quarter
- long-limit-plus-quarter
- newborn-limit-c0-p0
- newborn-limit-c0-p1
- newborn-limit-c1-p1
- newborn-limit-cancel
- newborn-limit-owner-absent
- newborn-limit-owner-other
- newborn-limit-raw
- newborn-limit-replace
- newborn-limit-rounded
- pair-hold-reissue
- range-breakout-july-fresh
- range-breakout-july-session
- range-breakout-may-22-points
- range-breakout-may-fresh
- range-breakout-may-pct2
- range-breakout-may-pct
- range-breakout-may-rev-sl
- range-breakout-may-rev
- range-breakout-may-shape
- range-breakout-trailpts-24p00001
- range-breakout-trailpts-24p000057
- range-breakout-trailpts-24p0001
- range-breakout-trailpts-24p001
- range-breakout-trailpts-24p4
- range-breakout-trailpts-24p6
- repeated-raw
- repeated-rounded
- rounding-sensor
- runner-cancel
- runner-frozen
- runner-history-literal
- runner-history-no-coof
- runner-history
- runner-live
- runner-no-coof
- runner-pooc
- runner-reordered
- runner-target-1160
- runner-target-1161
- runner-target-r1
- short-limit-minus-quarter
- short-limit-plus-quarter
- short-low-ceil
- short-low-floor
- short-low-raw
- short-low-rounded
- signed-coof
- signed-long-label
- signed-long-order
- signed-order-first
- signed-short-order
- signed-wrong-owner
- xau-trailpts-1000p000003
- xau-trailpts-1000p00003
- xau-trailpts-1000p0
- global_exit_children
- apex-third
- bars
- eth-fresh
- eth-member
- global-13
- global-14
- global-15
- global-16
- global-17
- global-18
- global-19
- global-20
- global-35
- global-36
- global-37
- global-38
- global-39
- global-40
- global-41
- global-42
- global-43
- global-44
- global-45
- global-46
- global-47
- global-48
- global-57
- global-58
- global-59
- global-60
- global-61
- global-62
- global-63
- global-64
- global-65
- global-66
- global-67
- global-68
- global-69
- global-70
- global-71
- global-72
- global-73
- global-74
- global-75
- global-76
- global-77
- global-78
- global-79
- global-80
- global-81
- global-82
- global-83
- global-84
- global-85
- global-86
- global-87
- global-88
- grown-bx-g
- grown-q-xa
- hist13-closeall
- hist13-same
- hist13
- hist4
- hist6
- hist7
- hist8
- live12-pend3
- live12
- live13-close1
- live13-close3
- live13
- live14
- live15
- live16
- live17
- named-ba
- named-xz
- named-zx
- pending-21
- pending-22
- pending-23
- pending-24
- pending-25
- pending-26
- pending-27
- pending-28
- pending-54
- pending-55
- pending-56
- pending-89
- reversal-29
- reversal-30
- reversal-31
- reversal-32
- reversal-33
- reversal-34
- reversal-51
- reversal-52
- reversal-53
- reversal-90
- reversal-95
- reversal-96
- shrink13
- siblings-01
- siblings-02
- siblings-03
- siblings-04
- siblings-05
- siblings-06
- siblings-07
- siblings-08
- siblings-09
- siblings-10
- siblings-11
- siblings-12
- siblings-49
- siblings-50
- siblings-91
- siblings-92
- siblings-93
- siblings-94
- terminal-part
- terminal-pct
- three-any
- three-fifo
- tie-aq
- tie-qa
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1496 | 1496 | | |
1497 | 1497 | | |
1498 | 1498 | | |
1499 | | - | |
| 1499 | + | |
1500 | 1500 | | |
1501 | 1501 | | |
1502 | 1502 | | |
| |||
3150 | 3150 | | |
3151 | 3151 | | |
3152 | 3152 | | |
3153 | | - | |
| 3153 | + | |
3154 | 3154 | | |
3155 | 3155 | | |
3156 | 3156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1136 | 1136 | | |
1137 | 1137 | | |
1138 | 1138 | | |
1139 | | - | |
| 1139 | + | |
1140 | 1140 | | |
1141 | 1141 | | |
1142 | 1142 | | |
| |||
0 commit comments