Skip to content
All library documents

Custom Price-Based Stops, Breakeven, and Trailing Logic for Expert Advisors

Article MQL5 articles

Summary

This article explains how a cross-platform Expert Advisor framework can represent stop-loss and take-profit levels as calculated chart prices instead of distances in pips or points. Its CStop design uses customizable methods when a configured stop value is zero, allowing levels to be derived from price series or indicator outputs. The discussion traces how main stops are calculated during order entry and how additional stop levels are created after a trade opens. It also describes platform-specific handling: in MetaTrader 5 netting mode, broker-side stops may be omitted from the entry request because they would affect the full position.

The article introduces CTrail for managing how a stop evolves over time, along with containers for applying trailing rules to orders. Examples cover custom stops, breakeven, and trailing behavior in MQL4 and MQL5. The material is an implementation guide, not a comparison of strategy returns: it supplies no performance evidence or recommended parameter settings. Correct behavior depends on the platform mode, order structure, and the user's custom calculations, so stop logic must be matched to the intended trade and account setup.

Key ideas

  • Custom stop methods can calculate levels from chart prices and market data rather than entry-price distances.
  • A zero configured stop value signals the framework to use custom calculation logic.
  • Main stops are handled during order entry, while additional stops are initialized after a trade opens.
  • Trailing classes represent stop levels that change over time and can support breakeven behavior.
  • MetaTrader 5 netting mode requires care because broker-side stops apply to the whole position.

Tags

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