No there is not there by default but you can write an EA to that for you
Ivarsen:
Quick question. I am trading with MT5, and i am looking for a way to close all open positions at once. Is this function in MT5?
I have looked everywhere in the platform and cant find it. If it isnt, why not? It really seems like this otion should be there as default.
Quick question. I am trading with MT5, and i am looking for a way to close all open positions at once. Is this function in MT5?
I have looked everywhere in the platform and cant find it. If it isnt, why not? It really seems like this otion should be there as default.
Maybe this can help you
https://www.mql5.com/en/code/25650

I have created a function for that. Hope this helps
void CloseThisSymbolAll() { int positions,orders; ulong inpMagic = 0; ulong ticket = PositionGetInteger(POSITION_TICKET); int orderType = (int)PositionGetInteger(POSITION_TYPE) ; int orderPendingType = (int)OrderGetInteger(ORDER_TYPE); string orderSymbol = PositionGetString(POSITION_SYMBOL); string orderPendingSymbol = OrderGetString(ORDER_SYMBOL); ulong orderPendingTicket = OrderGetInteger(ORDER_TICKET); ulong orderMagicNumber = PositionGetInteger(POSITION_MAGIC); ulong orderPendingMagicNumber = OrderGetInteger(ORDER_MAGIC); for(orders=OrdersTotal()-1, positions=PositionsTotal()-1; positions>=0 || orders>=0;positions--,orders--) { ulong numTicket = PositionGetTicket(positions); ulong numOrderTicket = OrderGetTicket(orders); if(orderType==POSITION_TYPE_BUY) { trade.PositionClose(numTicket); } if(orderType==POSITION_TYPE_SELL) { trade.PositionClose(numTicket); } if(orderPendingType==ORDER_TYPE_BUY_LIMIT || orderPendingType==ORDER_TYPE_SELL_LIMIT || orderPendingType==ORDER_TYPE_BUY_STOP||orderPendingType==ORDER_TYPE_SELL_STOP ||orderPendingType==ORDER_TYPE_BUY_STOP_LIMIT||orderPendingType==ORDER_TYPE_SELL_STOP_LIMIT) { trade.OrderDelete(numOrderTicket); } } }
-
ulong ticket = PositionGetInteger(POSITION_TICKET); int orderType = (int)PositionGetInteger(POSITION_TYPE) ; int orderPendingType = (int)OrderGetInteger(ORDER_TYPE); string orderSymbol = PositionGetString(POSITION_SYMBOL); string orderPendingSymbol = OrderGetString(ORDER_SYMBOL); ulong orderPendingTicket = OrderGetInteger(ORDER_TICKET); ulong orderMagicNumber = PositionGetInteger(POSITION_MAGIC); ulong orderPendingMagicNumber = OrderGetInteger(ORDER_MAGIC);
What position did you select before trying to read those? - Where are you using those variables?
-
for(orders=OrdersTotal()-1, positions=PositionsTotal()-1; positions>=0 || orders>=0;positions--,orders--) { ulong numTicket = PositionGetTicket(positions); ulong numOrderTicket = OrderGetTicket(orders);
What happens when positions or orders goes negative? Separate and simplify.

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
I have looked everywhere in the platform and cant find it. If it isnt, why not? It really seems like this otion should be there as default.