Loading…

Stagger Stops Against Sweeps

Stops tend to end up on the same price for reasons that have nothing to do with risk management: a round number, a swing low everyone can see, three tickets opened from the same template on the same day. A liquidity sweep that reaches that one price takes out every ticket sitting on it together, in one tick, rather than testing each one on its own merits. This script scans the matched positions, groups them by symbol and direction, and finds every group of at least InpMinGroupSize tickets whose stop sits within InpToleranceSamePips of each other. The first ticket found in each group - the anchor - is left exactly where it is. Every other ticket in the group gets moved by a random distance between InpMinOffsetPips and InpMaxOffsetPips, in a random direction, so the cluster becomes a narrow band of separate prices instead of one shared line. Every candidate offset is checked against the broker's minimum stop distance before it is sent, and is never allowed to cross the position's own open price - staggering spreads a cluster apart, it does not turn a stop-loss into a guaranteed-profit close by accident. If the randomly chosen direction does not fit, the script tries the opposite direction before giving up on that one ticket and reporting it, rather than silently leaving a level unstaggered without saying so. Running the script again is safe. A cluster that has already been spread apart no longer matches the tolerance, so it is left alone; only newly formed clusters get touched. Notes and limitations - Only market positions are touched. Pending orders have no live stop for a sweep to hunt, so they are excluded from the scan entirely. - The anchor ticket in each group (the first one found) never moves. Which ticket becomes the anchor depends on order-pool position, not on any property of the ticket itself. - A ticket whose offset range does not fit between the open price and the broker's minimum stop distance is left unchanged and reported, never approximated to the nearest allowed price. - This changes where a stop sits by a few pips; it does not change the fact that the position is exposed to a genuine trend move through that whole band. It defends against a level being an exact, known target - nothing more. - The script runs once per invocation and does not watch for new clusters forming afterward.

Script · MT5 · v1.0 · Free

About Stagger Stops Against Sweeps

Stagger Stops Against Sweeps is an expert advisor (trading robot) for MetaTrader 5. It has a news filter. It has 9 settings, such as Current symbol only, Magic filter and Min group size. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Current symbol onlyfalseRestrict to this chart's symbol
Magic filter-1Only this magic (-1 means every magic)
Min group size2Minimum tickets sharing a level before staggering
Tolerance same pips0.0Treat stops within this many pips as identical
Min offset pips1.0Smallest random offset applied, in pips
Max offset pips5.0Largest random offset applied, in pips
Also stagger targetsfalseAlso stagger identical take-profit clusters
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: Risk & Lot Size · News Trading · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria