If the server is busy processing numerous trades whether that be market orders or pending orders, how do I keep retrying until the OrderSend is successful?
There was guidance in the old documentation about what you are meant to do in response to errors . . . in their wisdom Metaquotes removed it when they updated the Documentation.
Have a read: https://www.mql5.com/en/forum/150158
Nice one thanks.
I tried using the code above to place trades and it just spat out 3 of the 4 and returned that error.
So how do I:
ERR_TOO_MANY_REQUESTS | 141 | Too many requests. The frequency of requesting must be reduced, the program logic must be changed. |
if( OpenOrdersThisPair(Symbol()) == 0 && LotSize_Buy >= minlot ) { BuyTicketOrder1 = OrderSend(Symbol(),OP_BUY,LotSize_Buy,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates();Sleep(500); if( OrderSelect(BuyTicketOrder1,SELECT_BY_TICKET)==true){ if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) bool ModifyBuy1 = OrderModify(BuyTicketOrder1,OrderOpenPrice(),BuyStopPrice,btp1,0,clrNONE);} BuyTicketOrder2 = OrderSend(Symbol(),OP_BUY,LotSize_Buy2,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates();Sleep(500); if( OrderSelect(BuyTicketOrder2,SELECT_BY_TICKET)==true){ if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) bool ModifyBuy2 = OrderModify(BuyTicketOrder2,OrderOpenPrice(),BuyStopPrice,btp2,0,clrNONE);} ...
Correct?
Spot on honest knave, really appreciate it!
Reading them now! Will post back the changes, thanks :)
int _IsTradeAllowed(int MaxWaiting_sec = 30) { // check whether the trade context is free if(!IsTradeAllowed()) { uint StartWaitingTime = GetTickCount(); Print("Trade context is busy! Wait until it is free..."); // infinite loop while(true) { // if the expert was terminated by the user, stop operation if(IsStopped()) { Print("The expert was terminated by the user!"); return(-1); } // if the waiting time exceeds the time specified in the // MaxWaiting_sec variable, stop operation, as well if(GetTickCount() - StartWaitingTime > MaxWaiting_sec * 1000) // "sign mismatch" { Print("The waiting limit exceeded (" ,MaxWaiting_sec, " сек.)!"); return(-2); } ...
As GetTickCount() is not an accurate representation of time, how would I go about actually making sure a specific number of seconds has passed as a replacement if this highlighted if statement?
"Tick" is a misnomer... what GetTickCount actually records is the number of milliseconds since system start.
It does get filled up after ~50 days if the system isn't restarted.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In relation to previous thread, this is what i was concerned about using Market Orders over pending orders...