Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Trailing Stop That Starts at the Take-Profit Level - expert for MetaTrader 5

Gilberto Cardona Velez
Gilberto Cardona Velez
  • MQL4/MQL5 developer - Expert Advisors, backtests and strategy conversion at  Laboratorio de Estrategias
  • Colombia
  • 825
Laboratorio de Estrategias - MQL4/MQL5 development with tested, honest results.
SMALL JOBS FROM 30 USD (MQL5 Freelance, usually delivered in 1-3 days):
- Fixes and changes to an existing EA or indicator (source code required)
- Adapting one of my free CodeBase tools to your own rules
Views:
22
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

This utility works on positions that are already open, whether you opened them by hand or with another Expert Advisor. When the price gets close to the take profit, instead of letting the trade close there, it starts a trailing stop so the trade can keep running while part of the profit is protected. It never opens or closes trades by itself: it only changes the stop loss and the take profit of existing positions.

What it does

  1. Waits for the take-profit zone. For each position that has a take profit, it measures the way from the entry price to the take profit. When the price has covered the percentage you choose (default 90%), trailing starts.
  2. Handles the take profit. You choose: remove it, move it further away by a percentage of the original distance, or keep it.
  3. Trails the stop. The stop follows the price at a fixed distance in points, or at a percentage of the original take-profit distance. It is never moved backwards, it only changes when it improves by at least the minimum step, and it respects the broker's minimum stop distance.

Inputs

  • Start at this % of the way from entry to take profit (1-99)
  • Trailing distance in points, or as a % of the original take-profit distance
  • Minimum step to move the stop
  • Take profit action: remove, extend or keep (and the extension %)
  • Positions to manage: this chart's symbol or all symbols
  • Magic number filter (-1 = any, 0 = manual trades only)
  • Status panel on the chart

Things to know

  • The take profit is stored on the broker's server and closes the trade as soon as the price touches it. That is why the tool must start before 100% of the way; the start value is limited to 1-99%.
  • A position without a take profit is ignored, because there is no level to work from.
  • The tool remembers which positions are already trailing in terminal global variables, so restarting the terminal does not lose them. It only works while the terminal is running with Algo Trading enabled.
  • If the broker rejects a change (for example, market closed), it waits 60 seconds before trying again.
  • A gap or a fast market can jump over the stop: the exit price is not guaranteed.

How it was tested

MetaTrader 5 Strategy Tester, EURUSD, real ticks, September-October 2026, with an internal copy that opens test trades only to exercise the tool: 77 test trades, trailing started on 40 of them, 353 further stop moves, 0 backward moves. This is a functionality test, not a profitability claim.

Test it on a demo account first.

Not financial advice. Past results do not guarantee future results.

Gold MACD Divergence Map Gold MACD Divergence Map

MACD regular and hidden divergences on closed bars with an honest first-touch statistics panel. Not a trading signal.

Close By Filter - close positions by side, symbol, magic number and profit Close By Filter - close positions by side, symbol, magic number and profit

Closes only the open positions that match your filters and, if you choose, deletes matching pending orders. Shows a summary and asks before it acts.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.