Spec Match Trade Copier MT5

  • 实用工具
  • Quoc Dat Quach
    Quoc Dat Quach
    Software engineer with 8 years in fintech and mobile, writing MQL4/MQL5 since 2017. I build Expert Advisors, indicators, trade and risk-management panels and utilities for MT4/MT5, and I trade forex and gold on MT5 myself.
  • 版本: 1.1
  • 更新: 30 九月 2026
  • 激活: 10

A local trade copier for MetaTrader 5. It copies positions between MT5 terminals on the same Windows PC or VPS and sizes each copy from both brokers' contract specifications (contract size, tick value, account currency), so a copy carries the same exposure even when the two brokers define a lot differently. It never opens a second copy of the same master position.

What it does

You attach the same EA to one chart in each terminal:

  • In the master terminal, set the Mode input to Master.
  • In each receiver terminal, set the Mode input to Receiver.

The master writes its open positions, their symbol specifications and a heartbeat to a file in the shared Common\Files folder. Each receiver reads that file every 100 ms and brings its own positions in line with the master:

  • opens new positions
  • changes stop loss and take profit
  • partially closes
  • closes

There is no server, no network connection, no DLL and no WebRequest.

Lot size that follows the contract, not the lot number

Brokers define "1 lot" differently. Gold can be 100 oz, 10 oz or 1 oz per lot. Indices can be 1, 10 or 25 units per point. A cent account shows 100 times the money. A copier that copies the lot number can open 100 times too much or too little.

This copier measures what one lot is worth on each side. It uses OrderCalcProfit, which is the broker's own profit calculation, in account currency. It then converts the master's value into the receiver's account currency. The tick value is checked as well, and the panel shows a warning when the two disagree.

One master position gives at most one copy

The receiver keeps a copy map on disk, one line per master position:

  • Every copy carries the comment SMC:<master position id>.
  • A request is written to the map before it is sent, so a crash or restart in the middle of a trade cannot lead to a second copy.
  • After a restart, and after you change the inputs or the chart timeframe, the receiver reloads the map. Changing inputs with copies open was tested live on hedging and netting receivers: no extra deals.
  • If the map file is lost on a hedging receiver, the receiver rebuilds the map from the position comments.
  • A netting receiver cannot rebuild a lost map, because one net position cannot be split back into master positions. It puts each symbol that has a copy open on NET_HOLD instead (see "When the copier stops or holds" below).

When something does not add up, the receiver stops copying and raises an alert. It never guesses. Examples:

  • two receiver positions carry the same master id
  • a copied position has no id in its comment
  • the master account changes
  • the account margin mode changes
  • the map file is damaged
  • the net volume of a netting account was changed by hand

The panel shows how many duplicates were blocked.

Copied positions are closed only on the master's instruction

The master publishes a close record for every position it closes, taken from its deal history. The receiver closes a copy only when it sees that record. A position can also disappear from the master file without a record, for example because the file was damaged or history was not loaded. In that case the copy is put on HOLD and you get an alert. It is not closed.

The receiver pauses when any of these happen, and your positions stay as they are:

  • the master terminal is stopped
  • the master terminal is killed
  • the master terminal loses its connection
  • the master file stops updating (heartbeat timeout, default 3 s)

Monitoring

The status panel sits on the receiver chart. It shows:

  • master state (ALIVE / SILENT / NOT CONNECTED)
  • number of active, closed, refused, held and filtered copies
  • total exposure of the master versus the receiver, in account currency, with the difference in %
  • counts of opens, closes, partial closes, SL/TP changes and blocked duplicates
  • the last action, the last error and warnings
  • one row per copied position, up to 10 rows, then a "... N more" line

Every action is also written to a CSV journal in Common\Files\SpecMatchCopier.

When the copier stops or holds

The copier never repairs an inconsistency by guessing. You fix the cause, then restart it.

