Loading…

Breakout Bracket Rebuilder

A breakout bracket - a buy stop and a sell stop placed symmetrically around price - is only useful while both legs are still resting. The instant one of them triggers, the other becomes a stale, one-sided trap: if it also fills later, the trader ends up in a second position they may not have wanted; if it expires or gets cancelled, there is no bracket left protecting either direction at all. Rebuilding it by hand means checking what is actually left on the book, cancelling the leftover leg, and placing two fresh stop orders at the right distance - easy to get wrong under time pressure right after a breakout. This script does the check and the rebuild in one run. It reads the current state of the bracket under its own magic number - both legs still resting, one leg triggered into a position, or one leg simply gone - and only acts when a rebuild is actually needed. A fully intact bracket is left completely untouched and the script says so plainly. When a rebuild is needed, any stale remaining leg is cancelled first, then a fresh symmetric pair is armed around the CURRENT price at the moment the script runs - it never touches a position that already came from a previous trigger, only the next trap. If one new leg sends successfully and the other does not, the script raises an Alert() rather than leaving a silent one-sided bracket armed, since a lone stop order left resting unopposed is a materially different risk than the intended symmetric pair. Notes and limitations - This is a Script, not an Expert Advisor - it does nothing on its own between runs. It must be run again manually (or via a hotkey/macro) each time the bracket needs re-arming after a trigger. - It never closes or modifies an existing open position from a previous trigger. It only manages the two pending legs. - If both the buy stop and sell stop are already intact and no position is open under this magic, the script does nothing and says so - it will not needlessly cancel and re-send a bracket that is still valid. - Distance and stop/target are re-applied fresh from the current price every time it rebuilds; it does not remember or adapt to how far price moved since the last trigger. - If one leg's send fails after the other succeeded, the script reports the exact one-sided state via Alert() rather than automatically retrying or cancelling the successful leg.

Script · MT4 · v1.0 · Free

About Breakout Bracket Rebuilder

Breakout Bracket Rebuilder is an expert advisor (trading robot) for MetaTrader 4. It places pending buy/sell stop or limit orders, has a news filter and trades breakouts. It has 10 settings, such as Magic, Lots and Distance pips. MQL source code included.

Files in the download: BreakoutBracketRebuilder.mq4, BreakoutBracketRebuilder.txt.

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

Settings

SettingDefaultWhat it does
Magic271001Magic number identifying this bracket's orders
Lots0.10Lot size for each new leg
Distance pips20Distance from current price to each stop order, pips
Stop loss pips30Stop loss distance from each entry, pips (0 = none)
Take profit pips60Take profit distance from each entry, pips (0 = none)
Slippage pips3Slippage tolerance, pips
Cancel stale legtrueDelete a stale leftover pending on the untriggered side before rearming
Max retries5Attempts per order before giving up
Retry wait ms500Pause between attempts, milliseconds
Confirm firsttrueAsk for confirmation before sending anything

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: Breakout · Pending Orders · News Trading · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria