@@ -361,44 +361,62 @@ static void test_resolve_exit_trail_fills() {
361361 CHECK (near (fl_tp.fill_price , 101.0 ));
362362}
363363
364- // ── explicit-zero-offset trails never retro-arm from the carried best ──
364+ // ── explicit-zero-offset trails arm from the carried best the command layer
365+ // hands them (the #148 retro-arm is closed at the source, not here) ──
365366//
366- // An EXPLICIT trail_offset=0 trail FILLS at its activation crossing, so in
367- // TV it can never be carried into a later bar already armed. When the exit is
368- // re-issued each bar with trail_points derived from close (level_t =
369- // entry ± prevBarClose*perc), a refreshed activation can drop UNDER a peak
370- // that was set beneath an older, higher level; deriving "armed" from that
371- // carried peak retro-armed a phantom stop that gap-filled at the next bar's
372- // open. An OMITTED trail_offset keeps the carried arming (see the omitted
373- // control below — TV fills those at the open off the carried peak).
367+ // #148 (a6e46ca): when the exit is re-issued each bar with trail_points
368+ // derived from close (level_t = entry ± prevBarClose*perc), a refreshed
369+ // activation can drop UNDER a peak that was set beneath an older, higher
370+ // level; deriving "armed" from that carried peak retro-armed a phantom stop
371+ // that gap-filled at the next bar's open. The resolver used to refuse the
372+ // carried best for an explicit 0 altogether. Since round 9 family Z the
373+ // COMMAND layer restarts the running extreme at the issuing bar's close on
374+ // every trail_points change (engine_strategy_commands.cpp), so the peak is
375+ // never carried; and round 10 family AC pinned (test_zero_offset_trail_rides)
376+ // that TV DOES arm the explicit-zero trail at the placement close and then
377+ // rides the raw running best — so the resolver now trusts the best it is
378+ // handed for every offset shape.
374379// Real discriminating bars from the boztilkiserhan-serhan1 WMA+RSI
375380// scalp tape (long entered 2025-04-09 00:15 @1478.84, trailPerc 1.5%,
376381// trail_offset passed as literal 0):
377382//
378383// 14:00 bar peaks at 1501.03 under that bar's level 1501.15
379384// (trail_points = 1486.70*1.5/0.01 = 2230.05 -> ceil 2231t) — no cross.
380385// 14:15 order refreshes from close 1475.99 -> 2213.985 -> ceil 2214t
381- // -> activation 1500.98 < carried peak 1501.03 .
386+ // -> activation 1500.98; the extreme restarts at that close 1475.99 .
382387// TV HOLDS through 16:30 (level from close 1489.89 -> 2235t -> 1501.19,
383- // crossed by high 1509.00, TV row px 1501.19). The engine used to
384- // retro-arm at the peak and exit at the 14:15 open 1475.99.
385- static void test_zero_offset_trail_never_retro_arms () {
386- std::printf (" test_zero_offset_trail_never_retro_arms\n " );
388+ // crossed by high 1509.00, TV row px 1501.19).
389+ static void test_zero_offset_trail_arms_from_the_carried_best () {
390+ std::printf (" test_zero_offset_trail_arms_from_the_carried_best\n " );
387391
388- // 14:15 bar: nothing crosses 1500.98 intrabar and the open is BELOW the
389- // activation — the position must HOLD (previously: gap-fill at open).
392+ // 14:15 bar with the best family Z actually carries (the issuing close
393+ // 1475.99 < activation 1500.98): dormant, the open is BELOW the
394+ // activation and nothing crosses it intrabar — HOLD, as TV does.
390395 Bar serhan_hold = mk (1475.99 , 1491.82 , 1475.89 , 1486.23 );
396+ ExitPathFill hold = resolve_exit_path_fill (
397+ serhan_hold, PositionSide::LONG , kNaN , kNaN ,
398+ /* trail_points=*/ 2213.985 , /* trail_price=*/ kNaN ,
399+ /* trail_offset=*/ 0.0 , /* entry=*/ 1478.84 ,
400+ /* best_start=*/ 1475.99 , false , false , kMintick );
401+ CHECK (hold.should_fill == false );
402+
403+ // The contract: a carried best past the activation ARMS the explicit-zero
404+ // trail (level = that best) and the open through it fills as a print —
405+ // exactly what an omitted offset does. Only the command layer's restart
406+ // keeps the #148 peak out of here.
391407 ExitPathFill retro = resolve_exit_path_fill (
392408 serhan_hold, PositionSide::LONG , kNaN , kNaN ,
393409 /* trail_points=*/ 2213.985 , /* trail_price=*/ kNaN ,
394410 /* trail_offset=*/ 0.0 , /* entry=*/ 1478.84 ,
395411 /* best_start=*/ 1501.03 , false , false , kMintick );
396- CHECK (retro.should_fill == false );
397-
398- // OMITTED offset control: the same bars with trail_offset = na keep the
399- // carried arming — the pre-armed level gap-fills at the open. This is
400- // the TV-pinned omitted-offset behavior (see the probe pin below); only
401- // the explicit literal 0 is the one-shot activation exit.
412+ CHECK (retro.should_fill == true );
413+ CHECK (near (retro.fill_price , 1475.99 ));
414+ CHECK (retro.at_bar_open == true );
415+ CHECK (retro.open_is_trail_level == false );
416+
417+ // OMITTED offset: the same bars with trail_offset = na keep the carried
418+ // arming — the pre-armed level gap-fills at the open. This is the
419+ // TV-pinned omitted-offset behavior (see the probe pin below).
402420 ExitPathFill retro_nan_off = resolve_exit_path_fill (
403421 serhan_hold, PositionSide::LONG , kNaN , kNaN ,
404422 /* trail_points=*/ 2213.985 , /* trail_price=*/ kNaN ,
@@ -433,19 +451,32 @@ static void test_zero_offset_trail_never_retro_arms() {
433451 CHECK (tvx.should_fill == true );
434452 CHECK (near (tvx.fill_price , 1501.19 ));
435453
436- // SHORT dual: refreshed activation 99.02 rises ABOVE the carried trough
437- // 99.00; the bar opens above it and never falls to it -> HOLD
438- // (previously: retro-armed and gap-filled at the open 100.50) .
454+ // SHORT dual: activation 99.02; the best family Z carries is the issuing
455+ // close 99.50 (above the activation: dormant), the bar opens above it and
456+ // never falls to it -> HOLD .
439457 Bar short_hold = mk (100.50 , 100.80 , 99.60 , 100.10 );
458+ ExitPathFill s_hold = resolve_exit_path_fill (
459+ short_hold, PositionSide::SHORT , kNaN , kNaN ,
460+ /* trail_points=*/ 98 , /* trail_price=*/ kNaN ,
461+ /* trail_offset=*/ 0.0 , /* entry=*/ 100 ,
462+ /* best_start=*/ 99.50 , false , false , kMintick );
463+ CHECK (s_hold.should_fill == false );
464+ // ... and a carried trough 99.00 past the activation arms it: the open
465+ // 100.50 gaps through the level 99.00 -> the open print (round 10 family
466+ // AC, f-gapdown-0404-1600-tp4 / 0423-1345-tp7b mirrored).
440467 ExitPathFill s_retro = resolve_exit_path_fill (
441468 short_hold, PositionSide::SHORT , kNaN , kNaN ,
442469 /* trail_points=*/ 98 , /* trail_price=*/ kNaN ,
443470 /* trail_offset=*/ 0.0 , /* entry=*/ 100 ,
444471 /* best_start=*/ 99.00 , false , false , kMintick );
445- CHECK (s_retro.should_fill == false );
446-
447- // Control: the "open gapped past the activation" TV rule is untouched —
448- // no pre-arming is needed for it. activation 101, open 102 -> open fill.
472+ CHECK (s_retro.should_fill == true );
473+ CHECK (near (s_retro.fill_price , 100.50 ));
474+ CHECK (s_retro.at_bar_open == true );
475+
476+ // Control: activation 101, carried best 101.03 (armed, level 101.03),
477+ // open 102 above it raises the best to 102; the low-first path's first
478+ // leg crosses that level at once -> a level fill at 102 (round 10 family
479+ // AC; the consumer floors it, 102 is on-tick).
449480 Bar gap_past = mk (102 , 103 , 101.2 , 102 );
450481 ExitPathFill gap = resolve_exit_path_fill (
451482 gap_past, PositionSide::LONG , kNaN , kNaN ,
@@ -605,7 +636,7 @@ int main() {
605636 test_exit_order_touch_gap_arms ();
606637 test_path_cross_kind_priority_order ();
607638 test_resolve_exit_trail_fills ();
608- test_zero_offset_trail_never_retro_arms ();
639+ test_zero_offset_trail_arms_from_the_carried_best ();
609640 test_fractional_trail_offset_truncates ();
610641 test_entry_bar_blocks_no_trail_exit ();
611642 std::printf (" \n %d passed, %d failed\n " , tests_passed, tests_failed);
0 commit comments