A Stop Should Only Move One Way: Lessons From My Trading Bot's First Weeks Live

2026-12-02来源 dev.toEnglish

My trading bot passed every test I threw at it. Then it went live, and within a few weeks it had sold a winner too early, let a gain fade while its stop sat still, and shown me a blind spot in how it scored setups.

The stop problem was the most expensive one, and the fix came down to one rule:

def update_stop(position, current_stop, price): """A stop should only ever move one way: up.""" candidate = trail_from(price) # however you size your trail if price > position.entry and current_stop < position.entry: candidate = max(candidate, position.entry) # first job: get to breakeven return max(current_stop, candidate) # never loosen a stop 

Three things I learned the hard way:

  1. Correct logic on a slow clock is still a bug. My stop math was fine. It just didn't run often enough, so a fast move up and back down happened entirely between updates.
  2. Breakeven first. Once a trade is green, the first priority is making sure it can't turn into a loss. Everything else comes after.
  3. max() is a safety rail. If a bad data point or a reset ever produces a lower stop, the last line throws it away. A stop that can loosen is a stop you can't trust.

The other problems (the killed winner, the scoring blind spot, and the temptation to lower the bar) are in the full write-up: What went wrong with my trading bot.

Before this, Part 5 covered a different kind of surprise: why my trading bot bought nothing.

Educational only, not financial advice.

原文:https://www.a8q9.cn/en/article/a-stop-should-only-move-one-way-lessons-from-my-trading-bot-s-first-weeks-live-937ceb.html

相关文章