How work with requotes?

 
Hi!! Maybe you can help me.
I'm writting my own EA. All seems ok in backtest but when I run it in forward I get some errors because of requotes. Curiously I've got this errors 3 times and the 3 times has been on GBPUSD (I'm testing the EA in 20 pairs). I've coded a maximum slippage of 10. I get this errors even when the requote is less than 5, so I don´t understand.

Here is the error message:
2008.03.05 08:15:12 EA1 GBPUSD,M15: Error opening SELL order! invalid price

And the requote message: 2008.03.05 08:15:11
'5267460': requote 1.9803 / 1.9807 for open sell 0.10 GBPUSD at 1.9807 sl: 1.9957 tp: 1.9357 2008.03.05 08:15:11
'5267460': request was accepted by server 2008.03.05 08:15:11 '5267460': instant order sell 0.10 GBPUSD at 1.9807 sl: 1.9957 tp: 1.9357

So if the requote is 1.9803/1.9807 and the is trying open an order at 1.9807 and a slippage of 10 pips is accepted, why this error?

Finally the piece of the code for open position:
void BuscarAbrir() { int Slippage=10; int MagicNumber; string symbolo=Symbol(); if (symbolo=="GBPUSD"){MagicNumber=185258471411;} if (symbolo=="EURUSD"){MagicNumber=458555788512;} if (symbolo=="NZDUSD"){MagicNumber=129999996613;} if (symbolo=="USDCAD"){MagicNumber=123456741814;} if (symbolo=="USDCHF"){MagicNumber=111112225415;} if (symbolo=="EURCHF"){MagicNumber=128588888216;} if (symbolo=="EURJPY"){MagicNumber=745698523657;} if (symbolo=="GBPJPY"){MagicNumber=555555555228;} . . . if (anterior && (comentar != -1)) { if (Kumo == 1) Print("SELL signal"); enviar = "SELL signal"; int ticket = 0; Arko = 0; while ((ticket <= 0) && (Arko < Number)) { while (!IsTradeAllowed()) Sleep(5000); ticket = OrderSend(Symbol(),OP_SELL,LotsRisk(StopLoss),Bid, Slippage,Bid + StopLoss * Point,Bid - TakeProfit * Point,Version,MagicNumber,0,Red); if (ticket < 0) { Print("Error opening SELL order! ",ErrorDescription(GetLastError())); var_116 = "Error opening SELL order! " + ErrorDescription(GetLastError()); Arko++; } } comentar = -1; } else { if (posterior && (comentar != 1)) { if (Kumo == 1) Print("BUY signal"); enviar = "BUY signal"; ticket = 0; Arko = 0; while ((ticket <= 0) && (Arko < Number)) { while (!IsTradeAllowed()) Sleep(5000); ticket = OrderSend(Symbol(),OP_BUY,LotsRisk(StopLoss),Ask,S lippage,Ask - StopLoss * Point,Ask + TakeProfit * Point,Version,MagicNumber,0,Blue); if (ticket < 0) { Print("Error opening BUY order! ",ErrorDescription(GetLastError())); var_116 = "Error opening BUY order! " + ErrorDescription(GetLastError()); Arko++; } } comentar = 1; } } }

Thanks for your help and sorry if my english is no very good.
 

Well, I've been reading about invalid price error, but I don´t know what is the problem of my code.

" At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a security differing from the current one, the MarketInfo() function must be used with MODE_BID or MODE_ASK parameter for the latest quotes for this security to be obtained. Calculated or unnormalized price cannot be applied. If there has not been the requested open price in the price thread or it has not been normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE) will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE) will be generated independently on the slippage parameter. If the requested price is out of date, but present in the thread, the position will be opened at the current price and only if the current price lies within the range of price+-slippage."

 

There is no RefreshRates() in your loop... So your prices can become old. This might help. If not, contact your Dealer.

ERR_REQUOTE 138 The requested price has become out of date or bid and ask prices have been mixed up. The data can be refreshed without any delay using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

void BuscarAbrir() { 
 int Slippage=10; 
 int MagicNumber; 
 string symbolo=Symbol(); 
 if (symbolo=="GBPUSD"){
  MagicNumber=185258471411;
 } 
 if (symbolo=="EURUSD"){MagicNumber=458555788512;} 
 if (symbolo=="NZDUSD"){MagicNumber=129999996613;} 
 if (symbolo=="USDCAD"){MagicNumber=123456741814;} 
 if (symbolo=="USDCHF"){MagicNumber=111112225415;} 
 if (symbolo=="EURCHF"){MagicNumber=128588888216;} 
 if (symbolo=="EURJPY"){MagicNumber=745698523657;} 
 if (symbolo=="GBPJPY"){MagicNumber=555555555228;} . . . 
 if (anterior && (comentar != -1)) { 
  if (Kumo == 1) Print("SELL signal"); 
  enviar = "SELL signal"; 
  int ticket = 0;   Arko = 0; 
  while ((ticket <= 0) && (Arko < Number)) { 
   while (!IsTradeAllowed()) Sleep(5000); 
   RefreshRates();
   ticket = OrderSend(Symbol(),OP_SELL,LotsRisk(StopLoss),Bid, Slippage,Bid + StopLoss * Point,Bid - TakeProfit * Point,Version,MagicNumber,0,Red); 
   if (ticket < 0) { 
    Print("Error opening SELL order! ",ErrorDescription(GetLastError())); 
    var_116 = "Error opening SELL order! " + ErrorDescription(GetLastError()); 
    Arko++; 
   } 
  } 
  comentar = -1; 
 } 
 else { 
  if (posterior && (comentar != 1)) { 
   if (Kumo == 1) Print("BUY signal"); 
   enviar = "BUY signal";
   ticket = 0; Arko = 0;
   while ((ticket <= 0) && (Arko < Number)) { 
    while (!IsTradeAllowed()) Sleep(5000);
    RefreshRates();     
    ticket = OrderSend(Symbol(),OP_BUY,LotsRisk(StopLoss),Ask,S lippage,Ask - StopLoss * Point,Ask + TakeProfit * Point,Version,MagicNumber,0,Blue); 
    if (ticket < 0) { 
     Print("Error opening BUY order! ",ErrorDescription(GetLastError())); 
     var_116 = "Error opening BUY order! " + ErrorDescription(GetLastError()); 
     Arko++; 
    } 
   } 
   comentar = 1;
  } 
 } 
}
 
Thanks for your help.
I will try with RefreshRates().
Is the error 129 (invlaid price) and 138 (requote) walking together?
 
Great!!
RefreshRates() seems works very fine!! There is no problem at all now, even with requote!!
Thanks again.

Forex
 

I've been working fne for a while with the above suggestion but I missed two trades in this week.

I get the error: Trade not allowed or trade context is busy. I thought my code was ready to work with this.

If trade is not allowed the EA go to sleep for 5000, maybe this sleeping time is too high (the EA works on M15 chart and take signals for the close of previous bar, so the EA has 15 minutes for send an order)???? Maybe there is no way to catch all trades???

I really don´t like when I miss trades.

Any new suggestion??


void BuscarAbrir()
{
if (var_752 && (var_764 != -1))
   {
   if (Kumo == 1) Print("SELL signal");
   int ticket = 0;
   Arko = 0;
   while ((ticket <= 0) && (Arko < Number))//Number is 20
      {
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      ticket = OrderSend(Symbol(),OP_SELL,LotsRisk(StopLoss),Bid,Slippage,Bid + StopLoss * Point,Bid - TakeProfit * Point,Version,MagicNumber,0,Red);
      if (ticket < 0)
         {
         Print("Error opening SELL order! ",ErrorDescription(GetLastError()));
         Arko++;
         }
      }
   var_764 = -1;
   }
      else
   {
   if (var_748 && (var_764 != 1))
      {
      if (Kumo == 1) Print("BUY signal");
      ticket = 0;
      Arko = 0;
      while ((ticket <= 0) && (Arko < Number))//Number is 20
         {
         while (!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         ticket = OrderSend(Symbol(),OP_BUY,LotsRisk(StopLoss),Ask,Slippage,Ask - StopLoss * Point,Ask + TakeProfit * Point,Version,MagicNumber,0,Blue);
         if (ticket < 0)
            {
            Print("Error opening BUY order! ",ErrorDescription(GetLastError()));
            Arko++;
            }
         }
      var_764 = 1;
      }
   }
}
Reason: