EA Ledger True Costs MT5

  • Utilità
  • Quoc Dat Quach
    Quoc Dat Quach
    Software engineer with 8 years in fintech and mobile, writing MQL4/MQL5 since 2017. I build Expert Advisors, indicators, trade and risk-management panels and utilities for MT4/MT5, and I trade forex and gold on MT5 myself.
  • Versione: 1.0
  • Attivazioni: 10

An account ledger for MetaTrader 5 that splits your results by magic number, symbol, weekday and hour, shows price P/L, commission, swap and fees in separate columns, and measures the spread paid at each fill and the slippage against the price you asked for. The totals are checked against the account balance on every update. It never trades on a chart.

What it does

Attach it to one chart. It reads the account's deal history, rebuilds every position from its deals and shows the result on a panel:

  • net result, price P/L, commission, swap and fees, kept in separate columns
  • spread cost and slippage cost of every fill, measured from the terminal's own tick history
  • MFE and MAE of every closed trade: how far the price went in your favour and against you while it was open
  • trades, win rate, profit factor, lots and all-in cost per lot
  • deposits, withdrawals, credit, bonus, corrections and other non-trading entries, shown apart from trading results

It updates by itself when a deal is added. Its calculation was tested with synthetic histories of 50,000 and 200,000 deals; the live test accounts had up to 1,249 deals.

Totals that add up to the balance

Every time the history changes, the panel adds up all deals of the account and compares the sum with the balance the broker reports. The bar under the summary shows both numbers and the difference: green "OK" when they match to the cent, red "MISMATCH" when they do not. For the selected period it also shows that the balance change equals trading result plus non-trading entries.

Credit is shown but not counted in the balance, the same way MetaTrader counts it.

Positions rebuilt from deals

  • Hedging and netting accounts.
  • Partial closes, positions added to, close by (both positions are marked "CB"), and reversals on netting accounts (one deal that closes a position and opens the opposite one). A reversal deal's commission is split between the closed and the new trade by volume.
  • Commission booked as separate deals, and daily or monthly commission, is attached to its position when the broker links it to one. Otherwise it is shown on its own row, "Commission not linked to a position".
  • Exits by stop loss, take profit and stop out are marked.

Grouping and filters

Views: by magic number (labelled with the EA comment when there is one, magic 0 is "Manual"), by symbol, by magic number and symbol, by weekday of entry, by broker hour of entry, and a trade list.

Periods: today, this week, this month, all history, or a custom range in server time.

Click a magic number row to see its symbols, a symbol row to see its magic numbers, and a magic number and symbol row to see its trades. A chip on the panel shows the active filter and clears it.

The Results page shows money; the Costs page shows spread, slippage, commission and fees per group, cost per lot, average MFE and MAE, and where each measurement came from.

How the costs are measured

  • Spread at a fill: the bid/ask in force at the deal time, from the terminal's tick history. If there is no tick, the spread of the M1 bar is used and the trade is marked "M1".
  • Slippage: the fill price against the price that was asked for:
    • a pending order: its order price
    • a stop loss or take profit: the stop level
    • a market order: the broker usually stores no requested price for it, so the quote at the moment the order was placed is taken from the tick history (ask for a buy, bid for a sell)

Positive slippage is against you, negative is in your favour.

  • Money value of a point: taken from the trade's own profit, so it follows the account currency, including cent and EUR accounts, and the contract size (gold of 1, 10 or 100 oz per lot, index CFDs of 1, 10 or 100 units). When a trade has no price move to measure it, the average of the symbol is used, then the broker's own profit calculation.
  • MFE / MAE: the highest and lowest price the position was valued at (bid for a buy, ask for a sell) between entry and exit, from ticks. Trades longer than 3 days (an input) use M1 bars and are marked "M1".

Spread cost and slippage cost are already inside the price P/L, because they are part of the fill price. They are shown so you can see how much of the result they took. They are not subtracted a second time.

Results are saved in a small cache file, so the measurement is done once per deal. On the test accounts, the first measurement of 1,246 fills and 557 trades took 7 seconds; it runs in small slices in the background, and the panel can be used meanwhile.

CSV export

The "Export CSV" button writes four files to MQL5\Files\EALedger\<account>\:

  • <time>_summary.csv: period totals, non-trading entries, the balance check
  • <time>_groups.csv: one row per group of the current view
  • <time>_trades.csv: one row per trade, with entry and exit, costs, spread and slippage at entry and exit, MFE and MAE in points and money, the source of each measurement and notes
  • <time>_deals.csv: one row per deal, with the trade it belongs to, the requested price, the quote at order time, slippage and spread

With the input "Write the CSV files again after every history change", the same files are kept up to date under the prefix auto_.

Inputs

