Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Expert Advisor | Trailing Stop Breakeven Manager | Source Code Included

New free code from MQL5: indicators, EAs, and scripts for traders.

A stop manager for MetaTrader 5 that moves your stop loss to breakeven first and then trails it behind price, on manual trades and on positions opened by any other EA.

When a position reaches the breakeven start in points, the stop goes to the entry price plus a small offset, so a winning trade can no longer turn into a loss. After that the trailing stop follows price at a fixed distance in points or at a multiple of ATR, and it only moves when the improvement is at least the step you set, so it does not flood the server with modifications. You can let the trailing start only after breakeven is done, or run both on their own levels.

It does not open trades. It works on the positions already in the account, filtered by magic number (0 takes all of them, manual trades included), by direction and by the chart symbol or the whole account. If a position has no stop loss at all, it can add one at the distance you choose.

Capture price channel breakouts with the Price Channel Expert Advisor. Precise entries and exits. Explore now.

Image for Trailing Stop Breakeven Manager

Settings

Strategy

  • Trailing distance mode (Fixed distance in points): or ATR multiple.
  • Trailing starts at this profit (300 points).
  • Trailing distance from price (200 points).
  • Minimum stop improvement to modify (50 points).
  • ATR period (14) and ATR multiple for the distance (2.0), used in ATR mode. The ATR is read on the chart timeframe and one handle is created per symbol and reused.

Close / Exit

  • Move the stop to breakeven first (true).
  • Breakeven starts at this profit (150 points) and Breakeven offset (20 points above the entry for buys, below for sells).
  • Start trailing only after breakeven is done (true).

Risk protection

  • Add a stop loss when the position has none (0 = off): distance in points from the entry.

Filters

  • Positions to manage (All symbols): or Chart symbol only.
  • Magic number (0 = all positions, manual trades included).
  • Manage buy positions and Manage sell positions (true).

Expert settings

  • Show status on chart (true) and Print every change to the Experts log (true).

What it needs

  • MetaTrader 5 with Algo Trading enabled. It works on hedging and netting accounts.
  • Distances are in points, so check the digits of your symbol. On a gold quote with 2 decimals 200 points are 2.00 in price, with 3 decimals they are 0.20.
  • Every new stop is checked against the broker stops level (SYMBOL_TRADE_STOPS_LEVEL) before it is sent. If the stop would be too close to price, it waits for the next tick.
  • It checks positions on every tick and once per second with a timer, so it keeps working on symbols that are not on the chart.

Make it yours

Run it on its own chart with magic 0 to protect the trades you open from the phone, or set the magic of another EA so it only touches that robot. Test the points mode against the ATR mode in the Strategy Tester on XAUUSD, EURUSD, GBPUSD, US30, NAS100 and BTCUSD: a fixed distance that fits gold on M15 is usually too wide for EURUSD. For partial closes at several targets, pair it with my Partial Close Multi TP Manager.

About this code

Open source. Use it as it is, adapt it, build your own version on top of it.

New versions and new tools are announced first on my MQL5 channel: https://www.mql5.com/en/channels/xander

Questions, suggestions and your own backtests are welcome in the Xander Lab group: https://www.mql5.com/en/messages/02eec85e4364dd01

More tools on my profile: https://www.mql5.com/en/users/09151993a

Provided as is, use at your own risk.

Related

  • Partial Close Multi TP Manager
  • Close All Positions Panel
  • Basket Pair Closer

Changelog

  • v1.0 - 2026-10-25 - Initial release

Complement community code with advanced automation from RobotFX.

79064

Best MetaTrader Indicators + Profitable Expert Advisors