Building a Broker-Aware ATR Trailing Stop Engine
Summary
This document describes a reusable MQL5 engine for managing volatility-based trailing stops. It derives stop distance from a simple average of True Range over completed bars, multiplied by a configurable factor. For long positions the stop can ratchet upward, and for shorts it can ratchet downward. The design uses completed bars to stabilize the volatility estimate while anchoring proposed levels to live Bid or Ask quotes.
The implementation also addresses operational constraints: it rounds prices to the instrument’s tick size, checks broker stop and freeze distances, optionally waits until a proposed stop is beyond the entry price, and records evaluation outcomes in telemetry. A companion indicator illustrates ratcheting behavior, while an Expert Advisor template demonstrates use and reporting. The document describes an implementation architecture rather than evidence of trading profitability. Its indicator is an approximation of live execution, and volatility-based distances may widen sharply during market shocks; broker rules and execution responses can still limit modifications.
Key ideas
- The stop distance is based on average True Range from completed bars and a configurable multiplier.
- Long stops only move upward, while short stops only move downward.
- The engine uses live Bid or Ask prices for anchoring and rounds levels to the broker’s tick size.
- Separate checks address broker stop-distance and freeze-distance constraints.
- An optional entry-price guard and telemetry make behavior configurable and observable.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.