Forum Sign in Register

Exit Management in Trading Robots: Trailing Stops, Break-Even and Partial Closes Done Right

Started by Support 1 week ago · 0 replies RSS

Most discussions about trading robots obsess over the entry: the indicator combo, the pattern, the signal. But ask anyone who has run an EA on a live account for a few years and they will tell you the same thing — the exit logic is where the money is actually made or lost. Two robots with identical entries and different exit management can produce completely different equity curves. This article covers the three exit mechanisms every robot builder should understand: trailing stops, break-even moves, and partial closes.

1. Trailing stops: letting winners run without giving it all back

A trailing stop follows price at a defined distance as the trade moves in your favour, and never moves backwards. When price reverses by more than that distance, the position is stopped out — ideally well above your entry.

The design decisions that matter in code:

  • Fixed-distance vs volatility-based. Trailing by a fixed number of points is simple but breaks when volatility changes. Trailing by a multiple of ATR (e.g. 2-3x ATR) adapts automatically: wide in fast markets, tight in quiet ones.
  • Step size. Modifying the stop on every tick spams the server with order modifications and can get you rate-limited by the broker. Only modify when the improvement exceeds a minimum step (say 5-10 points).
  • Structure-based trailing. Instead of a distance, trail below the most recent swing low (for longs). This respects market structure but needs careful swing-detection logic.
  • Activation threshold. Many robots only start trailing after the trade is up by some amount. Before that, the initial stop-loss does its job.


The classic failure mode: a trail that is too tight turns a winning system into a scratch-fest — you get stopped on noise before the move develops. Backtest the trail distance as seriously as you backtest the entry.

2. Break-even: the psychological free ride that is not free

Moving the stop to the entry price (plus a few points to cover spread and commission) once the trade reaches a profit threshold is the most popular exit modification in retail EAs. It feels great: "worst case, I lose nothing."

The catch is statistical. Markets routinely pull back to retest entry zones before continuing. A break-even move placed too early systematically converts trades that would have been winners into zero-profit exits, while barely reducing the size of your real losers (which usually go straight to the stop anyway). In many backtests, an aggressive break-even rule lowers total expectancy even though it raises the win-feel.

If you code it, make both parameters explicit and optimizable: the trigger distance (when to move) and the offset (where to move — entry + spread + commission at minimum, or the ride is not actually free).

3. Partial closes: scaling out in code

Closing a fraction of the position at a first target and letting the rest run is a compromise between "take the money" and "let it ride". In MetaTrader-style platforms a partial close is implemented by closing part of the ticket volume; the remainder keeps the original ticket (MT4) or position (MT5, netting aside).

Implementation details that bite:

  • Minimum lot and lot step. You cannot close 0.5 of a 0.01-lot position. Check the symbol's minimum volume and volume step before splitting, and round correctly, or your close order will be rejected.
  • State tracking. After a partial close your robot must know it already scaled out, even after a restart or VPS reboot. Persist state (e.g. in the position comment, magic number scheme, or a file) — do not rely on in-memory flags.
  • Combining with break-even. The common pattern is: close 50% at 1R, move the stop to break-even on the remainder. That combination has a very defensive profile — test whether it actually beats a plain fixed target on your strategy's data.


Testing exit logic honestly

Exits are exquisitely sensitive to execution detail, so test them with tick-level data where possible, model spread realistically, and remember that a trailing stop in a backtest gets perfect intrabar fills that live trading will not always match. Run the same exit settings on a demo account and compare the modification logs against the backtest before trusting the numbers.

The bottom line

Entries decide how often you are right; exits decide how much being right pays. Code your trailing stops with volatility awareness and a sane step size, treat break-even as an optimizable parameter rather than a free lunch, respect the broker's volume constraints when scaling out — and give your exit parameters the same backtesting rigour you give your entries.

Sign in to reply.