MT5 Trade Journal: Send Every Trade to a Database and Dashboard

An MT5 trade journal that fills itself is simple in principle: every time a deal is added to your account, a small piece of code captures it and writes it to a database, and a dashboard reads that database to show you what is really working. You can do it three ways: an Expert Advisor that writes to a local SQLite file, an EA that sends each deal to a small web API, or a Python script that reads your trade history on a schedule. This guide explains which to pick, what to store, and the mistakes that quietly ruin trade data.
Most traders keep a journal for a few weeks and then stop, because copying tickets into a spreadsheet by hand is boring. MetaTrader 5’s History tab shows what happened, but it is a view, not a dataset you can query across months, accounts and strategies. Once your deals land in a database automatically, questions like “which setup loses money on Fridays?” or “how much am I paying in commission per strategy?” become a single query instead of an evening of copy and paste.
Last reviewed: 4 December 2026, against the official MQL5 documentation linked below.
01Why log MT5 trades to a database at all
A database turns your trading history into something you can filter, group and compare. A few practical wins:
One place for every account
Live, demo and prop-firm accounts all write to the same tables, tagged by account number, so you stop comparing screenshots.
Results per strategy
Each EA’s magic number and order comment travel with the deal, so you can see profit, costs and drawdown per system rather than one blended curve.
Honest costs
Commission, swap and fees are stored per deal. Many traders only discover how much a scalping EA pays in costs once they add them up.
Dashboards and alerts
A web dashboard, a Telegram report or a daily email can all read the same data without touching the trading terminal.
02Deals, orders and positions: what you actually store
MT5 separates three things. An order is a request to trade. A deal is the actual execution that changes your account. A position is the open exposure built from one or more deals. For a trade journal, the deal is the record you want, because it carries the executed price, volume, profit and costs.
The official Python documentation for history_deals_get lists the fields each deal returns, including ticket, order, time, time_msc, type, entry, magic, position_id, reason, volume, price, commission, swap, profit, fee, symbol and comment. The entry field tells you whether a deal opened or closed a position, and position_id lets you join the opening and closing deals into one round-trip trade.
| Column | Source field | Why it matters |
|---|---|---|
| deal_ticket (unique) | ticket | Primary key; stops the same deal being saved twice |
| account | account login | Separates live, demo and prop-firm accounts |
| position_id | position_id | Links entry and exit deals into one trade |
| time_msc | time_msc | Millisecond timestamp; store in UTC |
| symbol, type, entry | symbol, type, entry | Market, buy/sell, open or close |
| volume, price | volume, price | Size and executed price |
| profit, commission, swap, fee | same names | Net result per deal |
| magic, comment | magic, comment | Which EA or setup placed the trade |
| setup_tag (optional) | your own | Your label, e.g. the candle pattern behind the entry |
Treat this as a starting schema to adapt, not a fixed standard. Add columns for stop loss, take profit or spread at entry if your analysis needs them.
03Three ways to build the pipeline
All three approaches work. The right one depends on how many terminals you run and where you want the data to live.
| Approach | How it works | Good for | Watch out for |
|---|---|---|---|
| EA + local SQLite | MQL5’s built-in Database functions write each deal to a file | One terminal, no server, offline analysis | Data stays on that machine unless you copy it |
| EA + WebRequest to an API | The EA posts each deal as JSON to a small server that saves it in PostgreSQL or MySQL | Several terminals or VPSs, live dashboards | Needs a server; network calls must not block trading |
| Python polling | A script reads deal history from the terminal on a schedule and writes new rows | No changes to existing EAs, easy analysis with pandas | Runs on Windows next to the terminal; slight delay |
The DatabaseOpen documentation confirms that MQL5 opens or creates a SQLite database in the terminal’s MQL5\Files folder (or the common folder shared by all terminals with the DATABASE_OPEN_COMMON flag), and uses the .sqlite extension when none is given. That makes the first option the quickest way to start.
04Step by step: an automatic MT5 trade journal
Decide what you want to answer
Write down three or four questions first, such as profit per strategy, costs per symbol or results by session. They decide which columns you need.
Capture new deals
Inside an EA, react to the OnTradeTransaction event when a deal is added, then read the deal’s properties from history. In Python, poll history_deals_get for the last few minutes or hours.
Make every write idempotent
Use the deal ticket plus account as a unique key and “insert or ignore”. If the logger restarts and reads the same deal again, nothing is duplicated.
Store or send the record
Write to SQLite locally, or send JSON over HTTPS to your API. Queue failed sends and retry later instead of dropping them.
Build the first dashboard views
Start with an equity curve, net profit by magic number, costs by symbol and a win/loss table by setup tag. Add more only when you use them.
Check it on a demo account
Run it for a week on demo and compare the database totals with the MT5 History tab before trusting it with live accounts.
05WebRequest rules that catch people out
If you choose the API route, the MQL5 WebRequest documentation sets some hard limits worth knowing before you write a line of code:
- The server address must be added to the allowed URLs list under Tools → Options → Expert Advisors, or the call fails.
- WebRequest is synchronous: it pauses the program until the server answers, so keep requests small and the timeout short.
- It can only be called from Expert Advisors and scripts. Indicators cannot use it (the call returns error 4014).
- It does not run in the Strategy Tester, so test the logging part on a demo account.
Never send account passwords to your journal server. An API key in a request header and HTTPS are enough to identify your terminal.
A trading EA should never wait on a slow server. Many developers keep logging in a separate lightweight EA on its own chart so trading logic is never delayed.
06Tag your trades so the dashboard means something
A journal is only as useful as its labels. Profit by symbol is interesting; profit by reason for entry is what changes behaviour. The simplest approach is to give each strategy its own magic number and write a short setup code into the order comment, which then travels with the deal into your database.
For discretionary traders, pattern-based entries are a good example. The CandleSticks Patterns indicator for MT5 marks patterns such as Engulfing, Hammer, Harami, Morning and Evening Star on the chart and can alert you by terminal, push or email when one appears (it is available, with a free demo, on the MQL5 Market). If you record which pattern triggered each entry in your setup tag, your dashboard can show how each pattern actually performed on your account, instead of relying on memory. Pair it with Support and Resistance Levels if you also want to tag where the pattern formed.
Because indicators cannot make web requests, the logging itself always lives in an EA, a script or a Python process, never inside the indicator.
07Common mistakes and how to avoid them
Mixing time zones
Broker server time is not UTC. Convert before saving, or session statistics will be shifted by hours.
Ignoring costs
Profit without commission, swap and fee overstates results. Store all four and report net figures.
Logging orders, not deals
Pending orders that never fill clutter the data. Base results on deals, joined by position ID.
No backup
A single SQLite file on a VPS can disappear with the VPS. Schedule a daily copy or move to a hosted database.
If several accounts are involved, for example when you copy trades across funded accounts as described in our prop firm trade copier guide, the account column becomes essential for checking that each copy behaved as expected.
08When to have it built for you
A single-terminal SQLite logger is a reasonable weekend project for someone comfortable with MQL5. A pipeline that collects deals from several VPSs, survives network drops, feeds a web dashboard and sends a daily Telegram summary is a small backend system, and that is where most of the work is. Our backend and automation service covers exactly this kind of job: data collection on a schedule, notification pipelines and dashboards, built in Python (FastAPI, Django, Flask) with PostgreSQL, MySQL or Redis and deployed to your VPS, the cloud or your own servers. The terminal side, connecting MT5 to databases and external services, falls under our API and integrations work.
If you are planning a new EA anyway, it is worth asking for journal logging in the same brief. Our guide on how to write an EA brief shows how to describe it clearly.
Frequently asked questions
Does MT5 have a built-in trade journal?
MT5 keeps your deal history and can produce account reports, but it is a manual view rather than a database you can query across accounts and months. An automatic logger keeps a permanent, searchable copy outside the terminal.
Can an indicator write my trades to a database?
Not over the web. According to the MQL5 documentation, WebRequest cannot be called from indicators. Use an EA, a script or a Python script running alongside the terminal.
Can one database hold several MT5 accounts?
Yes. Store the account number with every deal and use the deal ticket plus account as the unique key. Each terminal sends its own deals, or a Python process reads each terminal in turn.
Will logging slow down my EA?
Writing to local SQLite is fast. Web requests pause the program while waiting for a reply, so keep them short, queue failures, or run logging in a separate EA so trading logic is never held up.
Want an MT5 trade journal that runs itself?
Tell us which accounts you trade, what you want to see and where it should run. We will reply with a free quote and a realistic timeline, and the source code comes with the delivery.
Trading involves risk. This article describes software and data tools only; it is not financial advice, and no setup or tool guarantees profits. Test everything on a demo account first.
Expert Advisor · MQL5 · mt5 · Trade Journal · Trading Automation
Related articles
Automate Your Trading Strategy: Turn Manual Rules Into an MT5 EA
Automate your trading strategy in MT5: learn which rules a computer can follow, how to turn them into an EA and test it safely.…
Read more →Crypto Liquidation Alert Bot: Lessons From Bitcoin’s Drop to $45K
A crypto liquidation alert bot warns you before Bitcoin crashes close your positions. Learn what it watches, how to build one safely and get…
Read more →Connect Binance to MT5: Data Feed vs Real Execution Explained
Connect Binance to MT5 the right way: see how a custom-symbol data feed differs from real API execution, plus a safe build checklist. Get…
Read more →Need a team that can design, build and maintain it all?
Let's talk. Tell us about your project and we'll reply with honest timelines.