Panel shows What it means What to do
COPYING STOPPED The receiver found something it cannot explain: two positions for one master id, a position with the copier's magic but no id, a changed master account or margin mode, or a damaged map file. The reason is on the panel and in the journal. Nothing is copied until the EA is restarted. Fix the cause the message names, then remove the EA from the chart and attach it again. If the cause is still there, it stops again.
COPYING STOPPED: master account changed The channel now carries another master account. If the switch is intended: remove the EA, close the copies of the old master by hand, delete map_<login>_<magic>.txt in Common\Files\SpecMatchCopier (login and magic of this receiver), and attach the EA again.
COPYING STOPPED: map file is damaged The copy map failed its checksum. Hedging: delete the map file and attach the EA again, and the map is rebuilt from the comments. Netting: see NET_HOLD.
NET_HOLD (netting receiver) The net volume of a symbol differs from what the copier opened, for example after a manual trade or a lost map. That symbol is not traded any more. The hold is saved in the map, so a restart does not clear it. Remove the EA. Close the copier's positions by hand. Delete map_<login>_<magic>.txt. Attach the EA again. It then copies master positions opened after that.
HOLD on one row One copy is in doubt. For example, a master position vanished without a close record. Or a trade request was not confirmed, for example because the connection dropped, and no position appeared within 15 seconds. If the position appears later, it is attached to the held row with an alert, and nothing is sent twice. A held copy stays open, even when the master has closed its position. Close or keep the copy by hand. The copier does not touch a held copy again.

Lot modes

Mode Receiver volume Contract-aware
Same exposure (default) master volume x (value of 1 master lot / value of 1 receiver lot) x multiplier yes
Balance ratio same exposure x (receiver balance / master balance) yes
Equity ratio same exposure x (receiver equity / master equity) yes
Master lot x multiplier master volume x multiplier. A warning is shown when the contracts differ no
Fixed lot the fixed lot, for every copy no

In every mode the volume is then:

  • rounded to the receiver's volume step (nearest or down)
  • capped by the optional Max lot and by the broker maximum
  • skipped, or raised to the minimum, when it is below the broker minimum (your choice)
  • checked with OrderCalcMargin against free margin before sending

A copy is refused when one lot on one side is worth more than 1000 times one lot on the other side. This limit can be changed. It usually means a wrong symbol mapping.

Worked example: gold, 100 oz per lot to 1 oz per lot

Master (broker A) Receiver (broker B)
Symbol XAUUSD XAUUSD.cs (matched automatically)
Contract size 100 oz 1 oz
Account USD USD
Gold price 4,178.13 4,178.13
Value of 1 lot 100 x 4,178.13 = 417,813 USD 1 x 4,178.13 = 4,178.13 USD

The master opens 0.10 lot, which is 10 oz, worth 41,781 USD.

  • Same exposure: 0.10 x 417,813 / 4,178.13 = 10.00 lots on the receiver, which is 10 oz, worth 41,781 USD. A copier that copies the lot number would open 0.10 lot = 0.1 oz, one hundredth of the exposure.
  • Cent receiver (account currency USC, 1 oz contract): the broker reports 417,813 USC for 1 lot, which is 4,178.13 USD after the cent factor. The receiver gets the same 10.00 lots.
  • Balance ratio (master balance 10,000 USD, receiver balance 1,000 USD): 10.00 x 1,000 / 10,000 = 1.00 lot.

These numbers are the unit tests shipped with the test report. The same calculation also ran live: XAGUSD with 5,000 oz per lot on a USD account was copied to XAGEUR with 1,000 oz per lot on a EUR account. 0.10 lot became 0.50 lot.

Symbol matching

