trade.PositionClose probably has a boolean return value you could print that and look what it says
Use the debugger and step into the function. Find out why.
David _Detnator_:
Probably because closing a position takes time, and PositionTotal() is not updated synchronously, so you are trying to close a position which is already closed ?
I have tried multiple approaches to this, based on the documentation and on information I've found in this forum, and I can't get anything to work.
Simple version:
Same thing but with a bunch of Print statements to try to track down the issues:
The Symbol printed out by the Print(PositionGetSymbol(0)) line is correct. The error message simply says "10006 Request rejected" and no positions ever close.
I understand closing positions is complex in MQL5, but this is the Standard Library function. It's pretty hard to get it wrong...? What could possibly be causing this to reject?
Thanks in advance for any help.

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
I have tried multiple approaches to this, based on the documentation and on information I've found in this forum, and I can't get anything to work.
Simple version:
Same thing but with a bunch of Print statements to try to track down the issues:
The Symbol printed out by the Print(PositionGetSymbol(0)) line is correct. The error message simply says "10006 Request rejected" and no positions ever close.
I understand closing positions is complex in MQL5, but this is the Standard Library function. It's pretty hard to get it wrong...? What could possibly be causing this to reject?
Thanks in advance for any help.