OrderSend code error

 

Hello all,

I have a problem with the code of my OrderSend, that I wrote to use it in general purpose. The problem is that sometimes I get an OrderSend error with the 0 error code

int MyOrderSend(string symbol, int type, double volume, double price, int slippage, double stop, double take, string comment, int magic, datetime expiration=0, color col=CLR_NONE)
{
   int ticket = -1, error = 0;
   volume = NormalizeLots(volume);
   price  = NormalizeDouble(price, Digits);
   stop   = NormalizeDouble(stop, Digits);
   take   = NormalizeDouble(take, Digits);
   ...
   RefreshRates();
   ticket = OrderSend(symbol,type,volume,price,slippage,stop,take,comment,magic,expiration,col);
   if (ticket > -1) {
      return(ticket);
   }
   else {
      error = GetLastError();
      if (error == 130) {
         RefreshRates();
         ticket = OrderSend(symbol,type,volume,price,slippage,0,0,comment,magic,expiration,col);
         if (ticket >-1) {
            if (OrderModify(ticket,price,stop,take,expiration,col)){
                  return(ticket);
            }
            else{
               error = GetLastError();
               Print("Error OrderSend! Code: ",error," ",ErrorDescription(error),")");
               return -1;
            }
         }
         else {
            error = GetLastError();
            Print("Error OrderSend! Code: ",error," ",ErrorDescription(error),")");
            return -1; 
         }
      }
      else {
         error = GetLastError();
         Print("Error OrderSend! Code: ",error," ",ErrorDescription(error),")");
         return -1; 
      }
   }
   return(-1);
}

Why it happens ?

 
Algosupremacy:

Hello all,

I have a problem with the code of my OrderSend, that I wrote to use it in general purpose. The problem is that sometimes I get an OrderSend error with the 0 error code

Why it happens ?

After the GetLastError() call, the contents of _LastError are reset.
 
Algosupremacy:

Hello all,

I have a problem with the code of my OrderSend, that I wrote to use it in general purpose. The problem is that sometimes I get an OrderSend error with the 0 error code

Why it happens ?

See @Petr Nosek answer for your question.

As a side notes :

  • your error 130 processing can only fix the error by chance, it's not generic at all.
  • Your way to use NormalizeDouble() is not generic either.
  • Your RefreshRates() usage is useless.

There are a lot of topics on that on this forum if you want more information.

Reason: