This part extends the MQL5 risk management framework with two trailing stop methods: fixed points and an indicator line. A base class converts chart levels on Bid-built charts into stop prices and adds the current spread to sell stops so they align with Ask-triggered execution. The Series EA integrates these trails alongside the existing ATR and R-ladder options.
The previous part added TrailingStop.mqh to the framework. It holds one engine, which checks every proposed stop against four rules before sending it, and two methods: an ATR trail and an R-multiple ladder. It also lets an EA create a method of its own and hand it to the engine after Init(), and the engine applies the same four checks to that method as to the two it ships.
This part uses that route for two common ways of trailing. The first keeps the stop a fixed number of points behind price. The second keeps it behind an indicator line, with a moving average as the working example. Both are written in a separate file that includes the engine.
A fixed-point trail is plain arithmetic: take the price the position would close at and step back a set number of points. An indicator trail reads a line such as a moving average, places the stop on it, and moves the stop each time the line moves. The symbol property SYMBOL_CHART_MODE indicates whether bars are built from Bid or from the last deal price. On a Bid-based chart, placing the stop on the line works for a buy. A moving average calculated on those bars is a line in Bid, a buy closes at Bid, and its stop is triggered when Bid reaches it, so the line and the stop are at the same price.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Building Your Own Expert Advisor (Part 9): Point-Based and Indicator Trailing Stops.
The previous part added TrailingStop.mqh to the framework. It holds one engine, which checks every proposed stop against four rules before sending it, and two methods: an ATR trail and an R-multiple ladder. It also lets an EA create a method of its own and hand it to the engine after Init(), and the engine applies the same four checks to that method as to the two it ships.
This part uses that route for two common ways of trailing. The first keeps the stop a fixed number of points behind price. The second keeps it behind an indicator line, with a moving average as the working example. Both are written in a separate file that includes the engine.
A fixed-point trail is plain arithmetic: take the price the position would close at and step back a set number of points. An indicator trail reads a line such as a moving average, places the stop on it, and moves the stop each time the line moves. The symbol property SYMBOL_CHART_MODE indicates whether bars are built from Bid or from the last deal price. On a Bid-based chart, placing the stop on the line works for a buy. A moving average calculated on those bars is a line in Bid, a buy closes at Bid, and its stop is triggered when Bid reaches it, so the line and the stop are at the same price.
Author: Solomon Anietie Sunday