Skip to content
All library documents

Designing an EA for Netting and Hedging Accounts

Article MQL5 articles

Summary

The article discusses account-model differences that matter when adding automation to a MetaTrader Expert Advisor. Netting accounts combine trades in a symbol into one position with an average price, while hedging accounts keep positions separate and can hold opposing exposure. Because stop management and position handling behave differently under these models, an EA must account for the account type rather than assume identical server behavior.

The proposed design adds a manager class between the EA and its order-handling class. This intermediary centralizes order parameters and exposes a smaller set of safer operations. To standardize behavior, the design constrains the EA to one open position and one pending order, making hedging accounts behave more like netting accounts from the EA's perspective. The article also cautions that server errors should be handled selectively rather than cleared indiscriminately. It presents an architectural approach, not comparative testing or evidence that the restrictions suit every strategy or account configuration.

Key ideas

  • Netting accounts aggregate exposure in a symbol, while hedging accounts can maintain separate and opposing positions.
  • Automation must account for account type because position and order handling differ.
  • A manager class can centralize trading parameters and limit access to order operations.
  • Restricting the EA to one position and one pending order makes its behavior more consistent across account models.
  • Error handling should distinguish tolerable server interaction failures from critical faults.

Tags

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