not able to close a position in any way

 

Hi guys. I have faced a weird problem. I am running my EA on GBPUSD. Every thing was ok, several positions have been opened and closed by EA successfully. However, since a position is opened, it can not be closed in any way. I am using the following code to closing:

if (!trade.PositionClose(Symbol(), 10))   
         {
            Print("Close Order failed. Return code=",trade.ResultRetcode(),
               ". Code description: ",trade.ResultRetcodeDescription());
         }
         else
         {
            Print("Close Order executed successfully. Return code=",trade.ResultRetcode(),
               " (",trade.ResultRetcodeDescription(),")");
         }

and the printed result is:
Close Order executed successfully. Return code=10008 (placed) 

but the position is still there, in the Trade tab of MQL5 Toolbox.

In addition, The EA is such that the close command is repeating again and again, until be sure that the closing is happened really, by using the following code:

        Sleep(100);
         
         if (!PositionSelect(Symbol()))//If There is not an open position
         { 
            ClosePositionFlag = 2;
            ThereIsAPosition = false;    
         }

if ClosePositionFlag = 2, the attempt to close the position will be stopped. 

Also, it is weird because I even can not close the position manually. any attempt for manually modifying or closing or adding extra SL or TP to force it to be closed, is rejected. Any try for closing and opening mql5, restarting,... is not working. How can I manage such a situation? How can I force a position to be closed in similar cases? 

Thank you for helping me in advance.

 

My update:

I am checking if there is a position or not inside On Tick function:

if(PositionSelect(Symbol()))
      {         
         ThereIsAPosition = true;         
      }
      else
      {
        ThereIsAPosition = false; 
      }
        

Sometimes, the result is true, sometimes false, while that position is still open, there. 

I also checked my global variables. It seems that while EA running, they are restetting sometimes to their initialized values! 

 
sammsfy:

Hi guys. I have faced a weird problem. I am running my EA on GBPUSD. Every thing was ok, several positions have been opened and closed by EA successfully. However, since a position is opened, it can not be closed in any way. I am using the following code to closing:

and the printed result is:
Close Order executed successfully. Return code=10008 (placed) 

but the position is still there, in the Trade tab of MQL5 Toolbox.

In addition, The EA is such that the close command is repeating again and again, until be sure that the closing is happened really, by using the following code:

if ClosePositionFlag = 2, the attempt to close the position will be stopped. 

Also, it is weird because I even can not close the position manually. any attempt for manually modifying or closing or adding extra SL or TP to force it to be closed, is rejected. Any try for closing and opening mql5, restarting,... is not working. How can I manage such a situation? How can I force a position to be closed in similar cases? 

Thank you for helping me in advance.

Hi!

I believe 10008 is simply "the order was placed" and not necessarily "was performed/done".

Since you say that you cannot close them manually, I guess the problem may remains in your MT5 installation and/or communication with your broker.

Anyway, try to:

1- Suppress the SLIP value.

2- If it does not function, try a different value like 5 or 15.

Anyway, your code seems have a problem (which cannot explain why you can't close them manually). See the code below for a reference about what I perform here (obviously it is a resume to make easier your understanding):


int Opened = PositionsTotal() - 1;

for(int i = Opened; i >= 0; --i)
{
        // returns the number of open positions

       m_position.SelectByIndex(i);         
       string simbolo		= PositionGetSymbol(i);
       ulong Ticket             = PositionGetInteger(POSITION_TICKET);
       string Comentario	= PositionGetString(POSITION_COMMENT);
       long tipo                = PositionGetInteger(POSITION_TYPE);    // Here you get BUY or SELL ops.
       long MN                  = PositionGetInteger(POSITION_MAGIC);

       if((simbolo == _Symbol) && (MN == m_magic)   && (tipo == TipoOp)    )
       {
                if(m_trade.PositionClose(Ticket, -1) == true)
               {
                     Print(Coment + " -> " + IntegerToString(Ticket, 0, simbolo));
                     return true;
                }
       }
 


Good luck

 
sammsfy:

Hi guys. I have faced a weird problem. I am running my EA on GBPUSD. Every thing was ok, several positions have been opened and closed by EA successfully. However, since a position is opened, it can not be closed in any way. I am using the following code to closing:

and the printed result is:
Close Order executed successfully. Return code=10008 (placed) 

but the position is still there, in the Trade tab of MQL5 Toolbox.

In addition, The EA is such that the close command is repeating again and again, until be sure that the closing is happened really, by using the following code:

if ClosePositionFlag = 2, the attempt to close the position will be stopped. 

Also, it is weird because I even can not close the position manually. any attempt for manually modifying or closing or adding extra SL or TP to force it to be closed, is rejected. Any try for closing and opening mql5, restarting,... is not working. How can I manage such a situation? How can I force a position to be closed in similar cases? 

Thank you for helping me in advance.

Show your log files (both Experts and Journal).
 
AliceRioBR #:


Thanks Alice.

Slip value changing didn't solve the problem. I also used your piece of code and it helped me to identify the position. However, at last I uninstalled MT5. with the new installation, and after one day of testing, I have not seen such a problem yet. I hope it does not happen again. 

 
Alain Verleyen #:
Show your log files (both Experts and Journal).

Unfortunately, I don't have them. I finally uninstalled MT5. With the new installation, and after one day of testing, I have not seen such a problem yet.


That happening can be so much scary while using a real account. Do you have any idea on how to prevent such fatal errors? I mean when the system or MT5 is messed up and the mt5 doesn't even allow for manually closing/modifying a position in any price. For example, is there a way to protect the account from continuing to lose money?


Thank you in advance.