Most traders focus on strategy logic and completely overlook the infrastructure layer. I've spent the last few months deep in the weeds of data export and performance tuning, and I found some stuff that isn't in the standard docs.
The CSV Export Trap: Real-Time vs. "Pseudo-Real-Time"
I was running an EA that exported tick data to CSV every 15 minutes for external analysis. Everything worked fine in testing, but on live accounts, the CSV file would sometimes come out corrupted or incomplete. After digging through forums and logs, I discovered the issue: when an EA writes to a CSV file in real-time, that file gets locked by the system . If you try to open it simultaneously for analysis, you get a conflict.
The solution isn't to avoid exports—it's to use a workaround. Some developers use a "pseudo-real-time" approach where the EA doesn't write continuously; instead, it accumulates data in memory and writes at intervals, reducing the lock window . The MetaTrader 5 documentation confirms that if you're using the MQL5/Files folder for exports, the file remains locked until the EA finishes writing .
My workaround: I modified my EA to write to a temporary file, then rename it after the write completes. Renaming is atomic and doesn't lock the target file in the same way. This completely eliminated the corruption issue.
Backtest Speed: The Visual Marker Drain
This one blew my mind. During long backtests, I noticed the speed would gradually decrease—from 10,000 ticks per second down to maybe 2,000 after a few hours. The culprit? The visual markers left on the chart .
Every time the EA opens or closes a trade during a backtest, MT4/MT5 places an arrow or line on the chart to show the entry and exit points. Over thousands of trades, these markers accumulate and bog down the rendering engine, which slows down the entire backtest .
The fix is simple but not obvious: during the backtest, periodically pause and click the "Delete lines" and "Delete arrows" buttons in the strategy tester. This clears the visual clutter and the speed picks right back up . For long backtests, I set up a reminder to do this every hour.
The USB Alert Light Hack: Beyond Push Notifications
Most traders rely on push notifications or email alerts. These work, but they have a problem: if you're not near your phone or you're in a meeting, you miss the alert. A user on a forum shared a different approach: using a USB alert light connected to the computer .
The idea is simple: the MT4 indicator or EA calls a custom DLL that sends a signal to the USB device, turning on a specific color light when a trading signal occurs . This is more reliable than sound alerts because:
I found a pre-built solution called MetaTrader Data Export that includes a DLL with source code, allowing you to send signals to external hardware like Arduino devices . The MQL4 reference confirms that custom DLLs can be used for hardware communication, though this is rarely discussed in mainstream tutorials.
A Note on iCustom() Optimization
When using iCustom() to load indicator values in your EA, be aware that the function recalculates the indicator on every tick unless you handle it efficiently. The MQL4 tutorial warns that "calculations performed in custom indicators technically can also be implemented in Expert Advisors, but this may lead to duplication of calculations and unreasonable waste of resources" .
To optimize, I cache the iCustom() results in static variables and only recalculate when a new bar forms. This reduced CPU usage by about 40% in my tests.
---
Reference:
本文首发于FXEAR.com,原创内容,未经授权禁止转载