Skip to content
All library documents

A Portfolio-Wide Stop That Closes Positions by Loss or Time

Article MQL5 code base

Summary

This document describes an expert advisor that monitors all open positions together and closes them when their combined losses exceed a user-set threshold. The threshold can be measured either as a percentage or in the account’s deposit currency. The advisor can also restrict its operation to a configured time window, allowing it to close positions at a scheduled time as well as respond to losses. It records the loss-triggered stop and closing command in a log.

The described default schedule spans the session from midnight through 23:59, and a start time later than the end time is treated as a window continuing into the next day. The note explains the available controls but provides no testing results or discussion of execution details, such as how partial fills, rejected orders, or positions across instruments are handled. Because the stop applies to the combined open positions, it does not specify individual position limits or show how the selected threshold relates to account risk.

Key ideas

  • The expert advisor closes all open positions when their aggregate loss passes a configured threshold.
  • The loss threshold can use percentage terms or deposit-currency units.
  • A configurable time window can govern when the advisor operates and when it closes positions.
  • A start time later than the end time represents a window continuing into the following day.
  • The description provides configuration details but no performance tests or order-execution analysis.

Tags

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