Loading…

Close All On Current Symbol

A flatten-everything script is the wrong tool most of the time. Usually one instrument has gone wrong - a news spike, a spread blowout, a correlation you misjudged - and the rest of the book is fine and should stay open. This closes the chart's symbol and nothing else. The detail that makes this worth downloading is the symbol comparison. Brokers publish the same underlying under several names: EURUSD, EURUSD.m, EURUSDpro, EURUSD_raw, EURUSD.ecn. They are different contracts with different spreads, different swap rates and sometimes different contract sizes. Several published scripts compare with StringFind or a prefix match, which quietly closes positions on a contract you did not name. This script compares the exact string the terminal gives it, so what you see on the chart is precisely what gets closed. Tickets are collected into a list before anything is closed. The pool re-indexes the moment an entry leaves it, so closing while iterating by index silently skips roughly half the book. This is the single most common bug in scripts of this kind and it is invisible until the day it matters. The confirmation prompt shows the numbers that actually help you decide: how many positions, how much is long, how much is short, and the running result. "Close 4 positions on EURUSD.m? 0.30 long, 0.10 short" tells you at a glance whether you are flattening a hedge or a directional bet. Failures are retried only when the error deserves it. A requote, an off-quote, a busy trade context or a dropped connection are temporary and worth another attempt. An invalid volume or a disabled account is permanent, and retrying it just burns time. Notes and limitations - Market positions only. Pending orders on the symbol are not deleted, because cancelling an unfilled order is a different intention from closing a live position. - Exact symbol matching cuts both ways. If you keep two contracts of the same underlying open - EURUSD and EURUSD.m - you must run the script once from each chart. That is the intended behaviour, not an oversight. - A position that hits its own stop or target mid-run is counted as a success. - The MQL4 trade context is shared across the terminal. If an EA is mid-order the script waits rather than failing, which can add a short delay. - Nothing here can close a position while that market is shut. Those are reported as failures with the reason given. - An EA still attached to the chart will happily open a new position seconds later. Detach it first if you want the symbol to stay flat.

Script · MT4 · v1.0 · Free

About Close All On Current Symbol

Close All On Current Symbol is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Magic filter, Slippage pips and Max retries. MQL source code included.

Files in the download: CloseAllOnSymbol.ex4, CloseAllOnSymbol.mq4, CloseAllOnSymbol.txt.

Settings

SettingDefaultWhat it does
Magic filter-1Magic number (-1 closes every magic)
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per order before giving up
Retry wait ms500Pause between attempts, milliseconds
Confirm firsttrueAsk for confirmation before closing

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: News Trading · EURUSD · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria