problema cerrando trade (supuestamente problema 129)

 
¿Alguien sabrá por qué, usando la función "Alert" en el siguiente código, me dice en el mensaje: "error cerrando corta: 129", siendo que el precio al cerrar es "Bid", el cual ya está normalizado? (lo he probado en dos cuentas demo, por si el problema estaba en la plataforma):


void OnTick()
 {

double SMA7Previous, SMA9Previous, SL, TP, SalidaReal, OpenPrice;
int Period_Mayor, cnt, ticket, Total;
Period_Mayor=9;
SMA7Previous=iMA(NULL,PERIOD_M15,7,0,MODE_SMA,PRICE_CLOSE,1);  
SMA9Previous=iMA(NULL,PERIOD_M15,Period_Mayor,0,MODE_SMA,PRICE_CLOSE,1);
SL = 0.00100;
TP = 0.00100; 
SalidaReal=0.00060;
Total=OrdersTotal();
//---
if(Bars<50)
   {
   Print("bars less than 100");
   return;
   }

   

if(Total==0)
   {
   if(SMA7Previous>SMA9Previous)
      {
      RefreshRates();
      ticket = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 3, Ask-SL, Ask+TP, "FT_SMA_BUY", 12345, 0, Green);       
      if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
         { 
         OpenPrice=OrderOpenPrice();
         Print("Posición larga abierta con éxito: ", ticket); 
         } 
      else 
         { 
         Alert("Error abriendo larga:", GetLastError());          
         }      
      }
   
   if(SMA7Previous<SMA9Previous)
      {   
      RefreshRates();
      ticket = OrderSend(Symbol(), OP_SELL, 0.01, Bid, 3, Bid+SL, Bid-TP, "FT_SMA_SELL", 23456, 0, Red);         
      if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
         { 
         OpenPrice=OrderOpenPrice();
         Print("Posición cortaabierta con éxito: ", ticket);      
         } 
      else 
         { 
         Alert("Error abriendo corta:", GetLastError());           
         }   
      }
   
   }    

for(cnt=0;cnt<Total;cnt++)
   {
   if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
      {   
      continue;
      }
   
   if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
      {
      double WinLargo= Ask-OpenPrice;
      double LossLargo=OpenPrice-Ask;         
      if(SMA7Previous<SMA9Previous || WinLargo>SalidaReal || LossLargo>SalidaReal)
         {
         RefreshRates();
         if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE))
            {   
            Alert("Error cerrando largo",GetLastError());      
            }
         } 
      }
   if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
      {
      double WinCorto= OpenPrice-Bid;
      double LossCorto=Bid-OpenPrice; 
      if(SMA7Previous>SMA9Previous || WinCorto>SalidaReal || LossCorto>SalidaReal)   
         {
         RefreshRates();
         if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE))
            {   
            Alert("Error cerrando corta",GetLastError());      
            }                         
         }
      }      
   }  
}
//+------------------------------------------------------------------+

 

Hay mucho escrito sobre el error 129 en el foro.

https://www.mql5.com/en/forum/151147

MQL4: Error 129 on OrderSend and OrderClose - I'm trying to find out what it's wrong when I am trying to close an order with the Bid or Ask of a different one
MQL4: Error 129 on OrderSend and OrderClose - I'm trying to find out what it's wrong when I am trying to close an order with the Bid or Ask of a different one
  • 2014.04.17
  • www.mql5.com
With pending orders it's all right but when i search to insert a market order or close one of it i'll frequently recive error 129 (invalid price) i read on the online documentation that kind of error can happen 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. If not, you are trying to close a trade of one symbol with the bid or ask of a different one