Execution Speed Benchmark
"Is this too slow to call every tick" gets answered by opinion far more often than by measurement, because measuring it properly means writing a timing harness, and nobody wants to write one just to check a single question. This script is that harness, built once, covering the four operations that actually dominate a typical expert's per-tick cost: plain arithmetic, building a string, writing a file, and reading an indicator. Timing uses GetMicrosecondCount() throughout rather than GetTickCount() or a datetime difference. GetTickCount only resolves to somewhere around 15 milliseconds on a typical Windows install, which is coarser than a single call to several of these operations - timing them with it would report zero for real, non-zero costs. The indicator test is the one worth reading closely, and it is also the one place this script's two platform versions genuinely diverge - see "MQL4 versus MQL5 differences" below before comparing the two sets of numbers directly. Notes and limitations - Results depend entirely on the machine, build, broker feed and system load at the moment the script runs. Treat a single run as a sample, not a permanent benchmark - re-run a few times if the figures will inform a real decision. - The file test measures per-line write cost with the handle already open; it does not separately measure the one-off cost of opening and closing a file, which matters more for a script that opens a new handle per line than for one that opens once and writes many lines, as this test does. - The indicator test always reads on the current chart's symbol and period - it measures the cost of the read itself, not of any specific trading logic built around it. - This script writes and then deletes one scratch file in the Files sandbox during the file test; nothing is left behind afterwards.
Script · MT4 · v1.0 · Free
About Execution Speed Benchmark
Execution Speed Benchmark is a script for MetaTrader 4 based on Moving Average. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Loop iterations, String iterations and File write lines. MQL source code included.
Files in the download: ExecutionSpeedBenchmark.ex4, ExecutionSpeedBenchmark.mq4, ExecutionSpeedBenchmark.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Loop iterations | 200000 | Iterations for the plain arithmetic loop |
| String iterations | 20000 | Iterations for the string-building test |
| File write lines | 2000 | Lines written in the file test |
| Indicator calls | 2000 | Repeated iMA() calls in the indicator test |
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 · Moving Average · MT4 Script · MQL4 Source Code