Skip to content
All library documents

Closing Expert Advisor Positions at an Account-Currency Profit Target

Article MQL5 code base

Summary

The document explains an Expert Advisor approach that triggers take profit using current profit in the account currency rather than a price or pip distance. It counts open orders and sums profit for orders sharing a magic number, which can isolate a particular EA when several strategies are running. Once the target is reached, the example closes matching buy and sell positions for the chart symbol.

The described benefit is that a currency-denominated target can manage profit across multiple open positions and is less directly tied to entry-price slippage than a pip-based target. The method can also be adapted to manage positions across EAs by removing the magic-number filter, or combined with a profit-based trailing stop. The document provides code fragments but no backtest or performance evidence. It does not discuss transaction costs, whether floating profit includes all relevant charges, order-close failures, or how to set a target suited to position size and risk.

Key ideas

  • A profit-based exit can trigger when the combined open profit for selected orders reaches a currency target.
  • A magic number lets the EA count and manage positions associated with a particular strategy instance.
  • The example closes matching chart-symbol buy and sell orders after the aggregate profit threshold is met.
  • The approach can be extended across EAs or paired with a profit-based trailing stop, but no performance testing is provided.

Tags

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