tocOn this page 8 sections
To copy trades between MT4 accounts on one Windows VPS, run one portable MT4 terminal per account, attach a copier EA in master mode to the source account and in slave mode to each receiving account, and let them exchange order data through %APPDATA%\MetaQuotes\Terminal\Common\Files. Every terminal running under the same Windows user can read that folder, so copying stays on the VPS and needs no outside service.
How a local copier works
Each MT4 terminal has its own data folder, but MQL4 can also reach one folder shared by all terminals under the same Windows user. An EA opens files there by adding the FILE_COMMON flag to FileOpen(). The master EA writes its open orders to a CSV file on a timer. Each slave EA reads that file, compares it with its own orders, and opens, modifies or closes trades to match. Commercial copiers use the same idea or a DLL that does it in memory. The setup below applies to both.
Step 1: One portable terminal per account
Install MT4 three times, for example into C:\MT4\Master, C:\MT4\Slave1 and C:\MT4\Slave2. Set each shortcut target to "C:\MT4\Slave1\terminal.exe" /portable so data stays inside that folder. Our guide to running several MT4 terminals on one VPS covers the layout in detail.
Run every terminal under the same Windows account. %APPDATA% resolves to C:\Users\<name>\AppData\Roaming, which differs per user, so terminals in two users' RDP sessions never see the same file. Confirm what is running and from where:
Get-CimInstance Win32_Process -Filter "Name='terminal.exe'" |
Select-Object ProcessId, CommandLine
Step 2: Install the EA and enable trading
- Copy the compiled
.ex4intoC:\MT4\<terminal>\MQL4\Expertsin each folder, then right-click Expert Advisors in the Navigator (Ctrl+N) and choose Refresh. - Open Tools > Options > Expert Advisors (Ctrl+O) and tick Allow automated trading.
- Tick Allow DLL imports only if the copier ships a DLL. File-based copiers do not need it.
- Press Ctrl+E or click AutoTrading so the button turns green.
- When attaching the EA, tick Allow live trading on the Common tab.
A frowning face in the chart's top-right corner, or error 4109 in the Experts tab, means live trading is still off.
Step 3: Attach the master
Attach the EA to one chart only, such as EURUSD M1. It reads every order in the account, so the chart symbol does not matter. A second master instance would overwrite the same file. The core of a master looks like this:
int OnInit() { EventSetMillisecondTimer(250); return(INIT_SUCCEEDED); }
void OnDeinit(const int reason) { EventKillTimer(); }
void OnTimer() {
int h = FileOpen("copier.tmp", FILE_WRITE|FILE_CSV|FILE_COMMON, ';');
if(h == INVALID_HANDLE) return;
for(int i = OrdersTotal() - 1; i >= 0; i--) {
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
FileWrite(h, OrderTicket(), OrderSymbol(), OrderType(), OrderLots(),
OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit());
}
FileClose(h);
FileMove("copier.tmp", FILE_COMMON, "copier.csv", FILE_COMMON|FILE_REWRITE);
}
The timer keeps the file fresh even when the chart symbol has no ticks, and writing to copier.tmp before FileMove() means a slave never reads a half-written file.
Step 4: Attach and tune each slave
Attach the EA in slave mode to one chart per slave terminal and set:
- Lot mode: fixed, a multiplier such as 0.5, or balance ratio (
AccountBalance()of slave divided by master). Round the result down toMarketInfo(sym, MODE_LOTSTEP)and clamp it betweenMODE_MINLOTandMODE_MAXLOT, or orders fail with error 131 (invalid volume). - Symbol mapping: map names like
EURUSDtoEURUSD.morEURUSDpro. An unmapped name returns error 4106 (unknown symbol). - Magic number: give copied orders a unique magic number, such as 770001, so the slave never touches trades you opened by hand.
- Ticket map: save master-to-slave ticket pairs to
copier_map_slave1.csvinCommon\Files. Do not rely on order comments; partial closes replace them withfrom #12345. - Slippage: set in points. On a 5-digit broker, 30 points is 3 pips.
Step 5: Test on demo first
Use two demo accounts and test each event separately: market buy and sell; placing, modifying and deleting pending orders; moving SL and TP; a partial close; a full close and a stop-out on the master; and restarting the slave while trades are open. After a restart, the slave must adopt its existing orders, not open duplicates.
Check that the master file is still being written:
$f = "$env:APPDATA\MetaQuotes\Terminal\Common\Files\copier.csv"
$age = (Get-Date) - (Get-Item $f).LastWriteTime
if ($age.TotalSeconds -gt 10) { Write-Warning "Master stale for $([int]$age.TotalSeconds)s" }
A stale file means the master EA stopped. Read that terminal's Experts and Journal tabs.
Step 6: Keep every terminal running
Leave RDP by closing the window with X, not Sign out, so the session and terminals stay alive. Start slaves at logon and delay the master so no signal is missed:
$a = New-ScheduledTaskAction -Execute "C:\MT4\Master\terminal.exe" -Argument "/portable"
$t = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$t.Delay = "PT30S"
Register-ScheduledTask -TaskName "MT4-Master" -Action $a -Trigger $t
Repeat without the delay for each slave. To get back to a logged-on session after a patch reboot, follow auto-restarting MT4 and MT5 after Windows Update.
To save RAM, lower Tools > Options > Charts > Max bars in chart to 5000 in each terminal and close unused charts. Our Windows VPS for forex trading page lists plans sized for several terminals.
FAQ
Can the master and slaves be at different brokers?
Yes. The copier only reads a local file. Expect to map symbols, and compare contract size and lot step with MarketInfo() on both sides.
Is copying allowed on prop firm accounts?
It depends on the firm; some ban copying between accounts. Check the rules first, using our prop firm copier checklist.
Why does the slave open duplicates after a restart?
It lost its ticket map. Write the map to Common\Files after every change and reload it in OnInit().
Run this on your own Windows VPS
Get a Windows VPS from WindowsVPS in about 60 seconds, with full Administrator access over RDP, NVMe storage and the Windows license included.
Written by the WindowsVPS Team
We run Windows Server VPS hosting and write these guides from the same setups our customers use: RDP, PowerShell, trading terminals and always-on bots. Questions about a guide? Contact us.