vibeapp.win

What broke

The trailing stop that fired at -15 % and secured nothing

In the stock app, Claude's trailing stop measured the drop from the peak price and ignored the entry price, so on positions that only ever fell it fired before Henning's stop-loss and was labelled as securing a gain. A count of exit types per exchange in production found it while 25 exit tests were still passing.

The short version

What went wrongThe trailing stop measured drawdown from the peak and ignored entry price. On positions that only fell, it fired before Henning's stop-loss and was labelled as securing a gain.

How we found itCounting exit types per exchange in production showed trailing exits averaging -14.8% and -16.8%, while 25 exit tests still passed.

The rule nowArm a trailing stop only after the position has been in profit. Check new exit rules against production data, grouped by exit type and exchange, not only unit tests.

This post documents something Claude got wrong. The claim rests on a commit or a file, not on memory. All of Claude's mistakes

A trailing stop has one job. When a position has gone up and starts to fall back, it sells before the gain is gone. In the stock app, Claude built a trailing stop that also fired on positions that had never gone up at all. It always got there before the stop-loss Henning had set, and the sales were labelled “trailing stop”, a name that suggests there was a gain to protect.

This post covers how that happened, how it was found, and the rule that came out of it. Claude wrote all the code and the commit messages quoted here. The quotes are translated from Norwegian.

Background: three variants, two exit rules

The stock app runs autonomous strategies in three risk variants: passive, balanced and aggressive. Each variant has a hard stop-loss. Passive sells at -25 %, balanced at -15 % and aggressive at -8 %. Each variant also has a trailing stop that measures how far the price has fallen from its peak.

The trailing stop went live in late July 2026. Two days later, on 2026-07-28, it needed its first fix. Henning had noticed that “the old ones take an early exit”, and the commit message agrees he was right: “two design flaws in the trailing stop”. First, a flat 12 % trailing level applied to every variant, which made the passive variant tighter than the balanced one. Second, the peak was measured from entry. That meant positions that were already old got a month of price history they had never had a trailing stop for. All 11 trailing exits came within two days, between -11.5 % and -21.5 %, which the commit calls “an artefact, not a strategy decision”.

The fix set the trailing level to 0.8 times each variant’s stop-loss: 6.4 %, 12 % and 20 %. It also anchored the peak to the date the rule went live. That commit says it was checked against real positions (“0 of 70 positions would exit now”), and 276 tests passed.

The trailing logic still had a third flaw, and the tests did not catch it.

What was wrong

The drawdown was measured from the peak price, and the entry price never came into it. For a position that rose and then fell back, that works. For a position that only fell, the peak is roughly the entry price, so the drawdown roughly equals the loss.

Now put the two levels side by side. On the balanced variant the trailing stop is at 12 % and the stop-loss at 15 %. A position that only falls reaches a 12 % drawdown at about -12 %, before it can reach -15 %. So in that window the trailing stop always fired first. The commit from 2026-07-30 puts it this way:

“Consequence: the owner’s stopLossPct did not govern positions that had never risen, and the sale was labelled with a name that promises there was a gain to secure.”

There were two problems in one. Henning’s stop-loss setting had stopped meaning anything for losing positions, because the trailing stop had in effect become a tighter stop-loss. And the exit statistics said “trailing stop”, which reads as gain protection, when these were plain losses.

How it was found

Nobody spotted it by reading the code. The commit says so directly: “Found by measuring exit types per exchange, not by reading code.”

The production measurement on 2026-07-30, grouped by exit type and exchange:

  • Trailing-stop exits on the Oslo Stock Exchange: 7 sales, average P&L -14.8 %
  • Trailing-stop exits on NASDAQ: 3 sales, average P&L -16.8 %

Those averages are enough to show the problem. The commit’s reasoning: “A trailing stop is supposed to secure gain that is being given back. If it fires at -15 %, it has by definition secured nothing.”

Why the tests did not catch it

The commit message says this in capitals: “THE 25 EXISTING EXIT TESTS PASSED WHILE THE BUG WAS IN PRODUCTION.” No test covered a position that never rose and sat between the trailing level and the hard stop.

Claude also went back to one of the earlier tests: a passive position at -10 % P&L and 21 % below its peak, where the expected result is a trailing exit. Under the new rule it still gives a trailing exit, and that is correct. Worked backwards, that position had been up +13.9 % at its peak, so it was a real winner giving its gain back. The commit says “That test was well constructed; the window just wasn’t covered.” The tests checked the cases someone had thought of. They could not check a case nobody had thought of.

The fix

The trailing stop now has to be armed before it can fire. It arms only once the position has been in profit by at least a threshold, 3 % by default. Each variant can set its own threshold.

The peak gain is not stored anywhere, but it can be worked out exactly from two numbers the exit logic already has. The current price equals the peak price times (1 minus the drawdown). So the peak gain is (1 + P&L) divided by (1 − drawdown), minus 1. The new tests show how this plays out:

  • A position at -13 % that is 13 % below its peak has a peak gain of about zero. The trailing stop is not armed, and the position is held.
  • The same position at -15 % hits the real stop-loss, the one Henning set.
  • A position at +14 % that is 12 % below its peak had a peak gain of about +29.5 %. The trailing stop is armed and fires as before.
  • A position at -11 % that is 13 % below its peak had a peak gain of about +2.3 %. That is below 3 %, so the stop is not armed.
  • With the threshold set to 0, the old behaviour comes back. This shows the threshold is a setting and not something hidden in the code.

The same rule had to go into two places: the main exit decision and the separate target-portfolio engine, which has its own forced-exit logic. Claude used the same calculation and the same constant in both. The commit gives the reason: “two copies would have drifted apart”.

The change shipped in the same batch as a change to how exchanges are weighted. No exchange was open when the changes went in. The test count went from 446 to 451, with five new tests that include the measured production numbers in their comments.

What we take from it

Claude’s trailing stop needed two fixes in two days, for two different flaws. The first time, Henning noticed the symptom: older positions taking an early exit. The second time, a count of exit types per exchange showed it, while the 25 existing exit tests passed.

The rule

A trailing stop arms only after the position has been in profit. Without that, it is just a tighter stop-loss with a misleading name.

Check new exit rules against production data, not only unit tests. Group exits by type and by exchange and look at the average P&L for each. If an exit type’s name promises one thing and its numbers show another, the rule is wrong, however many tests pass. Here, 25 tests passed while the bug was live.