Duplicate Trade Shield
- Utilities
-
AL MOOSAWI ABDULLAH JAFFER BAQER
To trade successfully we need to go through the proven path that others had gone and reached!
Here are 17 quotes from such successful investors:
1- Limit your size in any position so that fear does not become the prevailing instinct guiding your judgment.
Joe Vidich - Version: 1.0
- Activations: 5
STOPS DUPLICATE TRADES FROM COPIER GLITCHES, EA DOUBLE-SENDS AND RECONNECT RESENDS BEFORE THEY DOUBLE YOUR RISK.
Built for traders who run copiers, signal services or Expert Advisors. One job: one trade stays one trade. Mechanism: positions with the same symbol and direction, opened seconds apart with near-identical volume and price, are grouped into a cluster; the first one is kept, the newer copies are handled your way.
Try it free first: run Duplicate Trade Shield in the Strategy Tester with visual mode on. There it sends small demo orders in bursts of one, two and three identical trades on purpose, so you can watch each copy being found, grouped and handled within a second.
Who this is NOT for: traders who scale in on purpose with several equal positions seconds apart (use mode 0 or 3, or switch the time rule off), and netting accounts, where the broker merges every trade into one position and duplicates cannot exist.
In short
- Finds duplicate positions: same symbol, same direction, optionally the same magic, opened within N seconds of each other, and/or with near-identical volume and open price.
- The original (first) position of a cluster is never touched. Only the newer copies are handled.
- Four modes: 0 alert only, 1 close the newer duplicates, 2 close a newer duplicate only while its loss is smaller than your limit, 3 keep it, tag it on the panel and alert once.
- Optional cap: a maximum number of positions per symbol and direction; positions beyond it are handled by the same mode.
- Fresh-only safety: closes only duplicates younger than 10 minutes; older pairs found at start-up are alerted, never closed.
- A DOUBLED EXPOSURE row: the extra lots and margin the copies are holding, and their share of equity.
- Not a grid, no martingale, no averaging, no DLLs, no web requests, no extra files. It never opens a trade on a live account.
START HERE
Attach it to one chart, for example EURUSD H1. One copy watches every symbol of the account unless you limit it. Keep the defaults (10 seconds AND same volume within 1 percent AND open price within 30 points, same magic). Run mode 0 (alert only) for a few days next to your copier or EA. When every alert is a copy you would have closed yourself, switch to mode 2 and turn on Algo Trading.
Why duplicates happen, and why they hurt
A trade copier loses the connection for a moment and sends the last signal again. An Expert Advisor gets no reply in time and sends the same order a second time. A VPS restarts and an EA that keeps no memory opens its trade again. Each time the account ends up with two or three identical positions where the plan had one. Nothing looks wrong on the chart, but the risk is doubled or tripled: the stop loss that should cost 1 percent now costs 2 or 3. Most traders find the copy only when the loss arrives. The shield checks the book every second and on every trade event, so a copy is seen while it is still seconds old and usually still close to breakeven.
What happens to one duplicate
Found. A new position matches an older one on the same symbol and side: within the time window, and with the same volume and price inside your tolerances. Both are put in one cluster. The older one is marked ORIGINAL, the new one DUPLICATE, with the gap in seconds since the original.
Handled. Mode 1 closes the copy at once. Mode 2 closes it only while its loss is smaller than your limit (5 by default); if the market has already moved far against it, it is KEPT BIG LOSS and you get one message, and it is closed later if the loss shrinks under the limit. Mode 0 sends one alert per copy. Mode 3 keeps the copy, shows it as TAGGED and alerts once.
Remembered. The "already alerted" mark is kept per position in a GlobalVariable whose key contains the chart symbol and the magic filter, so a restart does not repeat alerts and two copies of the shield on different charts never share a key.
The duplicate rule in detail
Time window: the open times are compared to the millisecond. Volume: equal within the percent tolerance, and half a lot step is always allowed. Price: the open prices may differ by up to the tolerance in points. The match rule decides how these are combined: time only, time AND similar volume and price (the default and the safest), or time OR similar. With OR, two identical positions opened hours apart also count as duplicates, which suits copiers that resend old signals after a reconnect. A cluster can hold more than two positions: the third and fourth copies of a burst join the same cluster.
What is new compared with our earlier guards
Fresh-only close: in modes 1 and 2 only a copy younger than InpCloseFreshSec (600 seconds) is closed. If you attach the shield to an account that already holds two old equal positions you placed on purpose, they are alerted once (OLD - ALERT) and left alone. The DOUBLED EXPOSURE row and the DUPLICATE LOAD bar show how many extra lots and how much margin the copies hold, so you see the size of the problem, not only its count.
Inputs, every one explained
DUPLICATE RULE
InpWindowSec = 10. Maximum seconds between two opens to count as a possible duplicate. 0 turns the time rule off (allowed only with the OR rule or a cap).
InpMatchRule = time AND similar. Time only, time AND near-identical volume/price, or time OR near-identical volume/price.
InpUseVolume = true. Compare volumes. InpVolTolPct = 1.0: allowed difference in percent.
InpUsePrice = true. Compare open prices. InpPriceTolPoints = 30: allowed difference in points.
InpSameMagic = true. Duplicates must carry the same magic number. Set false to also catch a manual trade copied by an EA.
ACTION
InpMode = 2. 0 alert only, 1 close the newer duplicates, 2 close a newer duplicate only if its loss is smaller than InpMaxLossMoney (a copy in profit is closed too), 3 keep and tag.
InpMaxLossMoney = 5. Mode 2 only: the loss in account currency that is still small enough to close.
InpCloseFreshSec = 600. Modes 1 and 2 close only copies younger than this; older ones are alerted once. 0 turns this safety off.
InpMaxPerSide = 0. Cap on positions per symbol and direction (with the same magic when InpSameMagic is on). 0 is off. The newest positions beyond the cap are handled by the mode, shown as OVER CAP.
EXECUTION
InpSlippagePoints = 30. Maximum slippage accepted on a close.
InpFailAlertAt = 3. A refused close is retried with a growing pause, up to two minutes. After this many failures on one position you get one alert. If the broker refuses the filling mode, the next allowed one is tried at once. Before every send the position is selected again and its symbol and magic are checked again.
FILTER - WHICH POSITIONS ARE CHECKED
InpSymbolScope = All symbols, or the chart symbol only. InpMagicFilter = Any magic, only manual trades (magic 0), or only the magic number InpMagic.
ALERTS
InpAlertPopup = true. Pop-up alert. InpAlertPush = false. Push notification to the MetaTrader app on your phone (enable it in the terminal options).
PANEL
ShowPanel = true. PanelX = 12, PanelY = 15: offset from the top left corner; the MOVE button drags it. PanelFontSize = 9. MaxTableRows = 6, MaxHistoryRows = 4. On a short chart the panel drops its least important rows first.
STRATEGY TESTER DEMO
InpTesterDemo = true. In the Strategy Tester only: twice a weekday a burst of one, two or three identical orders on the chart symbol (up to 0.1 lot, margin checked times 1.5 before every order, at most 8 open, closed after 2 days, stopped after a 20 percent balance loss). This code never runs on a live or demo chart.
The panel
DUPLICATE LOAD shows the share of lots in scope that are copies. SHIELD PLAN lists duplicates and clusters, doubled exposure, the last action, the mode, Algo Trading on or off, your match rule, the cap, the loss limit and fresh-only seconds, failed sends, totals and positions in scope. DUPLICATE CLUSTERS, ORIGINAL FIRST shows each cluster with symbol, side, lots, gap after the original, profit, state and a closeness bar (how close in time the copy came). States: ORIGINAL, DUPLICATE, OVER CAP, ALERTED, TAGGED, KEPT BIG LOSS, OLD - ALERT, MARKET SHUT, TRADE OFF and RETRY. ACTION HISTORY keeps every alert, close and tag with server time. QUICK CONTROLS: ARMED or PAUSED, a mode button that cycles the four modes, and RESCAN NOW. The right side of the chart stays clear.
What it cannot do
It cannot read intent. Two equal positions opened seconds apart on purpose look exactly like a copier glitch. Use the magic filter, mode 0 or 3, or a shorter window if you scale in this way.
It acts after the copy exists. A close books the copy's current result and pays spread and commission; it does not stop the copier or EA from sending. Fix the source too.
It only works while it runs: with the terminal off, Algo Trading off, the market closed or a disabled symbol nothing is sent, and it acts on the next pass. Keep the terminal running, for example on a VPS. History and totals reset on restart.
What was and was not tested
Tested in the Strategy Tester on a hedging account, 1 to 30 June 2026, H1, 1-minute OHLC, deposit 10000, leverage 100, four runs. EURUSD mode 2: 63 bursts, 126 demo orders, 63 duplicates found and 63 closed. EURUSD mode 0: 47 duplicates, 47 alerts, nothing changed. EURUSD mode 1 with a cap of 2: 79 found (duplicates plus over-cap), 79 closed. XAUUSD mode 3 with a cap of 3: 15 found and tagged, nothing closed. No send failed and no journal error appeared. On a live demo chart the panel ran in alert-only mode with a cap of 1 and showed one position over the cap without changing anything.
Not tested at the time of writing: a real close on a live or demo broker, a netting account, retries after a broker refusal, a filling mode refusal, the OR rule, chart symbol scope, magic filters, pop-up and push alerts, and the panel buttons. These paths exist in the code and are described by design. Please try them on a demo account with your own broker first.
Try it in the Strategy Tester
Choose Duplicate Trade Shield, EURUSD or XAUUSD, H1, a deposit of a few thousand, visual mode, and press Start. Switch the modes and watch the bursts of identical orders reduced to one.
If the shield caught a copy you would have missed, or you think it should handle a case differently, an honest review on the product page helps other traders decide and tells me what to improve next.
