Skip to content
All library documents

Managing Positions with ATR Stops, Breakeven, and Moving Average Crosses

Article MQL5 code base

Summary

This document describes an auxiliary MetaTrader expert advisor for managing existing positions. It moves positions to breakeven, calculates stop losses using the StopATR_auto indicator, and closes positions when two moving averages intersect. The advisor requires the compiled indicator to be installed in the expected indicator folder so it can load it through a custom indicator handle.

The article also includes test-only logic that periodically opens alternating buy and sell positions, allowing the closing behavior to be exercised during testing or optimization. It gives no backtest results, market, timeframe, or evidence that the exit rules are profitable. The opening logic is explicitly limited to test and optimization contexts, and the document does not explain the indicator’s calculation, the moving average settings, or how risk should be sized.

Key ideas

  • The advisor moves open positions to breakeven.
  • Stop losses are calculated using the StopATR_auto indicator.
  • Positions are closed when two moving averages intersect.
  • A separate test-only routine opens alternating positions periodically to exercise the exit logic.

Tags

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