Designing Cross-Platform Expert Advisor Stops for Partial Exits and Risk Control
Summary
The article presents an architecture for managing trade stops in expert advisors that run across MetaTrader 4 and MetaTrader 5. It recommends keeping the main order manager focused on entering and exiting primary trades, while separate stop objects handle stop definition, monitoring, triggering, and platform-specific behavior. Stop information can be stored locally when broker-visible levels are unsuitable or multiple levels are required.
It distinguishes broker-based stops, pending-order stops, and virtual stops managed by the advisor. A designated main stop represents the full-position exit and can supply the risk distance used for position sizing. Other stops may close only part of a trade, with volume allocated as fixed, as a proportion of remaining or initial volume, or as the remainder. The article explains that pending-order replacement can create execution races, so it favors allocating pending-order volume when the trade is created.
This is primarily an implementation and design discussion, not a test of stop strategies or evidence that one stop type improves returns. Practical behavior depends on platform mode, broker execution, and the advisor’s handling of pending orders and partial exits.
Key ideas
- Separating stop management from the main order manager keeps trade-entry logic simpler and allows customization.
- The design covers broker-based, pending-order, and locally managed virtual stops.
- A main stop represents the full-position exit and can define the maximum trade risk for position sizing.
- Partial-exit stops need an explicit volume allocation rule.
- Replacing pending orders can create race conditions that lead to unintended position changes.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.