Skip to content
All library documents

Designing Indicator-Based Trailing Stops with an MQL5 Class

Article MQL5 articles

Summary

This article explains how to build a reusable MQL5 trailing-stop class for managing open positions. A base class handles position direction, current stop level, stop updates, timer-driven indicator refresh, and optional chart buttons for enabling or disabling the feature. Subclasses supply the indicator-specific logic that determines trend direction and proposed stop levels. The examples include distance-based stop updates and indicator-driven approaches using tools such as moving averages, Parabolic SAR, and NRTR.

The article also describes integrating instances into an Expert Advisor lifecycle: initialize parameters and timers, refresh indicators, check positions during ticks, process chart events, and release resources at shutdown. Code examples and a sample expert illustrate the implementation, but the document does not provide backtest results or comparative evidence that one stop method improves returns. Stop placement and update behavior depend on each indicator and its parameters, and the discussion is implementation guidance rather than a tested trading recommendation.

Key ideas

  • A base class can centralize position checks and stop modification while subclasses calculate indicator-specific levels.
  • A timer can refresh indicator data and keep indicator handles active.
  • A trailing stop can be enabled or disabled through program logic or a chart button.
  • The sample integrates initialization, refresh, stop checks, event handling, and cleanup into an Expert Advisor.
  • The article presents implementation examples but reports no comparative performance tests.

Tags

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