Skip to content
All library documents

Validating Trade Levels and Trailing Stops in an MQL5 Expert Advisor

Article MQL5 articles

Summary

This programming tutorial develops MQL5 functions for checking and normalizing stop-loss, take-profit, and pending-order levels before trades are opened or modified. It gathers symbol properties such as digits, point size, bid and ask, volume constraints, and minimum stop distance, then uses bar data to generate signals and calculate trailing stops. The example Expert Advisor also includes adjustable position volume, stop and target distances, and a reversal option.

The article describes optimizing the example’s parameters in the MetaTrader 5 Strategy Tester and reports that the optimization took about seven minutes on the stated processor. It does not provide enough detail in the supplied text to assess the strategy’s robustness or out-of-sample performance. The example is presented as a learning step toward a fuller trading system, and the author notes that additional position properties require trade history and are left for later discussion.

Key ideas

  • Check trade levels against symbol properties before opening or modifying a position.
  • Use symbol digits and point size to format prices and evaluate stop-distance constraints.
  • Calculate trailing stops from completed-bar highs or lows, according to position direction.
  • The example generates signals from runs of bullish or bearish bars and exposes several parameters for optimization.
  • Strategy Tester optimization results alone do not establish robustness or out-of-sample performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.