Swap Accrual Ledger
OrderSwap() only ever reports the cumulative swap charged to a ticket since it opened. It never breaks that figure down by day, so answering "how much swap accrued on this position today specifically" means remembering yesterday's cumulative number and subtracting - easy to forget, impossible to reconstruct after the fact. This EA snapshots every open, magic-filtered position once per day at a declared server hour, computes the swap accrued since the previous snapshot for each ticket, and appends a DAILY row to a CSV ledger. It also watches order history continuously and, the moment a tracked ticket closes, writes a final CLOSED row capturing the last increment of swap between the last snapshot and the close. Each ticket's previous cumulative swap is kept in a global variable ("SAL_<ticket>") so a terminal restart mid-position does not lose the daily baseline. MQL4 auto-deletes any global variable left untouched for roughly four weeks. That is a theoretical exposure only for a ticket kept open and re-snapshotted daily, since every snapshot re-touches its variable, but it is stated here for completeness rather than left undocumented. Notes and limitations A position opened and closed entirely between two snapshots, before this EA ever recorded a baseline for it, produces no CLOSED row - there is nothing to reconcile against. Positions already tracked at least once always get a final CLOSED row. The daily snapshot runs at/after the declared hour, on the first check that sees a new calendar day; if the terminal is offline across that boundary, that day's snapshot is skipped rather than backfilled. This EA never trades and never modifies an order - it only reads swap and history data.
Expert advisor · MT4 · v1.0 · Free
About Swap Accrual Ledger
Swap Accrual Ledger is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Snapshot hour, Poll seconds and Magic filter. MQL source code included.
Files in the download: SwapAccrualLedger.ex4, SwapAccrualLedger.mq4, SwapAccrualLedger.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Snapshot hour | 23 | Server hour the daily snapshot runs at (0-23) |
| Poll seconds | 60 | How often the schedule/close-watch is checked |
| Magic filter | 0 | 0 = all magic numbers, otherwise only this one |
| Log file name | SwapAccrualLedger.csv | File written under MQL4\Files\ |
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 Expert Advisor · MQL4 Source Code