Two concrete problems are visible in the posted helper:
1. The "defensive" branch overrides a broker-reported step of 0.01 with 0.1 multiples. For a requested 0.05, that branch produces 0.10. Remove this forced 0.1 rounding; keep the broker-reported step.
2. CheckTotalVolumeLimit() returns zero to mean "cannot open", but ApplyMinimumLotConstraints() then raises zero to the minimum volume. Preserve the rejection instead of turning it into an order size.
Also, NormalizeDouble(constrainedLot, 2) can destroy a valid volume when the step is 0.001: 0.001 becomes 0.00. Revalidate the final volume against the actual min/max/step after every adjustment; do not guess missing properties.
These are defects in the shown sizing path, not proof of the cause of the closing error. Please show the closing code and log the selected position's symbol/volume, the outgoing request volume at full precision, and the trade result retcode/comment. The opening helper alone cannot explain that rejection.
Reference for the volume fields:
https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
test on EURUSD,H1 (netting) strategy tester report 22 total trades test on XAUUSD,D1 (netting) log files size exceeded 2080 MB, test terminated 2022.04.11 15:39:28 failed market sell 0.15 XAUUSD, close #47 buy 0.15 XAUUSD 1945.32 [Invalid volume] 2022.04.11 15:39:28 failed market sell 0.15 XAUUSD, close #47 buy 0.15 XAUUSD 1945.32 [Invalid volume] 2022.04.11 15:39:29 failed market sell 0.15 XAUUSD, close #47 buy 0.15 XAUUSD 1945.32 [Invalid volume]
Question: How is the EA allowed to open a position with invalid volume if it is not allowed to close the position due to invalid volume?
I do have checks in place to prevent invalid volume, I even hardcoded lotstep of 0.1 increments on XAUUSD/GOLD if the EA is not able to retrieve the actual properties form the broker/symbol.
Can anyone see what im missing?