See article Error 146 ("Trade context busy") and How to Deal with It and reflect on.
GG
Do something like this - just an idea..
In summary, you need to handle certain possible errors and get the latest prices.
Worst thing about yours is that if n orders goes off one tick, the Bid will have moved on at the brokers server when you will still be sending the Bid from that earlier tick..
So always do a RefreshRates() before calling this and sending the latest Bid/Ask
int OpenAtMarket (string strPair, int iOrderType, double dLots, double dPrice, int iSlippage, double dSL, double dTP, string strOrderComment, int iMagicNumber, datetime dtExpiry, color cColour, int iNR, int iMTS) { int iMaxNumRetries, iNumRetries=iNR; // is server or context busy - try n times to submit the order iNumRetries=iNR; while(iNumRetries>0) { int iTicket = OrderSend(strPair, iOrderType, dLots, dPrice, iSlippage, dSL, dTP, strOrderComment, iMagicNumber, dtExpiry, cColour); iNumRetries--; if(iTicket == -1 ) { int iError = GetLastError(); // retry if error is "busy", otherwise give up if( iError==4 || iError==146 || iError==137 || iError==6 || iError==128) //ERR_SERVER_BUSY, ERR_TRADE_CONTEXT_BUSY, ERR_BROKER_BUSY, ERR_NO_CONNECTION, ERR_TRADE_TIMEOUT Sleep(iMTS); else { iNumRetries = 0; Print("OpenAtMarket: OrderSend Error ", GetLastError() ); } } else iNumRetries = 0; } return(iTicket); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi!
I'd like to make multiple ordersend simultaneously (one tick).
Here is my code:
I get only one trade. Why?
How can I do it well?
Thanks