- RefreshRates before the OrderSelect, then no need for price=Bid/Ask just use OrderClosePrice in the OrderClose.
- Check your return codes (OrderSelect and OrderClose) and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- No slippage allowed, lots of requotes. See #2
Thank you WHRoeder, I will do it and let you know!
int CloseAllSymb() { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; if (OrderSymbol()==Symbol()){ switch(type) { case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE ); break; case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE ); break; case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : result = OrderDelete( OrderTicket() ); } } } return(0); }
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
Good morning,
I wrote this function to close open orders of specific symbol but, when testing, it seems not working properly. Could you give it a look and tell me if is there something wrong?
Thank you very much