The receiver finds the master symbol in this order:

  1. Manual map (XAUUSD=GOLD.x,US30=DJ30). It always wins and never falls back.
  2. The same name.
  3. The Suffix / Prefix hint (.cs, m, #).
  4. The same core name after the broker's decorations are removed: XAUUSD.cs, XAUUSDm, #XAUUSD, EURUSD.pro, US500Cash, fxEURUSD and similar.
  5. Built-in aliases: GOLD/XAUUSD, SILVER/XAGUSD, US30/DJ30/WS30, NAS100/US100/USTEC, US500/SPX500, GER40/DE40/DAX, UK100, JP225, USOIL/WTI, UKOIL/BRENT, BTCUSD, ETHUSD.

When two receiver symbols fit equally, the one that is in Market Watch is used. If both or neither are in Market Watch, the copy is refused and the panel asks for a manual map. For example, Exness offers US30m (1 index unit per lot) and US30_x10m (10 units per lot). Both fit a master's US30, so add the one you want to Market Watch or map it. The lot is converted either way.

Digits after a currency pair are not treated as a broker decoration. Exness XAUUSD247m (gold that also trades at weekends) is a different product, so a master's XAUUSD is copied to XAUUSDm, never to XAUUSD247m. Map it by hand if you really want it.

Before the first copy of a symbol, the receiver compares both prices in its account currency. The copy is refused when they differ by more than 3%, which can be changed. This catches mappings such as "GOLD", which at some brokers is a gold-mining stock worth about 40 USD, not gold.

Inputs

Input Default Meaning
Mode of this terminal Receiver Master publishes; Receiver copies
Channel 1 Links a master to its receivers. Use a different text for each master on the PC
Cent account (this terminal) Auto Auto treats USC/EUC account currencies as cent. Set Yes/No if your broker uses another code
Master scan interval, ms 200 How often the master checks for changes, in addition to trade events
Master heartbeat interval, ms 500 How often the master rewrites its file when nothing changes
Lot mode Same exposure See the lot modes above
Fixed lot 0.01 Used by Fixed lot mode
Multiplier 1.0 Applies to every mode except Fixed lot
Max lot of one copied position 0 (off) Upper limit for one copy
Volume rounding Nearest Nearest volume step or down
Volume below the broker minimum Skip Skip the copy, or use the minimum volume
Refuse if one lot is worth more than x times the other 1000 Guards against wrong mappings
Manual symbol map empty MASTER=RECEIVER pairs separated by commas
Receiver symbol suffix hint empty For example .cs
Receiver symbol prefix hint empty For example #
Refuse a mapping if prices differ by more than, % 3.0 0 turns the check off
Copy only these master symbols empty (all) Comma-separated
Never copy these master symbols empty Comma-separated
Copy only these master magic numbers empty (all) Comma-separated
Never copy these master magic numbers empty Comma-separated
Reverse copy false Buy becomes sell; stop loss and take profit swap
Copy stop loss and take profit true
Copy positions already open at the first start false By default only positions opened after the receiver starts are copied
Skip if price moved more than, % since master entry 0.10 Protects against late copies after a pause. 0 turns it off
Master heartbeat timeout, ms 3000 Copying pauses when the master file is older than this
Hold if a master position vanishes without a close record, s 30
Max slippage, points 20 For instant-execution symbols
Magic number of copied positions 7310001 One receiver per account and magic. Use another magic for a second receiver on the same account
Expected master account 0 0 accepts the first master seen. Otherwise copying stops if another account appears on the channel
Show the status panel true
Panel X / Y offset, px 12 / 24
Popup alerts / Push notifications true / false
CSV journal true Common\Files\SpecMatchCopier\journal_<account>_<magic>.csv

Setup

  1. Copy the EA into both terminals. They must run under the same Windows user, because Common\Files belongs to the user. Use the same version of the EA in the master and in every receiver terminal: after an update, update it in all of them.
  2. In the master terminal, attach the EA to any chart with Mode = Master.
  3. In each receiver terminal, attach the EA to any chart with Mode = Receiver and the same Channel.
  4. Enable Algo Trading in the receiver terminals.
  5. Open a small position on the master. The receiver panel shows the copy and the lot conversion.

Strategy Tester

The Strategy Tester has no second terminal. In the tester the EA therefore runs a simulated master:

  • it opens, modifies, partially closes and closes virtual positions every few bars, each sized to lose about 1% of the balance at its stop loss and to use at most 10% of the balance as margin
  • the virtual positions are never sent as orders
  • it copies those virtual positions to the tester account with the selected lot mode and all pre-trade checks

This lets you see the copying logic and the lot conversion without a second terminal. It is not a trading strategy, and its tester results say nothing about profit.

Limits (please read before buying)

  • Same PC only: master and receivers must run on the same Windows PC or VPS, under one Windows user. Copying across the internet is not supported.
  • The MQL5 built-in VPS cannot run it. Each migrated terminal has its own storage.
  • MT5 to MT5 only. Pending orders are not copied; a pending order is copied once it fills and becomes a position.
  • Closed markets: when the receiver symbol is outside its trade session, nothing is sent. The copier waits for the session to open, then copies what is still needed. A new position is still subject to the "Skip if price moved" limit. A close that the master made while the receiver's market was closed is carried out when that market opens, at the price of that moment.
  • Speed: measured on demo accounts, the receiver position matched the master 0.2 to 1.1 s after the master trade (median 0.3 s, 60 measurements; the 1.1 s case was closing 10 positions at once on a netting account). That is 100 ms of polling plus the broker's execution time. Copies are filled at the receiver's own prices, so they can differ from the master's prices, especially around news.
  • Stop loss and take profit levels:
    • When both symbols are quoted in the same currency, the exact levels are copied.
    • Otherwise, for example XAGUSD to XAGEUR, the levels are scaled by the price ratio.
    • On a netting receiver, SL/TP is copied only when all master positions on that symbol use the same levels.
  • Positions you close or reduce by hand on the receiver are left alone. They are never reopened.
  • Receiver offline for more than 48 hours: the master keeps close records for 48 hours. A copy whose master position closed before that is not closed automatically. It goes to HOLD with an alert, and you close it by hand.
  • Stop levels refused at open: when the broker rejects the stop loss or take profit of a new copy (invalid stops, for example a stops level widened around news), the copy is refused and not retried. The panel shows it as REFUSED.
  • Capped copies: when a copy is limited by Max lot or by the broker's maximum volume, a partial close on the master reduces the copy only when the new scaled volume is below what is open. Until then the copy stays at the cap.
  • No risk management: the copier does not limit drawdown or daily loss and does not manage accounts. It copies what the master does.
  • Same version everywhere: the master and the receivers measure the value of a lot with the same code. Run the same version of the EA in all terminals. For example, a v1.00 master with a v1.01 receiver keeps the v1.00 cent rounding for stock CFDs and other contracts with a small value per lot.
  • Not enough money at the broker: when the broker rejects a new copy for margin, the copy is refused and not retried. Some brokers charge more margin than MetaTrader's own margin calculation shows; the Exness demo used in the tests did.
  • Tested environment:
    • Tested live with MetaQuotes-Demo accounts: USD master, EUR hedging receiver, USD netting receiver.
    • The master was also tested on a USD netting account, with additions, a reversal by one deal, a partial close and a full close.
    • Tested live across two brokers, MetaQuotes-Demo and an Exness Standard demo (USD, hedging, symbols with the "m" suffix), in both directions:
      • MetaQuotes-Demo to Exness, matched automatically: XAUUSD to XAUUSDm, XAGUSD to XAGUSDm, EURUSD to EURUSDm. Tested with open with SL/TP, SL change, partial close, receiver restart, input change and close.
      • Exness to a MetaQuotes-Demo EUR account, matched automatically: XAUUSDm to XAUUSD, XAGUSDm to XAGUSD, EURUSDm to EURUSD. Tested with open, SL change, partial close and close. The stock CFD BACm (100 shares per lot) was copied to BAC (1 share per lot): 0.10 lot became 10.
      • Different contract sizes within Exness, with a manual map: US30m to US30_x10m (0.30 lot became 0.03), USTECm to USTEC_x100m and US500m to US500_x100m (1.00 lot became 0.01), and BTCUSDm to BTCUSDTm.
      • In every run: 0 duplicates, and an exposure difference of 0.00% to 0.01% on the panel. Wrong mappings were refused by the price check. Ambiguous matches were refused until one symbol was in Market Watch.
    • 1 oz gold and cent accounts are covered by unit tests with synthetic broker specifications, not by live accounts. Neither broker offered them on a demo.
    • Please test with your brokers on demo accounts before copying real money.
筛选:
无评论
回复评论