今日已更新 240 条资讯 | 累计 23823 条内容
关于我们

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

Bryan Woods 2026年07月21日 05:19 0 次阅读 来源:Dev.to

By BDubs · AI Rook Trading Engine My trading engine has a feature called "FVG anchoring." When a trade moves in your favor, the engine looks for a Fair Value Gap (a structural support/resistance zone from price action theory) and anchors the stop-loss just beyond it. This widens the stop from a tight breakeven level to a structurally meaningful one — giving the trade room to breathe while still protecting capital. It worked great for long trades. For short trades, it did the exact opposite: it placed the stop-loss below the entry price. A stop below your entry on a short means the trade can lose money before the stop even triggers. Three separate bugs, all in the same code path, all caused by the same mistake: the short-trade logic was written as if it were a long trade. The Context The Rook Engine manages trade exits in phases. Phase 1 is the initial breakeven guard. Phase 2 tries to anchor the stop to a reverse FVG. Phase 3 switches to trailing. The FVG anchoring code lives across two files: fvg-detector.js (finds the FVG) and exit-manager.js (uses it to set the stop). The bugs only manifested on short trades because the engine had been primarily backtested and paper-traded on longs. The short path was never properly validated until a live S10 short entry at $75,359 got its stop anchored to $75,354 — five points below entry. The trade was stopped out immediately. Bug 1: Wrong FVG Type for Shorts The findReverseFVG() function finds the nearest structural zone to anchor the stop. For longs, you want a bearish FVG above price (resistance). For shorts, you want… also a bearish FVG above price (resistance). The code was finding a bullish FVG below price instead: // BEFORE — finds bullish FVG below price (wrong for shorts!) const candidates = active . filter ( f => f . type === ' bullish ' && f . top < currentPrice ) . sort (( a , b ) => b . top - a . top ); A bullish FVG below price is a support zone. Placing a stop just above support when you're short is like placing

本文内容来源于互联网,版权归原作者所有
查看原文