Yesterday's short position could block today's long trades in my NQ/MNQ simulator, even after the strategy had reset for the new session. That matters for the research: a simulation with silently blocked entries is testing different behavior from the strategy it is meant to represent.
Two pieces of state had drifted apart. The strategy stored its open position. A shared counter enforced a rule that prevents a long entry while a short is open. Resetting the strategy could erase the position while leaving that counter at one.
The ordinary end-of-day close depends on a price bar arriving at or after 15:45 New York time. If the input stops earlier, no bar triggers that check. The regression test isolates the sequence:
| Input | Position state | Shared short count |
|---|---|---|
| Prior session, 12:50 | A short opens | 1 |
| Last input at 12:59:59 | The short remains open | 1 |
| Next session, 09:30 | Daily reset is about to run | Still 1 |
Resetting first loses the position before its exit can reduce the counter. A later long signal then meets a block belonging to a short the strategy no longer holds.
Close the position before forgetting it
The fix uses the engine's cached last timestamp and prices. When the date changes, _force_close_eod_for_previous_day() sends those prices through the normal exit code with a synthetic previous-day 15:45 timestamp. The daily reset runs afterward.
Close, release the gate, then reset
- 01Date changesThe next session brings a new bar
- 02Close old shortUse the normal position-close path
- 03Release gateNoHedgeGate.on_exit() reduces the count
- 04Reset strategyClear daily state after the close
The ordering is the important part:
# Simplified sequence, not the complete implementation.
if bar_date != current_date:
close_remaining_previous_day_positions()
reset_regime()
reset_strategies()The ordinary close path records the closed position and calls NoHedgeGate.on_exit() to release its count. Simply clearing the count would let new trades through, but would also lose the old trade from the results. Both records need to agree about what happened.
Replay the missing event
The test ends the old input at 12:59:59 and resumes at 09:30 the next day. It requires exactly one closed SHORT with reason EOD, and a shared short count of zero. All five existing engine tests passed locally, including this replay.
I keep the result narrow. The last observed price and a synthetic timestamp repair simulator accounting; they do not establish an executable fill during missing market data. Rollover also needs another bar to arrive, so a final truncated day still needs separate closing treatment.
Project sources & checks
mnq-nq-reverse-engineering: src/nq_scalper/engine_v2/engine.py, no_hedge.py, exits.py and tests/engine_v2/test_engine.py.
All five existing engine tests passed locally, including the missing-close day-rollover regression.
docs/research_lineage_audit.md and docs/knowledge_base.md document earlier invalidated results and data-handling mistakes.