Skip to content
All library documents

MQL5 Breakeven and Trailing Stops with Timer-Based Triggers

Article MQL5 articles

Summary

This article describes adding breakeven and trailing-stop automation to an MQL5 Expert Advisor managing OCO-style protection. Breakeven is triggered when a position's profit reaches a configured threshold, then the stop is moved to the opening price. After breakeven, the EA checks the relevant market price and advances the stop by a fixed gap when price has moved far enough from the current stop. The implementation accounts for buy or sell direction and discusses why chart pricing mode and spread characteristics matter when selecting the price used for trailing logic.

The author recommends calling these checks from a millisecond timer rather than OnTick, arguing that frequent tick events can overload a distant client platform and that a timer provides periodic checks. The sample sets a 100 millisecond interval and releases it on deinitialization. The article also sketches a pending-order stop variant and demonstrates it in a video, but provides no quantitative comparison of trigger performance. It cautions that the simple mechanism is unsuitable for portfolio setups and that asset-specific behavior must be understood before using it.

Key ideas

  • A profit threshold can trigger a breakeven adjustment that moves a position's stop to its entry price.
  • After breakeven, a trailing stop can advance by a fixed gap when price moves sufficiently far from the stop.
  • Buy or sell direction, chart price mode, and spread behavior affect which market price should drive the trailing check.
  • The article uses a periodic timer to call trigger checks and recommends releasing the timer when the EA stops.
  • The mechanism is presented as a simple automation example and is cautioned against for portfolio setups.

Tags

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