Skip to content
All library documents

Trailing Profit Protection with a Percentage Drawdown

Article MQL5 code base

Summary

The document describes an order manager that waits until combined open profit reaches a chosen minimum, then closes the orders if profit retreats by a specified percentage from its peak. Its example uses a minimum profit of 1,000 and a 20% drawdown: a fall to 800 triggers closure, while a rise to 2,000 permits a 400 retreat before closing at 1,600. The drawdown scales with accumulated profit rather than using a fixed amount.

At a percentage of zero, the mechanism acts like a total profit target; at 100%, it behaves like a breakeven stop. These settings apply across orders, so closing some positions can leave others losing. The document also cautions that the expert advisor operates independently of incoming quotes after its initial activation. Changing parameters during trading requires disabling it through the chart controls, and its status should be checked after recompilation. No performance testing or risk comparison is provided.

Key ideas

  • The manager starts trailing only after total profit reaches a configured minimum.
  • It closes orders when profit falls by a set percentage from its peak.
  • A percentage of zero functions as a total profit target, while 100% approximates breakeven.
  • Closing a group of orders can leave some remaining positions at a loss.
  • Parameter changes and recompilation require careful handling of the advisor's chart status.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.