Loading…

Partial Fill Aware Copier

A partial close in MQL4 does not shrink the original ticket. The broker closes the requested slice against the original ticket, which then shows closed at partial volume in history, and opens a brand-new ticket for whatever remains open. Any copier that tries to remember "master ticket 123 maps to slave ticket 456" breaks the moment either side partially closes, because the ticket it was watching either vanishes or keeps trading a volume that no longer matches what the mapping recorded. This copier never builds that mapping. Every reconciliation pass reads the master's current open-order snapshot, sums lots per symbol and direction, and separately sums this account's own open lots for the same symbol and direction. The difference between those two sums is the only thing that drives action: grow the slave side with an incremental order if the master is bigger, shrink it with a full or partial close if the master is smaller. However MetaTrader re-tickets a partial close internally, the aggregate lot figures already reflect it on the very next poll, so the reconciliation never depends on knowing which specific ticket did what. Reducing lots on the slave side prefers whole-order closes and only reaches for a partial close on the last order it needs to touch, and even then never partial-closes an order's entire remaining volume - some brokers reject that call and expect a full close instead. Notes and limitations - This EA does not write the master snapshot file itself - it only reads one. Producing that file on the master side is outside this project's scope and must be built separately. - Reconciliation works on the AGGREGATE lots per symbol and direction, not on individual trades. If the master holds two separate BUY EURUSD positions of different sizes for different reasons, this copier only ever sees and replicates their combined total on the slave side, as a single order per direction. - A snapshot older than InpMaxSignalAgeSec freezes the slave book exactly where it is rather than forcing it flat - a stale file is read as "no new information", not as "the master has nothing open". - Symbols the master no longer has open at all are fully closed on the slave side, but only for orders carrying this EA's own magic number; it never touches a manually opened or foreign-magic position.

Expert advisor · MT4 · v1.0 · Free

About Partial Fill Aware Copier

Partial Fill Aware Copier is an expert advisor (trading robot) for MetaTrader 4. It has 7 settings, such as Master book file name, Copy ratio and Magic number. MQL source code included.

Files in the download: PartialFillAwareCopier.ex4, PartialFillAwareCopier.mq4, PartialFillAwareCopier.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Master book file namepartial_fill_master_book.csvFile in MQL4\Files\ - master's open-order snapshot
Copy ratio1.0Multiplier applied to master's aggregate lots per symbol/direction
Magic number46300Magic number stamped on orders this EA opens
Slippage points30Maximum acceptable slippage, in points
Max signal age sec90Ignore a master snapshot older than this many seconds
Min reconcile lots0.01Smallest drift worth acting on (avoids churn from rounding)
Poll interval sec2Seconds between checks of the master snapshot file

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Volume · Trade Copier · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria