Loading…

Sync Stops Across Same Symbol Tickets

A position on the same symbol and side built from several separate tickets - scaling in, an EA and a manual trade both running, a partial hedge unwound in stages - usually ends up with each ticket carrying whatever stop was typed in when it was opened. One ticket might be protected at 30 pips, another left at 80, a third with no stop at all. Managing the position as a whole then means checking every ticket individually, and the loosest one is the one that actually decides how much the group can lose. This script groups open positions by symbol and direction, and for each group finds the most conservative level already present: for a stop, the one closest to price on the correct side, since that is the one limiting the least loss; for a target, the one closest to price as well, since that is the one that locks in profit soonest. It then applies that single level to every ticket in the group. Because the level chosen is always the tightest one already present on at least one ticket, syncing can only pull other tickets' levels in to match it - it never loosens anything and never invents a level tighter than what a human or an EA already decided was appropriate for this symbol. A ticket that already matches is left untouched and counted separately in the summary, rather than resent for no reason. Notes and limitations - Grouping is by symbol and direction together. A buy and a sell on the same symbol are never synced against each other, since a conservative buy stop and a conservative sell stop point in opposite price directions. - A group of exactly one ticket has nothing to sync against and is skipped, whatever level it carries. - The synced level is validated against the broker's minimum stop and freeze distance for every ticket before it is applied. A ticket where the level is not currently placeable is reported and left unchanged, not approximated. - Only open market positions are touched. Pending orders are not part of this scan. - The script runs once per invocation. If a new ticket is opened afterward with a looser stop, it is not picked up until the script is run again.

Script · MT5 · v1.0 · Free

About Sync Stops Across Same Symbol Tickets

Sync Stops Across Same Symbol Tickets is an expert advisor (trading robot) for MetaTrader 5. It has a news filter. It has 7 settings, such as Sync stops, Sync targets and Apply to unprotected. MQL source code included.

Files in the download: SyncStopsAcrossTickets.ex5, SyncStopsAcrossTickets.mq5, SyncStopsAcrossTickets.txt.

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

Settings

SettingDefaultWhat it does
Sync stopstrueSynchronise stop loss levels
Sync targetstrueSynchronise take profit levels
Apply to unprotectedtrueAlso apply the synced level to tickets with none set
Current symbol onlyfalseRestrict to this chart's symbol
Magic filter-1Only this magic (-1 means every magic)
Max retries5Attempts per ticket before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Hedging · News Trading · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria