Filtering and Updating Trailing Stops by Symbol and Magic Number
Summary
This document explains an expert advisor approach for moving stop losses as a trade becomes profitable. The user sets whether trailing is enabled, a profit distance at which trailing begins, a step size, and a magic number. On each tick, the routine scans open trades and filters them by magic number and the chart symbol before considering buy or sell positions. For eligible trades, it calculates a new stop from the current Bid or Ask and modifies the order when the configured distance and step conditions are met.
Initialization checks that the start distance is positive when trailing is enabled, while a helper converts symbol digits into a pip-sized price increment. The example is implementation guidance, not evidence of trading performance: it gives no tests or results and does not discuss slippage, broker stop-distance restrictions, or broader risk controls. Its pip conversion handles common two-, three-, four-, and five-digit quotes, so readers should check whether it suits their instrument and broker conventions before relying on it.
Key ideas
- Trailing begins after a position reaches a configured profit distance and then advances in set increments.
- The routine scans open orders and filters them by magic number and chart symbol.
- Buy and sell positions use different Bid and Ask calculations to place the stop loss.
- A helper derives a pip-sized price increment from the symbol’s quote precision.
- The example does not report testing or address broker restrictions and broader risk controls.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.