Input Default Meaning
Period shown at start All history Today, This week, This month, All history, Custom
Custom period: from / to 2026.01.01 / 0 Server time. 0 = now
View shown at start By magic number By magic number, By symbol, By magic number and symbol, By weekday of entry, By broker hour of entry, Trade list
Show only this magic number -1 -1 shows all
Measure spread and slippage at every fill true
Measure MFE / MAE of closed trades true
Trades up to this many days long use ticks 3 Longer trades use M1 bars
Write the CSV files again after every history change false
Panel distance from the left / top edge 8 / 22 Pixels
Panel scale in % 0 0 follows the screen DPI
Hide the chart's own trade arrows while the panel is open true MetaTrader draws them above the panel. The chart setting is restored when the panel is collapsed or the EA is removed
Tester only: open sample positions true See below

Strategy Tester

The tester has no deal history to show at the start. In the Strategy Tester only, the EA therefore opens a short series of sample positions itself:

  • minimum volume (twice the minimum when margin allows), three magic numbers ("Sample A", "Sample B", "Sample C")
  • each position is opened, half of it closed, then the rest closed, up to 60 positions
  • free margin is checked before every new position; with too little money it writes a note and sends nothing

Run it in visual mode to see the panel fill up. The sample positions are not a trading strategy and their results say nothing about profit. The tester has no requested price for market orders, and it may have no tick history, so there spread and MFE/MAE come from M1 bars and slippage is shown as "n/a" in the trade list and 0.00 in the summary.

On a live or demo chart the EA never sends, changes or closes an order.

Limits (please read before buying)

  • One chart slot: it is an Expert Advisor, so it uses the EA slot of the chart it is attached to. Attach it to a spare chart, not to the chart of a trading EA.
  • Tick history is the broker's: spread, slippage at market orders and MFE/MAE need the broker's tick history for the time of the trade. Brokers keep it for a limited time and for some symbols not at all (one stock CFD in the tests had none). Then M1 bars are used and the trade is marked "M1", or "n/a" when there is no data. The first measurement downloads tick history from the broker's server.
  • Slippage of market orders is measured against the quote at the moment the order was placed. It includes any price move during execution, which is what you pay.
  • Close by: MetaTrader books the whole profit of a close by on one of the two positions. The ledger shows it the way the broker booked it; the totals are right, the split between the two positions is MetaTrader's.
  • Netting accounts: one position can be changed by several EAs. The trade belongs to the magic number that opened it; deals of other magic numbers on it are marked "Mix".
  • Money is shown in the account currency as the broker reports it. A cent account shows cents.
  • Swap is shown in its own column and not counted in the all-in cost per lot, which covers spread, slippage, commission and fees.
  • Weekday and hour are those of the entry, in server time.
  • Tested environment:
    • Live on four demo accounts: MetaQuotes-Demo USD hedging (1,249 deals), EUR hedging (900 deals), USD netting (262 deals), and a demo account at a second broker, USD hedging (337 deals, including 5,000 oz silver, 10-unit and 100-unit index contracts and stock CFDs). On all four, the totals matched the balance to the cent, and every trade matched a separate rebuild of the history written for the test.
    • Cent accounts and 1 oz gold are covered by unit tests with synthetic deals, not by live accounts. Neither broker offered them on a demo.
    • Speed was tested with synthetic histories of 50,000 and 200,000 deals.
  • Please try it on a demo account first, with the free Strategy Tester demo.
Altri dall’autore
A local trade copier for MetaTrader 5. It copies positions between MT5 terminals on the same Windows PC or VPS and sizes each copy from both brokers' contract specifications (contract size, tick value, account currency), so a copy carries the same exposure even when the two brokers define a lot differently. It never opens a second copy of the same master position. What it does You attach the same EA to one chart in each terminal: In the master terminal, set the Mode input to Master. In each rece
Symbol Spec Auditor puts the part of a symbol's contract specification that decides position size and trading cost into one panel on the chart: point value, spread cost, margin, swap, execution rules and trading sessions. Raw specification values are converted into money per 1.00 lot in the account currency, and the broker settings that quietly break lot-size code are listed as warnings. One button exports the same audit for every Market Watch symbol to a CSV file. It is a checking tool. It plac
FREE
Spread Profile by Hour builds the spread distribution of one symbol for every hour of the server day from your broker's own tick history, and draws it as 24 bars. The solid part of a bar is the median spread of that hour, the lighter cap reaches the 90th percentile. Enter the stop size you normally use and every bar is labelled with its median spread as a share of that stop, so the cost is in the same unit as your risk. It is a measuring tool. It places no orders, uses no DLL and no WebRequest,
FREE
Repaint Inspector measures whether an indicator repaints instead of taking the claim on trust. You attach it to a chart, name any custom indicator and its parameter list, and it re-reads that indicator's buffers on bars that have already closed, counting every value that moves, every value that appears and every value that disappears, together with how far back in history that still happens. It is a measuring tool. On a chart it never sends an order. In the Strategy Tester it opens and closes on
FREE
Filtro:
Nessuna recensione
Rispondi alla recensione