Problem with closing position

 
While working on an EA in mql5, I encountered a problem that I don't know how to solve. I have no problem opening a position. When closing in the debugger everything works fine. In real life, however, I have a lot of problems and sometimes a new opposite position is created, i.e. when it is sell, it turns into buy. And sometimes there are two positions left.
I don't know what the problem is.
 
Zbigniew Mirowski: While working on an EA in mql5, I encountered a problem that I don't know how to solve. I have no problem opening a position. When closing in the debugger everything works fine. In real life, however, I have a lot of problems and sometimes a new opposite position is created, i.e. when it is sell, it turns into buy. And sometimes there are two positions left.
I don't know what the problem is.

Without more information we can only guess. By more information, I mean source code, log output, trade log, screenshots and a more detailed explanation of the issues.

 

As I wrote earlier, when debugging the order it closes properly, but when I do this "life" a new order is created. That's why the tickets are different.


I'm thinking of doing another workaround and checking if position exists and closing it. But it can have the same effect :)


This EA is conceived as a performer, all the logic is elsewhere. It fetches commands from the database and is supposed to execute them


I made a version using the CTrader class and ... the effect is the same :))


Ok, I found a bug :)) Sorry for bothering.
It turned out that the struct ro was not erased and was passed to the second part of the code, the sell order was executed again. And I ended the debugger after doing the close and didn't notice it. It cost me a few days of work but at least I learned the secrets of mql5 :))))