Building a Local Stop-Loss System for MQL5 Positions
Summary
This tutorial explains how to implement local stop losses in an MQL5 Expert Advisor. Instead of sending a stop price to the broker, the EA stores it on the trading terminal, checks quotes on each tick, and closes a position with a market order when the trigger is reached. It derives the relevant quote side from the closing trade: a buy position is monitored against bid, while a sell position is monitored against ask. The design scans open positions, creates and tracks a stop for each, closes positions when conditions are met, and removes tracking data and chart objects when positions close.
The article uses a hash map keyed by position ticket to track multiple stops, and describes draggable chart lines and labels for adjusting and identifying them. It frames local stops as a way to keep the trigger price undisclosed and avoid broker minimum-distance restrictions. However, execution still depends on the terminal monitoring prices and submitting a market close; if the terminal is offline or disconnected, the local trigger cannot act. The tutorial explains implementation mechanics but provides no comparative execution study or evidence of better trading outcomes.
Key ideas
- A local stop stores its trigger price on the terminal and submits a market close when the monitored quote reaches it.
- For a buy position the EA checks bid, while for a sell position it checks ask.
- A hash map keyed by position ticket can track stops across multiple open positions.
- Chart lines and labels let traders view and adjust local stop levels.
- Because monitoring and closing occur in the terminal, the system depends on the terminal being active and connected.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.