← Changelog

Cointegration Pairs, Correctness Audit

Patch7 June 2026· per-strategy

Audit / Issue Found

A deep review of every variable in this pairs strategy turned up three real bugs that were each quietly biasing the strategy in the same direction, against you.

Before the patch

The first bug was that the audit log of every entry recorded the ask as the buy price, but the post-only buy that the strategy actually places fills at the bid. The recorded entry price was higher than the real fill price by the full spread.

The second bug was on the profitable revert exit. On a profitable mean-reversion exit the strategy places a post-only sell that fills at the ask. The profit calculation and the audit log were both using the bid as if the sell had been a market order. Because ask is higher than bid, the recorded profit was lower than the real profit by the full spread. So every revert win looked smaller than it actually was.

The third bug was in the audit log when the BE_GUARD safety blocked a sell. The safety check correctly skipped the profit and the win-loss counter when the order was blocked, but a copy of the ghost trade was still being pushed into the audit log, which would then be replayed by any analytics that read the log as ground truth.

After the patch

The entry price is now recorded as the bid that the post-only order actually fills at. The exit logic now picks the right price based on whether the exit was a market sell or a post-only sell, and both the profit calculation and the audit log use that same price consistently. The audit log no longer records phantom trades when the BE_GUARD blocks a sell.

Three other findings from the review were checked. Two were minor inconsistencies that did not affect trading decisions. One was a timezone-handling note that the operator can address by setting the bot's clock as desired.

Bottom line

Your audit log now matches reality, your profitable revert exits are no longer silently understated by the spread, and the BE_GUARD safety no longer leaves phantom trade entries behind for analytics to replay.