Loading…

Magic Number Collision Checker

An expert that closes or modifies "its own" trades almost always does it by filtering on a magic number. That works perfectly until a second expert, on the same symbol, happens to use the same magic number - by a default value nobody changed, a copy-pasted template, or plain coincidence. From that moment, each expert's filter loop also matches the other one's trades, and one expert can close or modify a position it does not actually own. There is no reliable way to ask either platform which expert owns a given order or position; the data carries a magic number and a free-text comment, nothing more. This script uses exactly that: it groups every currently open position and pending order by (symbol, magic number), and within each group checks whether the comments agree. A group whose tickets carry two or more different comment strings under the same magic number is reported as a likely collision. A group that shares one comment, or has none at all, is reported as unverifiable rather than declared safe - the absence of a disagreeing comment is not proof the tickets share one owner, only the absence of the one signal this script can check. Every flagged group is printed with its full ticket list, type and comment, so the actual review - which expert really placed which ticket - can be done by a human who knows what is running on that account. Notes and limitations - This checks positions and orders that exist right now. It cannot see an expert's magic number input directly, and it cannot detect a collision between two experts if neither currently has an open position or pending order on that symbol. - "Likely collision" means the comments disagree, which is strong evidence but not proof - some experts deliberately vary their own comment text per trade. - "Unverifiable" is the more common and more cautious result: many well-behaved single-purpose experts never set a comment at all, so an empty-comment group sharing a magic number is not automatically two experts colliding, it is simply a case this script cannot rule either way. - On a netting account, a magic-number collision between two experts' open positions cannot physically occur under MQL5's own position model - see the differences section above. Pending orders are still checked normally.

Script · MT5 · v1.0 · Free

About Magic Number Collision Checker

Magic Number Collision Checker is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Ignore magic zero and Alert on finding. MQL source code included.

Files in the download: MagicNumberCollisionChecker.ex5, MagicNumberCollisionChecker.mq5, MagicNumberCollisionChecker.txt.

Settings

SettingDefaultWhat it does
Ignore magic zerotrueSkip magic number 0 (usually manual trades)
Alert on findingtrueAlert when a likely collision is found

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Buy/Sell Arrows · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria