Back to feed
Dev.to
Dev.to
7/20/2026
Three Bugs, One Pattern: How My Trading Bot Put Stop-Losses Below Entries on Short Trades

Three Bugs, One Pattern: How My Trading Bot Put Stop-Losses Below Entries on Short Trades

Short summary

A developer details three bugs in a trading bot's FVG anchoring feature that caused stop-losses to be placed below entry prices on short trades, effectively giving trades no protection. All three bugs stemmed from short-trade logic being copied from long-trade code without proper inversion: wrong FVG type selection, inverted validation guard, and missing breakeven activation check. The author fixes each bug with code changes and traces them to a common root cause.

  • Three bugs in short-trade stop-loss anchoring all stemmed from copying long-trade logic without inversion
  • Stop-loss was placed below entry on shorts, allowing losses before the stop could trigger
  • Root cause: short-trade code path was never properly validated or backtested

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more