Skip to content
All library documents

Core Order Functions and Account-Specific Position Management for EAs

Article MQL5 articles

Summary

This article outlines core functions for an automated trading system: submitting pending orders, placing market orders, changing order prices, and explicitly closing positions. It explains that position handling depends on account mode. On netting accounts, an opposite market order can reduce or close a position; on hedging accounts, it may open an offsetting position instead, so the EA needs a clear close request. The discussion also covers managing stop-loss and take-profit levels through pending orders or position modifications.

The implementation shares common order fields, including volume derived from a leverage parameter, protective levels, expiry settings, and an optional magic number for identifying EA orders. It flags practical risks in closing trades, such as price gaps, connectivity interruptions, and insufficient liquidity. The guidance is an implementation tutorial rather than a tested trading strategy, and its examples do not establish that a particular order-management approach is suitable for every broker or account configuration. The author also advises monitoring an EA while it runs.

Key ideas

  • An EA generally needs separate functions for market orders, pending orders, order modification, and position closure.
  • The correct close procedure differs between netting and hedging account models.
  • A magic number can help an EA identify the orders it created.
  • Order exits can be affected by price gaps, connection failures, and inadequate liquidity.
  • The article recommends active supervision of automated trading systems.

Tags

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