Skip to content
All library documents

Global Stop-Loss Control for All Open Positions

Article MQL5 code base

Summary

This Expert Advisor applies a portfolio-wide loss threshold: when losses across open positions exceed a fixed maximum, it closes all positions. Before beginning the close process, it records the trigger in a terminal global variable. The saved state lets the advisor continue attempting to exit positions if the multi-step closing process is interrupted.

After all positions are closed, the global variable is removed. This design addresses the possibility that closing trades can take time and fail partway through, so the trigger remains available for recovery. The document does not specify how losses are calculated, whether costs or unrealized losses are included, how the maximum is selected, or what happens if trading permissions or market conditions prevent execution. It describes a risk-control mechanism rather than evidence of effectiveness or a full position-management strategy.

Key ideas

  • The advisor closes all open positions when their combined losses exceed a configured maximum.
  • It records the loss-trigger event in a terminal global variable before closing trades.
  • The saved trigger supports continued closing attempts if execution is interrupted.
  • The variable is deleted once all positions have been closed.
  • The description does not define the loss calculation or provide performance evidence.

Tags

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