Skip to content
All library documents

Classifying and Reading Aggregate Hedge Positions in MQL5

Article MQL5 articles

Summary

The article describes how to represent an aggregate position formed from multiple orders in MetaTrader 5's hedging account mode. It classifies positions as buy-only, sell-only, net-buy, net-sell, or locked, with mixed positions distinguished by comparing total buy and sell volume rather than order counts. It then introduces a class design for collecting orders of the same symbol, optionally filtered by an Expert Advisor magic number, and exposing combined properties such as volume, prices, stops, commissions, swap, profit, and margin.

The implementation builds on the platform's position and symbol information classes, selects the relevant tickets, and calculates aggregate values. Initialization checks that the account uses retail hedging and restricts the example to Forex contract calculation mode. The article also describes a chart panel for viewing hedge properties and handling updates as positions change. This is platform-specific implementation guidance, not an evaluation of hedging as a strategy; the Forex and account-mode checks limit the example's direct applicability.

Key ideas

  • An aggregate hedge position can be categorized by its buy and sell composition.
  • For mixed positions, net direction depends on total volume on each side rather than the number of orders.
  • A position information class can collect same-symbol tickets and expose aggregate trading properties.
  • The example requires a retail hedging account and supports Forex contract calculation mode.
  • A chart panel can display changing position details and respond to trade and chart events.

Tags

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