Realised Gains By Tax Year
Handing an accountant a screenshot of the Account History tab is not enough - it shows every trade individually, mixes gross price result with swap and commission in ways that are not always obvious, and has no concept of a tax year at all. This script does the grouping work: every closed trade is bucketed by its close date into the tax year it actually falls in, with gross profit, swap and commission reported as three separate columns plus the net. The tax year boundary is an input, not a fixed assumption. Plenty of jurisdictions do not run their tax year from January to December - the United Kingdom's runs from 6 April, for one well-known example - and a script that only understood the calendar year would put months of real trades in the wrong bucket for anyone outside a January-start country. Set the month and day once and every trade lands in the right year from then on. Deposits and withdrawals are deliberately excluded. They are balance operations, not trades, and OrderProfit() on a balance entry is the cash amount itself, not a trading result - folding it into a "gains" figure would overstate or understate the real trading result by however much was moved in or out that year. Use this catalogue's Deposit Withdrawal Ledger script separately for the cash-flow side. Notes and limitations - This is a summary of what the terminal's own history holds, not a tax filing. Tax treatment of forex and CFD trading varies enormously by jurisdiction and account type, and this script makes no attempt to apply any of it - it only groups and totals figures the platform already reports. - Deposits, withdrawals, and any other balance operation are excluded entirely, on purpose. Only actual buy/sell trades are counted on either platform. - The terminal only reports what its own history has loaded - choose All History (MT4) or widen the history range (MT5) before running the script if a year looks short. - A trade year is determined by close time. A position opened in one tax year and closed in the next is counted entirely in the year it closed, which matches how realised gains are normally recognised.
Script · MT5 · v1.0 · Free
About Realised Gains By Tax Year
Realised Gains By Tax Year is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Fiscal year start month, Fiscal year start day and Magic filter. MQL source code included.
Files in the download: RealisedGainsByTaxYear.ex5, RealisedGainsByTaxYear.mq5, RealisedGainsByTaxYear.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fiscal year start month | 1 | Tax year start month (1-12) |
| Fiscal year start day | 1 | Tax year start day (1-31) |
| Magic filter | -1 | Magic filter (-1 = all) |
| Symbol filter | Symbol filter ("" = all) | |
| Export csv | false | Also write the table to a CSV file |
| Delimiter | DelimiterComma | CSV column separator |
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: Alerts · MT5 Script · MQL5 Source Code