Net Exposure Auto Hedger
A trader running several uncorrelated strategies, or several EAs, on different symbols rarely stops to add up what the account is net exposed to by currency. Three separate EURUSD-adjacent positions can add up to a much larger net EUR exposure than any single position suggests, and nothing in the terminal totals it for you. This EA does the totalling continuously. It reads every open position on a configured list of symbols, works out each position's signed exposure to its base and quote currency, and sums that across the whole book into one net figure per major currency. Exposure is measured in standard-lot- equivalent units - a signed lot count per currency, matching how a trader thinks of "how many lots of EUR am I net long" - rather than converted into a single risk-weighted currency value. That is a deliberate simplification, stated plainly rather than dressed up as more than it is: it does not account for different currencies carrying different volatility or value per lot. When a currency's net exposure drifts outside a configured band, this EA sends the minimum-size offsetting trade on a configured hedge symbol to pull it back to the edge of the band - not a full flatten to zero, just the correction needed. Every hedge trade's estimated spread cost is accumulated, and the running swap carried on this EA's own hedge positions is added to it, so the account holder can see what maintaining the band is actually costing rather than assuming hedging is free. Checks run at most once every InpCheckSeconds rather than every tick, because correcting a small drift on every price update would generate far more hedge trades - and far more spread cost - than the drift between checks actually warrants. Notes and limitations - Exposure is a lot-count figure per currency, not a risk-weighted or volatility-adjusted figure. Treat the band as a position-count control, not a precise risk budget. - A currency missing from InpHedgeMap cannot be corrected automatically; its breaches are reported in the log and the on-chart Comment only. - The reported hedging cost is an estimate - spread cost is computed from the current tick spread and tick value at the moment each hedge is sent, and swap is read live from this EA's own open hedge positions. It does not include commission, which some brokers charge separately. - Non-standard symbol names (anything not exactly six characters, base then quote) are skipped from both the book and the hedge map. - This EA does not manage stop-losses on its own hedge positions - they are opened without one, since their purpose is a temporary offset, not a directional bet with its own risk plan.
Expert advisor · MT4 · v1.0 · Free
About Net Exposure Auto Hedger
Net Exposure Auto Hedger is an expert advisor (trading robot) for MetaTrader 4. It can hold buy and sell positions at the same time (hedging). It has 9 settings, such as Book symbols, Hedge map and Band lots. MQL source code included.
Files in the download: NetExposureAutoHedger.ex4, NetExposureAutoHedger.mq4, NetExposureAutoHedger.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Book symbols | EURUSD,GBPUSD,USDJPY,AUDUSD,USDCHF,USDCA | Symbols this EA reads exposure from |
| Hedge map | EUR:EURUSD,GBP:GBPUSD,JPY:USDJPY,AUD:AUD | currency:hedgeSymbol pairs |
| Band lots | 0.50 | Currency net exposure allowed to drift this many lots before hedging |
| Max hedge lots | 1.00 | Largest single hedge trade this EA will send |
| Magic book | -1 | Magic filter for the positions being measured, -1 = every magic |
| Magic hedge | 27801 | Magic number this EA tags its own hedge trades with |
| Check seconds | 30 | Minimum seconds between exposure checks - hedging every tick is wasteful |
| Slippage pips | 5 | Slippage tolerance for hedge orders |
| Max retries | 5 | Order-send attempts before giving up on one hedge |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Hedging · EURUSD · MT4 Expert Advisor · MQL4 Source Code