How to copy trades between your own MetaTrader 5 accounts on one VPS

How to copy trades between your own MetaTrader 5 accounts on one VPS

7 October 2026, 07:21
Timon-pascal Krueger
0
11

I run a personal account and funded accounts from one Windows VPS and wanted trades from one to appear on the others without placing them three times. Below is how I set it up with plain MetaTrader 5, including the mistakes that cost me money first. Every account here belongs to me.

1. One terminal per account, each in its own folder

MetaTrader 5 will not run two copies from the same directory, the help page tells you to install into separate folders: https://www.metatrader5.com/en/terminal/help/start_advanced/start

A terminal started with the /portable key keeps all its data inside its own folder. Remember that for step 2.

2. Give both terminals the same mailbox

A local copier needs a file that both terminals can see. The usual place is the common folder, which MQL5 opens with the FILE_COMMON flag: https://www.mql5.com/en/docs/constants/io_constants/fileflags

My slave ran in portable mode and resolved the common folder inside its own directory, so master and slave wrote to two different places and the slave never saw one trade. The fix was a directory junction from the portable Common folder to the one under AppData\Roaming\MetaQuotes\Terminal\Common. Check that the master's file shows up where the slave reads before you test anything else.

Open the file with sharing flags: FILE_SHARE_READ on the writer, FILE_SHARE_READ and FILE_SHARE_WRITE on the reader. Without them I kept getting error 5004 on both sides.

This needs a Windows VPS where you install both terminals yourself. The MQL5 virtual hosting has no shared file system between terminals.

3. Send the whole position list every cycle

If you forward events, every missed event is a permanent desync. My master writes the complete list of open positions (ticket, symbol, direction, lots, SL, TP, magic number) several times per second, with a heartbeat at the top and an end marker at the bottom. The slave compares its own positions with that list and fixes the difference. A restart or a partial close stops being a special case, and a half written file is ignored because the end marker is missing.

4. Pair each copy with something the server cannot change

I first matched copies to master tickets through the position comment. On one demo server the comment I read back was not the one I sent, so the slave did not recognise its copy and opened a new one every cycle until I switched it off. I now store the pairing in a terminal global variable keyed by the master ticket, the comment is only a fallback.

Give every new copy a grace period too. Execution took about 300 ms, longer than one copier cycle, so the slave saw no position yet and opened a second one. I wait 10 seconds before a copy counts as missing.

5. Copy every master ticket exactly once

Sooner or later a copy gets closed on the slave while the master still holds the trade. Opening it again at the new price is a different trade. I had a loop where a risk guard on the slave closed a copy at its loss limit and the copier reopened it right away. Now each master ticket is copied once, and the marker is cleared only after the master no longer holds that ticket.

6. Size by risk ratio and freeze it at open

If the master risks 2% per trade and the funded account should risk 0.25%, the slave lots are master lots times 0.125 times the equity ratio of the two accounts. Calculate that once when the copy fills and store the ratio. My first version recalculated it every cycle against live equity, floating profit kept moving the target, and the slave clipped small pieces off open copies all day.

Round down to the volume step and skip copies under the minimum lot. With 0.01 lot trades one of my test copies filled 47% below the calculated size.

7. Stop quietly when something is wrong

If the master heartbeat is older than 10 seconds, my slave freezes. A slave acting on a stale file copies trades the master closed long ago. When AutoTrading was off on the slave, my copier sent about 30 requests per second, all rejected with retcode 10027. Check TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) and OrderCalcMargin before each request, and pause a ticket after three failures.

Use hedging accounts. A netting account keeps one position per symbol, so there are no separate tickets to pair.

8. SL and TP with a different broker

On the same broker and symbol, copying SL and TP prices is fine. With a different broker the feed and often the symbol suffix differ, so I map the symbols, switch SL/TP price copying off and let the slave set its own stops.

In my logs the time from the master writing the file to the slave's fill was 203 to 266 ms, broker execution included. That is fine for my intraday entries and too slow for scalping. I later packaged my own copier as a Market product. The steps above apply to any local copier you build or buy.

What this does not cover

Copying another person's account or a signal is a different case, and the prop firm I trade with treats it as a breach, so read your firm's terms before you connect anything that is not yours. I also did not cover MT4 to MT5 bridges, copying between two machines, or netting accounts.