Last post ended with a promise: find the last point the account was genuinely flat, and match forward from there. This one is that algorithm, plus the two problems that only showed up once it existed — a fill that had nowhere correct to land, and a completed trade that belonged to a session it never touched.


Where this fits

The setup is in the previous post: sessions in this system aren't calendar units, they're strategy epochs, and a reoptimization can rotate one underneath an open position. A resting stop-loss submitted under the old session can fill after the new one has already started, and a trade calculator scoped to a single session's orders doesn't have enough information to see the whole round trip. The root cause traces back further, to why contracts expire and the state machine that rolls them — neither of those pauses the reoptimization schedule, so the rotation and an open position can always coincide.

This post is the fix.