Skip to content
All library documents

Adding a Configurable Trailing Stop to an Expert Advisor

Article MQL5 code base

Summary

The document describes a reusable library for adding a simple trailing stop to a MetaTrader Expert Advisor. Integration involves including the library, declaring configuration variables, and calling its position-management function during the advisor’s execution. Parameters enable or disable trailing, restrict it to profitable positions, set separate stop distances for buy and sell orders, and specify a trailing step.

The function can also be scoped by instrument, trade direction, and magic number, allowing an advisor to manage selected positions. The document includes implementation examples but gives no trading results, testing evidence, or detailed explanation of order-modification behavior and error handling beyond configurable retry attempts and pauses. It therefore explains integration and available controls, while leaving the suitability of any stop settings and their effect on strategy performance to the user.

Key ideas

  • A library can add trailing-stop management to an Expert Advisor.
  • Parameters control activation, profit-only behavior, stop distance, and trailing step.
  • Position management can be limited by symbol, trade direction, and magic number.
  • The document explains integration but reports no strategy performance or testing results.

Tags

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