Basket Age And Cost Summary
A basket that has been open for a while quietly accumulates two kinds of cost that never show up on the chart: swap charged every night the positions stay open, and the spread that will be paid again the moment they are eventually closed. Answering "what is this basket actually costing me to carry" normally means opening the Account History tab and adding figures up by hand, one ticket at a time. This script scans every open market position, groups them by magic number (manual trades share magic zero, so they form their own group), and prints one summary line per basket: how many positions, total lots, the age of the oldest position in the group, the swap total, and an estimated round-trip spread cost. The swap figure is a straight sum of OrderSwap() and is exact - it is the real value the terminal already tracks per ticket. The spread figure is different and is labelled as an estimate deliberately: MQL4 keeps no record of what spread was actually paid when each position opened, only the running swap total. What this script reports instead is what closing every position in the basket would cost at today's spread, computed from the broker's live tick value and tick size - a genuinely useful number, but not the same thing as "what was paid on entry", and the two would only match by coincidence if the spread has moved since. Notes and limitations - Covers open market positions only (OP_BUY / OP_SELL). Pending orders carry no swap and have not yet paid a spread, so they are excluded from every total. - The spread figure is an estimate of the cost to close now, at today's live spread - not a record of what was paid at entry. Say so plainly if quoting this figure elsewhere; the two numbers can differ meaningfully on a symbol whose spread varies by session or by volatility. - "Oldest" age is the oldest single position in each basket, not an average - a basket built mostly this week with one leftover position from a month ago will report that month-old age, which is intentional: it is the figure most useful for spotting a forgotten leg. - Grouping is by magic number only. Two unrelated strategies that happen to share a magic number (or both use manual trading, magic zero) will be reported as one combined basket.
Script · MT4 · v1.0 · Free
About Basket Age And Cost Summary
Basket Age And Cost Summary is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Current symbol only and Magic filter. MQL source code included.
Files in the download: BasketAgeCostSummary.mq4, BasketAgeCostSummary.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Current symbol only | false | Restrict to this chart's symbol |
| Magic filter | -1 | Only include this magic (-1 = every magic, grouped separately) |
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 → Scripts.
- 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 script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code