I can't immediately see a problem in the code around order closure. I have also tried running the code above - after zeroing out the problematic Stoploss values in the OrderSend() - in the MT4 strategy tester, and it closes both buy and sell positions.
I haven't inspected the code thoroughly to see whether it's closing positions when intended, but if it isn't closing them at all then I'd look for logic errors introduced for any further modifications you have made. For example, the code as exactly posted above doesn't compile because there is a missing }. If you have edited it incautiously, then you might have done something such as making the entire trading logic part of the block controlled by if(OrdersTotal()<MAX_ORDERS), which would mean that nothing at all further happens once three simultaneous positions have been opened.
If that's not the explanation then the key question is whether the OrderClose() is failing, and your Print() statements are generating messages in the log, or whether nothing is getting logged and therefore the OrderClose() isn't getting called at all.
To add comments, please log in or register