Skip to content
All library documents

Managing Open Trades with Break-Even, Trailing Stops, and Partial Closes

Article MQL5 code base

Summary

The document describes a trade-management library for positions that have already been opened. It can move stops to break-even after a profit threshold, trail stops, partially close positions, and add missing stops or targets. Triggers can use multiples of initial risk (R), average true range, or points; trade selection can be restricted by symbol or magic number.

The library records completed actions so a terminal restart does not repeat them, and defers stop changes that violate broker distance limits. Its calculations are presented as independently testable, with an included self-test, and the document reports checks in a strategy tester and use on a demo account. It does not generate entry signals, and stops may execute at worse prices during fast markets. Management also depends on the terminal and EA running while prices move.

Key ideas

  • The library manages existing positions and does not open trades or generate signals.
  • Break-even, trailing, partial-close, stop, and target rules can use R, ATR, or points as applicable.
  • A position without an initial stop has no R value, so R-based rules skip it.
  • Saved position state prevents completed actions from being repeated after a terminal restart.
  • Stops may be delayed by broker distance limits or filled at worse prices in fast markets.

Tags

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