A small, free MetaTrader 5 script with one job: run it once and it closes your open positions — on every symbol or only the chart symbol — and can delete your pending orders too. Then it stops. It never opens a trade.
Closes all open positions on the account, or only on the chart symbol (OnlyThisSymbol). Oldest positions are closed first, so hedging, netting and FIFO accounts are all handled.
Deletes pending orders as well, unless you switch DeletePending off.
Asks before it acts (ConfirmBeforeClose): a pop-up shows how many positions and orders will go. On a requote it tries again up to 3 times, then writes how many were closed and how many failed in the Experts log.
How to install
In MetaTrader 5 open File → Open Data Folder, then the folder MQL5\Scripts, and copy SpectarCloseAll.ex5 into it.
In the Navigator panel right-click Scripts → Refresh.
Drag SpectarCloseAll onto any chart and check the inputs. Make sure Algo Trading is switched on in the toolbar.
Click OK, then confirm with Yes in the pop-up. The result appears in the Experts tab.
What it does not do
It does not work in the MT5 mobile app. Scripts only run in the MetaTrader 5 terminal on Windows.
It does not guarantee the closing price. Each position is closed at market, so slippage, gaps, low liquidity or a closed market can make the result worse than the price you saw.
It does not run in the background or watch your account. It acts once, when you start it, and then stops.
Questions
Does it work on hedging, netting and FIFO accounts?
Yes. On hedging accounts every position is closed separately; on netting accounts there is one position per symbol. Positions are always closed oldest first, so accounts with a FIFO rule are respected.
Can it close only one symbol?
Yes. Set OnlyThisSymbol to true and it closes only positions (and, if DeletePending is on, pending orders) on the symbol of the chart you drop it on.
What happens if a close is rejected?
On a requote or a price change it tries again, up to 3 times per position. Anything it could not close is counted and shown in the Experts log, and a pop-up tells you to check it.
Want everything closed automatically at your daily limit?