Dealing with OrderSend Error 136 Off Quotes

 

Hi All,

Lately my EA's have been running into the OrderSend error 136 a lot of the time. So I have placed my OrderSend code into a loop that repeatedly retries to send the order up to a maximum of X times until the order is filled. Problem is sometimes even after 10-15 attempts I still get the same error code! Could anyone please help me understand if this is a problem with my code or a problem with my broker?

1) I have included the code for the function I have written below - is there any issue with the code? (there are a lot of "RefreshRates()" in there as I'm not sure exactly where to do this and thought this could be the cause of the problem!)

2) Could you please explain exactly what the error code means? I assume it means the broker has rejected the order because the price has changed, but how can this happen 10-15 times in a row?

3) Does anyone else get this problem regularly? Is this normal or is my broker screwing me here?


My set up is that I run multiple EA's per terminal (max 19), across 8 terminals on a VPS. Just thought I would mention this in case this has any effect on the issue.

Thanks in advance

int OrderSendNew(string pair, int type, double lots, double price, int slippage, double sl, double tp, string comment, int magic, datetime expiry, color arrow, int OffQuotesRetries_)
{
   int ticket=0;
   int Retries=0;
   double execution_price=0;
   while(Retries < OffQuotesRetries_)
   { 
      if(type==OP_BUY) { RefreshRates(); execution_price=MarketInfo(Symbol(),MODE_ASK); } else if(type==OP_SELL) { RefreshRates(); execution_price=MarketInfo(Symbol(),MODE_BID);; }    
         ticket = OrderSend(pair,type,lots,execution_price,slippage,sl,tp,comment,magic,expiry,arrow);
         
         if(ticket>0) { if(Retries==0){Print("Order Opened First Attempt");} else Print("Order Opened, OrderSend Retries = ",Retries); Retries = OffQuotesRetries_; /*continue;*/ return(ticket); }
            else {
               Print("Order Send Failed, Retry #",Retries," error #",GetLastError());
               Retries++;
               Sleep(500);
               RefreshRates(); }
   }
Print("OrderSendNew Function Unable to Open Order, OrderSend Attempts = ",Retries);
return(ticket);
}
 
int OrderSendNew(string pair, int type, double lots, double price, int slippage, double sl, double tp, string comment,...)
{
   int ticket=0;
   int Retries=0;
   double execution_price=0;
   while(Retries < OffQuotesRetries_)
   { 
      if(type==OP_BUY) { RefreshRates(); execution_price=MarketInfo(Symbol(),MODE_ASK); } 
      else 
      if(type==OP_SELL) { RefreshRates(); execution_price=MarketInfo(Symbol(),MODE_BID);; }    
         ticket = OrderSend(pair,type,lots,execution_price,slippage,sl,tp,comment,magic,expiry,arrow);
     ...
         

If pair is different of chart symbol you have a wrong price.

All RefreshRates() are useless in your code.

 
Alain Verleyen:

If pair is different of chart symbol you have a wrong price.

All RefreshRates() are useless in your code.


Thanks :) Good spot, I have changed Symbol() to "pair" so it will work across pairs.

However at the moment I only open trades on the chart symbol so I don't think this is contributing to my error 136's.

int OrderSendNew(string pair, int type, double lots, double price, int slippage, double sl, double tp, string comment, int magic, datetime expiry, color arrow, int OffQuotesRetries_)
{
   int ticket=0;
   int Retries=0;
   double execution_price=0;
   while(Retries < OffQuotesRetries_)
   { 
      if(type==OP_BUY) { execution_price=MarketInfo(pair,MODE_ASK); } else if(type==OP_SELL) { execution_price=MarketInfo(pair,MODE_BID);; }    
         ticket = OrderSend(pair,type,lots,execution_price,slippage,sl,tp,comment,magic,expiry,arrow);
         
         if(ticket>0) { if(Retries==0){Print("Order Opened First Attempt");} else Print("Order Opened, OrderSend Retries = ",Retries); Retries = OffQuotesRetries_; /*continue;*/ return(ticket); }
            else {
               Print("Order Send Failed, Retry #",Retries," error #",GetLastError());
               Retries++;
               Sleep(500); }
   }
Print("OrderSendNew Function Unable to Open Order, OrderSend Attempts = ",Retries);
return(ticket);
}