Discussing the article: "Building Your Own Expert Advisor (Part 8): ATR and R-Multiple Trailing Stops"

Check out the new article: Building Your Own Expert Advisor (Part 8): ATR and R-Multiple Trailing Stops.

We add TrailingStop.mqh: a trailing engine plus pluggable methods for the Series EA. Each method proposes a level; the engine decides if and when to send it, enforcing protective direction, minimum step, stops level and freeze level. Included methods are ATR trailing and an R‑multiple ladder, with optional break‑even as a floor. The result is per‑tick, safer stop management under broker constraints.

The previous part moved every risk control in the series into a framework of three classes, one for each scope of risk, and closed by suggesting that a trailing stop could become another class alongside them, with its own configuration structure and an additional call in the tick handler. This part builds that class and connects it to the Series EA. The broker's freeze level was set aside in the preceding parts because it governs changes to an order or position that already exists, and nothing in the EA moved a stop. A trailing stop changes the stop of an open position on every move, so the freeze level is checked here as well, against the stop and target the position already carries.

Every control built so far runs before a trade exists. Sizing, the margin checks, the basket limits, and account limits all decide whether a trade may open and how large it may be. After the order is sent, the EA never looks at the stop again. The basket tier can close a losing group of positions, but nothing moves an individual stop. A position that has traveled a long way in its favor, therefore, still carries the stop it was opened with. If the price turns and comes back, and nothing else closes the position first, the trade gives up all of its open profit and then loses the full amount it risked at entry. The take-profit sits at a fixed multiple of the stop distance, and until price reaches it, nothing protects what the trade has gained.


Author: Solomon Anietie Sunday