Plugins / Hedge Account/Introduction
Introduction
An overview of the Hedge Account plugin and what it does.
What is Hedge Account?
Brokeret Hedge Account is a native C++ MT5 Server Plugin (DLL) that automatically mirrors or hedges trades from configured client groups into designated hedge accounts. It runs inside the MT5 Trade Server process and monitors all deals via the Server API.
This allows brokers to:
- Aggregate exposure from multiple client groups into a single account
- Forward net positions to liquidity providers via the hedge account
- Hedge client flow in reverse direction for risk management
- Monitor real-time exposure across groups
How It Works
- Configure mappings via plugin parameters or the REST API: map source groups (e.g.,
real\vip\*) to a hedge account (e.g., login 5001) - Plugin monitors all deals via
IMTDealSink::OnDealPerform - When a client in a mapped group opens a trade, the plugin automatically opens a corresponding position in the hedge account
- When the client closes, the plugin closes the hedge position (or sends an offsetting trade in NET mode)
- The hedge account naturally accumulates the net exposure from all mapped groups
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Client Trades │──────▶│ Hedge Account │──────▶│ LP / Execution │
│ (Group: vip\*) │ │ Plugin (DLL) │ │ Server │
└──────────────────┘ └──────────────────┘ └──────────────────┘
│ │
OnDealPerform Auto-mirror or
(Server API) net aggregate
Two Hedge Modes
Mirror Mode (HEDGE_MIRROR)
- Creates a separate tracked position in the hedge account for every source trade
- Uses comment
ha:<source_position_id>to track the relationship - On close, finds and closes the exact matching position
- Best with Hedging-type MT5 accounts for full trade visibility
Net Mode (HEDGE_NET)
- Sends trades to the hedge account without individual position tracking
- MT5's built-in netting automatically aggregates into a single net position per symbol
- On close, sends an opposite direction trade — MT5 reduces the net position
- Best with Netting-type MT5 accounts for clean net exposure view
Core Features
- Group-to-Account Trade Mapping — Map entire MT5 groups to a single hedge account using wildcard group masks
- Direction Control — Same direction (mirror/LP forwarding) or reverse direction (hedge/offset)
- Volume Multiplier — Configurable scaling per mapping (0.1x to 10x+)
- Multiple Mappings — Different groups can map to different hedge accounts with independent settings
- Symbol Filtering — Restrict hedging to specific symbols (e.g., only EURUSD, XAUUSD)
- Minimum Volume — Skip trades below a lot size threshold
- Priority System — When multiple mappings match, highest priority wins
Safety & Reliability
- Dual Recursion Prevention — Comment-based (
ha:prefix) and login-based checks prevent infinite trade loops - Thread-Safe — All shared state protected by
CMTSynccritical sections - Graceful Fallback — If a hedge trade fails, the error is logged without affecting the source trade
Monitoring
- Ring Buffer Log — Last 200 hedge actions with source/hedge details
- Daily Statistics — Total deals, hedged opens/closes, skipped, errors, volume hedged
- Server Journal — All actions logged to MT5 server journal with
BrokeretHA:prefix
Next Steps
- Installation — Get the plugin running on your MT5 server
- Parameters — Configure mappings and plugin settings
- API Reference — Manage mappings and monitor via REST API