Cross-Platform Trade Tracking Across MetaTrader 4 and 5
Summary
The article explains how differences in MetaTrader 4 and MetaTrader 5 affect the way an expert advisor represents and manages trades. It compares MetaTrader 4 orders with MetaTrader 5 orders, deals, and positions, including the distinct behavior of netting and hedging accounts. A proposed COrder class stores trade details so strategy logic can operate across these platform modes. It discusses ticket handling when opening and partially closing positions, and describes maintaining order state and volume in the class. The approach is illustrated with a class template and examples of platform-specific behavior. The main limitation is that stored objects last only while the expert advisor runs; restart-safe use requires a separate persistence mechanism. The article also notes that stop management and other practical features are outside its current implementation.
Key ideas
- MetaTrader 4 represents a live trade with an order ticket, while MetaTrader 5 distinguishes trade requests, deals, and resulting positions.
- MetaTrader 5 netting consolidates activity into one position per symbol, whereas hedging can maintain multiple positions.
- A shared order class can store trade details and reduce platform-specific differences for strategy logic.
- Ticket behavior differs across platforms, especially after partial closes.
- In-memory trade records are lost on restart unless the expert advisor saves and reloads them.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.