MT4 to MT5 Trade Copying on a Single Windows VPS

Copy trades from an MT4 master to an MT5 slave on one Windows VPS through the shared Common\Files folder, with hedging checks, symbol mapping, lot rounding and tests.

dns WindowsVPS Team calendar_today schedule5 min read
MT4 to MT5 Trade Copying on a Single Windows VPS
tocOn this page 8 sections
  1. Why MT4 to MT5 needs extra care
  2. Step 1: Install both terminals and enable algo trading
  3. Step 2: Confirm the shared Common folder
  4. Step 3: Master EA in MT4 writes a snapshot
  5. Step 4: Slave EA in MT5 mirrors it
  6. Step 5: Test on demo accounts
  7. Step 6: Keep it running unattended
  8. FAQ

To copy trades from MT4 to MT5 on one Windows VPS, run both terminals under the same Windows account. A master EA in MT4 writes its open positions to a file in %APPDATA%\MetaQuotes\Terminal\Common\Files. A slave EA in MT5 reads that file on a timer and opens, changes or closes matching positions. Both terminals share one disk, so a copy usually lands within one timer cycle (about 250 ms). Most failures come from the MT5 account type and symbol names, not from the file transfer.

Why MT4 to MT5 needs extra care

MT4 runs MQL4 and MT5 runs MQL5, so you need one EA compiled for each terminal. Three platform differences also affect the setup:

  • Position accounting. MT4 gives every order its own ticket. An MT5 account is either hedging or netting. On a netting account, all buys and sells on one symbol merge into a single position, so a master holding two EURUSD trades cannot be mirrored.
  • Symbol names. The same pair can appear as EURUSD, EURUSD.m or EURUSDpro.
  • Contract specs. Minimum lot, lot step and contract size often differ on indices, metals and crypto CFDs.

For MT4-to-MT4 copying only, follow our local MT4 trade copier setup instead.

Step 1: Install both terminals and enable algo trading

Over RDP, install the terminals into C:\Trading\MT4-Master and C:\Trading\MT5-Slave by clicking Settings on the installer's first screen and changing the path. Log in to each account. Then enable:

  • MT4: Tools > Options > Expert Advisors > Allow automated trading, plus the AutoTrading toolbar button.
  • MT5: Tools > Options > Expert Advisors > Allow algorithmic trading, plus the Algo Trading toolbar button.

Check the MT5 account type before going further. The MT5 title bar shows Hedge or Netting after the server name. To check from code, print AccountInfoInteger(ACCOUNT_MARGIN_MODE) in OnInit() and confirm it equals ACCOUNT_MARGIN_MODE_RETAIL_HEDGING. If it doesn't, ask the broker to open a hedging account.

Step 2: Confirm the shared Common folder

Each terminal keeps its own data folder (File > Open Data Folder), but all MT4 and MT5 terminals run by the same Windows user share one Common folder. This is true even when they start with /portable:

$common = "$env:APPDATA\MetaQuotes\Terminal\Common\Files"
Test-Path $common
Get-ChildItem $common | Select-Object Name, Length, LastWriteTime

If MT4 runs as trader1 and MT5 as Administrator, each user has a different %APPDATA% path and the copier sees nothing. Run both terminals in one RDP session under one user.

Step 3: Master EA in MT4 writes a snapshot

In MT4 press F4 to open MetaEditor, create an EA under MQL4\Experts, and compile it with F7. Have the master write the full list of open positions each cycle, not individual events. That way, if one update is missed, the next write corrects it. Call this from OnTimer():

int h = FileOpen("copier.tmp", FILE_WRITE|FILE_CSV|FILE_COMMON, ';');
for(int i = 0; i < OrdersTotal(); i++)
  if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderType() <= OP_SELL)
    FileWrite(h, OrderTicket(), OrderSymbol(), OrderType(),
              OrderLots(), OrderStopLoss(), OrderTakeProfit());
FileClose(h);
FileMove("copier.tmp", FILE_COMMON, "copier.csv", FILE_COMMON|FILE_REWRITE);

Writing to a temporary file and then renaming it means the slave never reads a half-written file. Call EventSetMillisecondTimer(250) in OnInit() and EventKillTimer() in OnDeinit(). Drag the EA from the Navigator (Ctrl+N) onto one chart only.

Step 4: Slave EA in MT5 mirrors it

Build the slave under MQL5\Experts with the same 250 ms timer. On each cycle, read copier.csv with FILE_READ|FILE_CSV|FILE_COMMON, then:

  1. Match each slave position to its MT4 ticket. Store the ticket in the position comment (for example m:12345678) and set a fixed magic number with CTrade::SetExpertMagicNumber(20251) so manual trades are never touched.
  2. Open a position for every master ticket that has no slave position.
  3. Modify the SL/TP with CTrade::PositionModify() when they differ from the master's.
  4. Close slave positions whose ticket has left the file. After a partial close in MT4, the remaining volume gets a new ticket with the comment from #<old ticket>. Treat that ticket as a replacement and reduce the slave position's volume to match.

Add an input such as EURUSD=EURUSD.m;XAUUSD=GOLD for symbol mapping. To size each copy, multiply the master lots by the multiplier, round down with MathFloor(lots / step) * step using SYMBOL_VOLUME_STEP, then clamp the result between SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_MAX. If FileOpen returns INVALID_HANDLE or the file is older than 10 seconds, skip that cycle. Never treat it as "close everything".

Step 5: Test on demo accounts

Start with demo accounts on both sides. Watch the snapshot change live in PowerShell:

Get-Content "$env:APPDATA\MetaQuotes\Terminal\Common\Files\copier.csv" -Wait

In MT4, open, modify, partially close and fully close trades. After each action, check MT5's Toolbox > Trade tab (Ctrl+T) and its Experts tab. Then close MT5 while MT4 has trades open and start it again. The slave should pick up the existing positions without opening duplicates.

Step 6: Keep it running unattended

  • Leave by running tsdiscon or by closing the RDP window. Don't use Sign out, because signing out closes both terminals.
  • Start the terminals at logon, with the slave delayed so the master writes the file first:
$a = New-ScheduledTaskAction -Execute "C:\Trading\MT5-Slave\terminal64.exe"
$t = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$t.Delay = 'PT30S'
Register-ScheduledTask -TaskName "MT5 Slave" -Action $a -Trigger $t

For automatic logon after Windows Update reboots, see auto-restarting MT4 and MT5 after reboots. To check memory use, run Get-Process terminal, terminal64 | Select-Object Name, @{n='MB';e={[math]::Round($_.WorkingSet64/1MB)}} and close charts the copier doesn't need.

For data center locations and plans sized for MetaTrader, see Windows VPS for forex trading.

FAQ

Can I copy from MT5 to MT4 instead?

Yes. Swap the roles so MT5 writes the file and MT4 reads it. If the MT5 master is a netting account, it only has one net position per symbol, and that single position is what MT4 copies.

Does the copier keep working with the RDP window closed?

Yes, as long as the session is disconnected and not signed out. Both terminals and their timers keep running in a disconnected session.

Can one MT4 master feed several MT5 accounts?

Yes. Install one MT5 terminal per account in its own folder, such as C:\Trading\MT5-Slave2. Attach the slave EA to each terminal with its own lot multiplier and magic number. Every slave reads the same copier.csv.

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.

Buy a Windows VPS →

dns

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.

About WindowsVPS Windows VPS guides All articles

Ready to deploy your server?

Windows or Linux VPS — up and running in under 60 seconds.