Virtual Sub Account Allocator
A MetaTrader account has exactly one balance and one equity figure. A trader running several strategies on it - several EAs, or one EA in several configurations - has no native way to ask "how is strategy B doing on its own", and no native way to stop strategy B specifically when it blows its own risk budget while strategy A keeps running normally. Everything shares the same real account number. This header keeps that missing bookkeeping in memory. Each named bucket gets its own allocated virtual capital, its own running virtual equity (updated as the trader reports each closed trade's P&L into the bucket that owns it), its own high-water mark, and its own drawdown limit expressed as a percentage of that high-water mark. Once a bucket's drawdown limit is breached it halts - and a halted bucket stops accepting further P&L, so even a subsequent winning trade reported into it cannot quietly revive its equity past the halt point behind the trader's back. Every other bucket keeps operating exactly as before; one strategy failing its own risk limit never has to mean stopping the account entirely. Rebalancing pools the current virtual equity of a chosen set of buckets back together and redivides it by a set of target weights - concretely, this reallocates capital away from a bucket you choose to exclude (for example, a halted one) toward the buckets still trading, in whatever proportion you specify. A freshly rebalanced bucket receives new capital, but that is a separate decision from being cleared to trade again: halting and recapitalising are tracked independently, and ResetHalt() must be called explicitly when the intent really is to let a halted bucket resume. This library is pure bookkeeping and arithmetic - it never reads or writes a real order or the real account balance. IsHalted() is a flag the calling EA is expected to check before sending an order for that strategy; the library only decides, the caller is responsible for actually acting on it. Notes and limitations - Advisory bookkeeping only. This library never touches OrderSend, OrderClose or the real account. IsHalted() is only as effective as the calling code that checks it before trading. - ReportPnL expects the CALLER to attribute each closed trade's profit to the correct bucket - there is no automatic mapping from a real ticket or magic number to a bucket name. A typical caller keys that mapping off its own magic-number-to-strategy convention. - Drawdown is measured from each bucket's own high-water mark of virtual equity, not from its original allocated capital - a bucket that has grown well past its starting allocation can still halt on a drawdown measured from its new peak, which is the intended, standard drawdown definition, not a bug. - Rebalancing is an explicit, caller-triggered operation, not automatic or scheduled. Nothing in this header watches for when a rebalance "should" happen. - No accessor exposes equityCurve directly by design (only the running totals via Equity()/DrawdownPct()) - a caller wanting the raw curve for charting would need to add an accessor for it; this keeps the shipped header's public surface small.
Script · MT5 · v1.0 · Free
About Virtual Sub Account Allocator
Virtual Sub Account Allocator is a script for MetaTrader 5. MQL source code included.
Files in the download: VirtualSubAccounts.mq5.mqh, VirtualSubAccounts.txt, VirtualSubAccountsDemo.ex5, VirtualSubAccountsDemo.mq5.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT5 Script · MQL5 Source Code