You must understand the difference between 'heading' and 'netting' a merchant account.
More details in the help: Basic Principles - Trading Operations

Basic Principles - Trading Operations - MetaTrader 5 Help
- www.metatrader5.com
Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position...
Thanks. That helps a lot. A bit surprised because this documentation makes it clear that there's only one position per symbol.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
It seems that position volume and PositionsTotal are switched or something. Running this code, which just buys twice then sells once leaves POSITION_VOLUME at 1 after the first order is filled. However PositionsTotal() increases after each order (including the final sell order) to 3. I'm a newbie, so I'm sure I'm missing something, but can't see what it is.