Error code "0" on OrderClose() function

 

Hi all, I have a strange error when my expert tries to close an order.

I'm sure the condition is met, because I see the "Check" output in the Expert tab.

The problem is that GetLastError() function return "0".

if(Bid>=GlobalVariableGet(StringConcatenate("Take_Profit_1_",OrderTicket() )) )
              {
              Print("Check");
              OrderClose(OrderTicket(),OrderLots(),Bid,NULL,PaleGoldenrod); 
              
              if(GetLastError()!=1)
              {
              Print("Error closing BUY order @ ratio 1: ",GetLastError());
              }  
              } 

Have you got a suggestion on how to find the problem?

Thank you!

 
Alberto Tortella:

Hi all, I have a strange error when my expert tries to close an order.

I'm sure the condition is met, because I see the "Check" output in the Expert tab.

The problem is that GetLastError() function return "0".

Have you got a suggestion on how to find the problem?

Thank you!

Try this one....

if(Bid>=GlobalVariableGet(StringConcatenate("Take_Profit_1_",OrderTicket())))
     {
      Print("Check");
      if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,PaleGoldenrod))
        {
         Print("Error closing BUY order @ ratio 1: ",GetLastError());
         return;
        }
     }
 

Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
          What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

Reason: