Calculating Net Position Volume by Expert Advisor Magic Number
Summary
This article presents a method for tracking the net position volume attributable to a particular Expert Advisor, symbol, and magic number in MetaTrader 5. It adds buy deal volumes and subtracts sell deal volumes, starting from the most recent point in deal history where the net volume was zero. Saving that point lets the program load and process only the necessary portion of history on later runs, rather than scanning the account's full deal record each time.
The implementation uses terminal global variables to persist the saved point across restarts and to distinguish instances by program, symbol, magic number, and account or tester mode. It also describes clearing tester-specific variables and encapsulating the volume calculation in a reusable class. A control example runs four RSI-based configurations across two symbols and two magic numbers to check that volumes remain separate. The article focuses on implementation and resource use; it does not evaluate trading performance. Its method depends on correctly identifying deal history and maintaining the saved zero-volume reference as new deals arrive.
Key ideas
- Net volume for a selected Expert Advisor is calculated by adding buy deals and subtracting sell deals with its magic number.
- Starting from the latest zero-volume point can reduce the amount of deal history processed.
- Persistent terminal variables can store the reference point across Expert Advisor or terminal restarts.
- Prefixes based on program, symbol, magic number, and operating mode help separate stored values.
- The example checks volume tracking across multiple RSI configurations and symbols.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.