Files
nt8-sdk/TASK_GAP054_RUNNER_TRAIL_PROMPT.md
mo 34c3767fbf [GOV]: cleanup prompted task state
- SPRINT_BOARD.md: stage GAP-025/GAP-030 and correct GAP-062 deploy status

- TASK_GAP025_RUNNER_ORDER_LIFECYCLE_LOGGING_PROMPT.md: add runner lifecycle logging prompt

- TASK_GAP030_ORB_HYDRATION_VERIFY_PROMPT.md: add ORB hydration verify prompt

- TASK_GAP051/052/059/060 prompts: record commit-only deploy instruction

- TASK_GAP054_RUNNER_TRAIL_PROMPT.md: clarify SIM/replay validation path

- docs/00-governance/2026-08-19-run-book.md: reconcile implemented/verified task states

- docs/00-governance/active_work.md: update blocker status and validation requirements

- docs/00-governance/decisions.md: record prompted follow-ups and resolved GAP-062 deploy status

Build: clean | Tests: 569 passing | Deploy: GAP-062 deployed backup 20260826_005308
2026-08-26 00:59:35 -04:00

149 lines
8.4 KiB
Markdown

# TASK: GAP-054 — Auto-breakeven destroys the runner's trailing stop
# Staged: 2026-08-18 (v7.0 review, Finding 6)
# ACCEPTED: 2026-08-19 — see DEC-20260818-18. Option 0 approved. Runner-scoping
# sub-question resolved to "unconditional skip, no new flag" (see decision entry).
# Sprint: Stage 2 — Runner. BLOCKS RUNNER-001.
# Owner: Kilocode (implementation)
# ─────────────────────────────────────────────────────────────────
## THE DEFECT
In NinjaScript, `SetStopLoss()` and `SetTrailStop()` are MUTUALLY EXCLUSIVE per
signal name — the later call replaces the earlier exit order for that signal.
At entry, `SubmitOrderToNT8()` (NT8StrategyBase.cs ~2178-2196) arms the runner
correctly:
SetStopLoss (_runnerSignalName, Ticks, intent.StopTicks, false)
SetTrailStop(_runnerSignalName, Ticks, RunnerTrailTicks, false) // wins
EnterLong/EnterShort(runnerQty, _runnerSignalName)
Then in `OnBarUpdate()` (~797-804):
if (EnableAutoBreakeven && !_breakevenMoved && profitTicks >= BreakevenTriggerTicks)
{
SetStopLoss(_runnerSignalName, CalculationMode.Price, bePrice, false);
_breakevenMoved = true;
}
That `SetStopLoss` call REPLACES the live trailing stop with a static stop at
entry + BreakevenOffsetTicks. The runner never trails again for that trade.
The comment four lines below correctly warns against re-calling SetTrailStop
here (it would reset the anchor to bar-close price — real defect, 2026-04-13).
That warning is still valid. The SetStopLoss call above it was not recognised
as doing worse.
## RUNTIME PROOF — all four broker-confirmed trades
| Trade | Session log line | Profit at BE | 12t trail would sit | Stop actually went |
|-------|-----------------------------------------------------------|--------------|---------------------|--------------------|
| 08-07 | BREAKEVEN runner stop -> 29826.00 profit=28ticks | +28t | +16t | +1t |
| 08-10 | BREAKEVEN runner stop -> 29848.50 profit=25ticks | +25t | +13t | +1t |
| 08-16 | BREAKEVEN runner stop -> 30200.08 profit=24ticks | +24t | +12t | +1t |
| 08-17 | BREAKEVEN runner stop -> 30271.00 profit=26ticks | +26t | +14t | +1t |
The breakeven action moves the stop BACKWARDS — it gives back 11-15 ticks of
already-locked profit and then freezes. Conservative floor estimate: the runner
would have banked 55 ticks (~$275 gross / ~$252 net) instead of $25 / $1.96.
## READ-FIRST — do not start coding until you have confirmed all of these
1. Read `NT8StrategyBase.cs` around lines 785-830 and 2170-2205 in full.
2. Confirm from NinjaTrader's own documentation that SetStopLoss and
SetTrailStop are mutually exclusive per signal name. Cite the doc page in
your writeback. If NinjaTrader documents different behaviour, STOP and
report — the whole task premise depends on this.
3. Confirm `_runnerActive`, `_breakevenMoved` and `_runnerSignalName` lifecycle:
where each is set, cleared, and read.
## THE CHANGE — Option 0 (APPROVED — DEC-20260818-18, 2026-08-19)
Stop applying auto-breakeven to the RUNNER leg. A trailing stop already provides
monotonically improving protection and does it better at every point.
- In the `OnBarUpdate` breakeven block, do NOT call `SetStopLoss()` on
`_runnerSignalName`.
- Do NOT call `SetTrailStop()` there either — the existing warning stands.
- `EnableAutoBreakeven`, `BreakevenTriggerTicks` and `BreakevenOffsetTicks`
must remain as parameters and must continue to work unchanged for the
scaler leg. RESOLVED (DEC-20260818-18, 2026-08-19): skip breakeven on the
runner leg unconditionally — do NOT add a new `EnableRunnerBreakeven` flag
or any other toggle. If `_runnerSignalName` is the leg in question, the
breakeven block simply does not act on it, full stop.
- Keep the `BREAKEVEN ...` FileLog line only if it still describes something
that happened. If the block no longer acts, remove the log line rather than
logging a no-op.
DO NOT change: scaler leg stop/target handling, `intent.StopTicks`, the dynamic
ATR stop, sizing, risk validation, or order submission ordering.
## SECONDARY DEFECTS IN THE SAME BLOCK — fix only if Option 0 leaves the block live
- `entryPrice` is `Position.AveragePrice` — the BLENDED average across scaler
and runner legs, not the runner's own fill. On 2026-08-16 this produced a
breakeven price of 30200.08, which is not a valid NQ price (tick 0.25).
If any breakeven logic survives, it must use the runner leg's own entry and
must round to `TickSize`.
- `Calculate = OnBarClose` means `BreakevenTriggerTicks = 20` actually fires at
24-28 ticks. Document this in the parameter's `Description` attribute so the
value stops meaning something it does not mean.
## TESTS (required)
Add to `tests/NT8.Core.Tests/` or `tests/NT8.Integration.Tests/`:
1. A regression test asserting that, for a runner signal name, no `SetStopLoss`
call is issued after a `SetTrailStop` has been issued for that same signal.
Use the existing `MockNT8OrderAdapter` / recording-adapter pattern; if no
seam exists to observe these calls, say so explicitly and propose the
smallest seam rather than fabricating coverage (GAP-022 precedent).
2. A test asserting the scaler leg's stop/target behaviour is unchanged.
3. If any breakeven logic survives: a test that the breakeven price is a valid
multiple of `TickSize`, and that it derives from the runner's entry.
## VALIDATION (operator, after deploy + manual NinjaScript compile)
- SIM/replay only — NOT the live frozen account — until this passes.
- **A manually-placed order does NOT validate this.** The defect and fix both live inside
`NT8StrategyBase`'s own automated order management — `_runnerSignalName`, `_runnerActive`,
and the `SetStopLoss`/`SetTrailStop` calls in `SubmitOrderToNT8()` only get set up when
the STRATEGY submits its own entry via `EnterLong`/`EnterShort` with those signal names. A
manual order typed into the NT8 order-entry window is a completely separate position with
no signal name the strategy tracks — the runner-trailing-monitor block (`_runnerActive &&
!string.IsNullOrEmpty(_runnerSignalName)`) never engages for it, so it would prove nothing.
The strategy has to generate the trade itself.
- **When the market is closed, use NinjaTrader Market Replay (Playback connection) instead
of a live SIM trade.** Replay feeds previously-recorded historical data to the strategy at
playback speed while it is fully armed and running exactly as it would live — `OnBarUpdate`
fires per bar, `SubmitOrderToNT8()` and the runner-trailing-monitor block execute
identically. This is a legitimate substitute for a live SIM trade, not a lesser one.
Recommended: replay one of the four dates already used as this defect's evidence
(2026-08-07, 2026-08-10, 2026-08-16, or 2026-08-17 — see RUNTIME PROOF table above), since
each is already confirmed to produce a runner trade reaching 25+ ticks under the OLD
(defective) code. Replaying the same date now gives a direct before/after comparison
against the exact `BREAKEVEN runner stop ->` lines already in the record for that session.
- Take one SIM/replay trade that reaches +25 ticks or more. Confirm NO
`BREAKEVEN runner stop ->` line appears for the runner.
- Confirm the runner's exit is materially better than entry + 1 tick, and that
the exit reason in the NT8 execution grid reads as a trail stop, not a
fixed stop.
- Confirm the scaler leg still exits at its profit target unchanged.
## SEQUENCING — IMPORTANT
This task BLOCKS RUNNER-001 (`tools/runnersweep`). Sweeping
breakeven-trigger x trail-distance against a runner whose trail is disabled
would return a trail axis with no effect and a confident, meaningless
recommendation. Fix this first, then sweep.
It also supersedes the framing in DEC-20260810-02 and DEC-20260815-01, both of
which describe this as a parameter-placement problem. Record a superseding
decision entry when the option is chosen.
## GOVERNANCE
Track as [GAP-054] in SPRINT_BOARD.md. Add a decisions.md entry recording the
option chosen, the NinjaTrader documentation citation, and the expected effect.
Reference: NT8_SDK_Master_Document_v7.0 Finding 6, Sections 4.8 and 9.5 (P2-0).