Loading…

Anti Basket Builder

A book in drawdown sometimes needs a brake, not a full close-out - a partial hedge that slows further loss without giving up on the original positions. Building that brake by hand means working out the net exposure per symbol and sizing an offsetting trade for each one, under the exact conditions where a trader is least likely to want to do careful arithmetic. This script automates the sizing, not the decision to trade. It nets every open position per symbol (positive = net long, negative = net short), and for each symbol that carries real net exposure, computes the opposite-direction trade sized at a chosen percentage of that net - 50% by default, so the brake slows the book without doubling it into a mirror-image bet. Every run prints the full preview table - symbol, net lots, and the exact mirror trade that would be opened - unconditionally, before any decision about sending is made. RISK WARNING: this script sends real market orders when it executes. Because of that, it never sends anything on a plain run. Two independent inputs, InpConfirmExecute and InpAcknowledgeRisk, both default to false and BOTH must be set to true before a single order is sent - a single "are you sure" flag was judged too easy to leave on by habit for a tool whose entire purpose is opening new exposure while the account is already under strain. Mirror trades are stamped with their own magic number so they can be found, tracked and closed independently of the original book, and the script never re-mirrors its own previous mirror trades. Notes and limitations - Anything that opens new exposure can lose money, including this script's own mirror trades if the market reverses after they are opened - a brake reduces net directional risk, it does not eliminate risk from the account. - Only symbols with a net non-zero exposure larger than half the broker's minimum lot get a mirror trade; internally hedged symbols are left alone. - The preview table always prints in full, even on a dry run, so the exact trade list is visible before the two confirmation inputs are ever switched on. - Mirror trades use the script's own magic number and are excluded from the net calculation on any later run, so re-running the script does not compound the brake against itself. - This script does not manage or remove the brake automatically once opened - closing it when it is no longer needed is a manual step.

Script · MT4 · v1.0 · Free

About Anti Basket Builder

Anti Basket Builder is an expert advisor (trading robot) for MetaTrader 4. It has 6 settings, such as Mirror scale pct, Magic filter and Confirm execute. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Mirror scale pct50.0Mirror size as a percentage of each symbol's net exposure
Magic filter-1Magic number filter for positions read (-1 = every magic)
Confirm executefalseGate 1 of 2: must be true to send real orders
Acknowledge riskfalseGate 2 of 2: must ALSO be true to send real orders - deliberate double gate
Anti basket magic900002Magic number stamped on the mirror trades, for later identification
Slippage points30Allowed slippage in points for the mirror trades

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: Hedging · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria