Terry Bogger:
best practices from more experienced MQL4/MQL5 developers
best practices from more experienced MQL4/MQL5 developers
Do not use AI to generate content and post it on the forum.
Terry Bogger:
Thanks in advance to anyone willing to share their approach.
Share YOUR approach (code) if you want the others to share too.
Thanks in advance to anyone willing to share their approach.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all,
I’m working on a non-trading EA whose only purpose is to log trades for journaling and statistics, and I’d like to ask for some feedback / best practices from more experienced MQL4/MQL5 developers.
The EA idea:
It never opens or manages trades – it only listens for account activity
It logs each closed trade to a CSV file
It stores some extra info (session, timeframe, R:R, etc.)
It saves entry/exit screenshots so I can review what I saw on the chart
Right now I’m doing the following:
In MT5, using OnTradeTransaction() and HistoryDealSelect() to detect when a position is closed
In MT4, checking order/position history periodically
Writing a CSV with columns like:
Date, Ticket, Symbol, Type, Volume, EntryTime, ExitTime, EntryPrice, ExitPrice, SL, TP, Commission, Swap, Profit, Pips, SessionIn, SessionOut, RR, EntryShot, ExitShot
Using ChartScreenShot() to capture the chart when a trade opens/closes
A few questions where I’d love to hear opinions or see code examples:
Partial closes & multiple deals
What’s your preferred way to group several deals into one “logical trade” for logging, especially on MT5 netting vs hedging accounts?
Performance / reliability
Any tips to avoid file access conflicts or lost records when many trades close in a short time?
Do you buffer data in memory and flush it less often, or write one line per event?
File structure
Is CSV still the most practical choice in your experience, or do you prefer JSON / XML / something else for external analysis?
Screenshots
How do you handle naming and storing screenshots so they can be easily matched to trades later (ticket ID, timestamp, symbol, etc.)?
Any tricks to reduce disk usage without losing too much detail?
Other useful fields
Are there any additional fields you found critical for later analysis (e.g. tags, strategy name, manual vs EA, etc.)?
I’m mainly interested in robust design and long-term reliability, so any experience, code snippets or “things you wish you’d done differently” when building similar logging tools would be very helpful.
Thanks in advance to anyone willing to share their approach.