Refreshed Rates and Looped Trying But Still OrderSend error 129

 

I am consistently getting an OrderSend error 129 for invalid price on my EA. The same EA is running on several pairs, for most of them it works fine, but there a few pairs that consistently get errors when trying to open a trade. I am refreshing the rates before sending the order, and if the order fails it loops to keep trying. It shouldn't be a connectivity issue since at the same time it's opening trades for other pairs. Even while it's going through the loop of trying to open a trade and getting errors, i can open the trade manually with no issues. I'm lost for an explantion. It should also be noted that before getting the error #129, it was getting an error 130, invalid stop loss / take profit, so I changed the code to open without a stop loss / take profit, then modify the order after to add them.


RefreshRates();
 
double ask = MarketInfo(Symbol(),MODE_ASK);
             
ticket = OrderSend(Symbol(),OP_BUY,lots,ask,500,0,0,Symbol(),0,0,clrNONE);
while(ticket<0){
   RefreshRates();
   ask = MarketInfo(Symbol(),MODE_ASK);
   ticket = OrderSend(Symbol(),OP_BUY,lots,ask,500,0,0,Symbol(),0,0,clrNONE);
   Print("OrderSend failed, will try again, error #",GetLastError());
}
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Invalid lots. Min/Max/multiple of LotStep.
 
The lots are 0.01, same for the working pairs as well, but I guess it could be giving a 129 error for a different issue besides invalid price right, so i may just need to look at other issues that may be happening?
 
Drew Clayman:
The lots are 0.01, same for the working pairs as well, but I guess it could be giving a 129 error for a different issue besides invalid price right, so i may just need to look at other issues that may be happening?

I don't see why. If it is a different issue it should have a different code.

But I don't see why you are getting an invalid price based on the code.

Note:

   ticket = OrderSend(Symbol(),OP_BUY,lots,ask,500,0,0,Symbol(),0,0,clrNONE);
   Print("OrderSend failed, will try again, error #",GetLastError());

You are printing the error report even if the OrderSend succeeds!

Should be

   ticket = OrderSend(Symbol(),OP_BUY,lots,ask,500,0,0,Symbol(),0,0,clrNONE);
   if(ticket==-1)
     Print("OrderSend failed, will try again, error #",GetLastError());

Also, in your print you should print relevant information like the current Ask price and the order entry price.

Lastly, the code that you have posted IS the exact code that you are using, is it? I don't know why, but people sometimes post different code to where they are getting the issue.

Reason: