Skip to content
All library documents

Guarding Automated EAs Against Duplicate Orders and Netting Risks

Article MQL5 articles

Summary

This article explains safeguards for an automated Expert Advisor (EA) interacting with an order-management class, with particular attention to differences between hedging and netting accounts. It proposes blocking additional pending orders when one is already tracked and preventing new market orders when a hedging position is open. On netting accounts, it warns that a returned order identifier may not be the persistent position ticket, so the EA should retain an existing ticket when appropriate and then refresh or clear its position data.

The article also describes a failure mode in which faulty EA logic repeatedly reduces and reopens parts of a netted position, changing its average price while the displayed volume may appear unchanged. It suggests limiting total volume traded during an EA run and handling errors with different responses for severe and recoverable cases. These measures can limit exposure and improve oversight, but the author stresses that no lock is fully secure and that the EA still requires supervision. The provided excerpt is incomplete, so it does not give a full implementation or evidence from live or simulated trading.

Key ideas

  • Block new pending orders when one is already active, and restrict market orders based on account type and open positions.
  • On netting accounts, do not assume a market order's returned identifier is the persistent position ticket.
  • Repeated partial closes and openings can shift a net position's average price without an obvious volume change.
  • A cumulative traded-volume limit can constrain an EA, but supervision and careful error handling remain necessary.

Tags

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