Margin Usage History
- Utilities
- Version: 1.0
- Activations: 10
Margin Usage History reads this account's own closed-trade history and shows how much of the account balance was typically committed as margin at the moment each position was opened - as a percentage. It does not predict, judge or advise, and it never looks at trade results; it only measures how much of the account was put on the line each time.
WHY THIS EXISTS
The same lot size means something very different depending on how large the account balance is at the time. If the balance shrinks and lot size stays the same, the share of the account committed to each trade quietly climbs without anyone deciding it should. "I was only committing 3% of my account during a good stretch, but that crept up to 15% once losses started piling up" is a pattern many traders would recognise in hindsight, yet the account's history tab never adds it up - it just lists trades one by one.
SETUP
1. Drag the EA onto any chart. The symbol and timeframe do not matter - it reads the account's whole closed-trade history, not the chart it is running on.
2. A panel appears in the top-left corner and fills in from this account's own history.
3. It recalculates only when the number of closed deals changes, checked every 60 seconds. Nothing needs to be started or configured.
4. Nothing else is required. There are no numeric settings to tune.
INPUTS (four, in this order)
- InpShowPanel (true) - show or hide the panel.
- InpPanelCorner (top-left) - which of the four chart corners the panel sits in.
- InpPanelFontSize (9) - panel text size. Display only.
- InpColorText (white) - panel text colour.
There is no numeric threshold anywhere. The 365-day window is fixed and cannot be changed.
HOW THE NUMBERS ARE BUILT
For each closed position, the margin that would have been required to open it is estimated with the terminal's own margin calculation, using this account's current leverage and symbol settings - MT5 has no way to look up what those settings were in the past, so this is a deliberate, disclosed approximation rather than a limitation of this tool. The account balance at the moment that position opened is reconstructed by working backward from the current balance, subtracting every closing result, swap, commission, deposit and withdrawal that happened after that position was opened. Any unrealised result on positions that are still open plays no part in this calculation.
WHAT THE PANEL SHOWS
The panel shows the median committed margin over the last 365 days - the middle value of what share of the account balance was committed at the moment each position opened - next to the total number of positions behind it. Below that, Highest committed margin shows the single largest share seen in that window. By symbol lists the median committed margin for up to 5 symbols, ranked by how many positions could be measured, with anything beyond that folded into an Other symbols line. When there is no closed-trade history to measure, the panel says so in one line instead of leaving the section blank.
THE REPORT FILE
A CSV file is written to MQL5\Files\MarginUsageHistory\margin_usage_report.csv, broken down by month with columns: Month, Symbol, ClosedCount, MedianMarginPercent. A blank Symbol marks the overall row for that month. It is rewritten in full each time, not appended, so it never contains duplicates. Its full path is printed on the panel.
BEFORE YOU TEST IT
The Strategy Tester only has the closed-trade history from that one test run, so what you see there reflects the test period, not this account's real trading history. It is useful for confirming the EA runs without errors, not for reading its numbers as if they were real account data.
WHAT IT DOES NOT DO
It never places, closes or modifies a trade - it has no connection to the trade side of the terminal at all; it only reads and calculates from history that already exists. It does not use trade results to judge anything - the result of each closed trade is only used internally to reconstruct the account's balance at each point in time, never shown as a number anywhere. It does not include open positions - only fully closed ones count, and any unrealised result plays no part in the calculation. It does not judge whether a committed margin share was too high or too low, and it does not suggest what share to use. It reads one account on one terminal, going back only as far as this account's own trade history reaches.
