Array Limit Prober
There is no documented hard element cap for a dynamic array in MQL4 - the real ceiling is available memory, and that varies by machine, by build, and by everything else the terminal happens to be doing at the time you ask. Code that assumes "arrays can always grow as far as I need" eventually meets a resize that fails, and if nothing checked for that, the result is either a crash or, worse, silent use of an array that never actually grew. This script measures two different things and keeps them separate rather than assuming they scale together: how far a double[] array can grow, and how far a string[] array can grow. String elements carry per-element object overhead beyond their characters, so the practical ceiling for a string array is meaningfully lower than a double array of the same element count - conflating the two would understate the risk for any tool that stores strings. It grows each array by doubling from a starting size until ArrayResize() returns -1, and stops there rather than continuing to probe past failure, both to get a clean answer and to avoid needlessly stressing the terminal. A safety cap input keeps the probe itself well short of "freeze the terminal for a minute" territory. Separately, and more importantly for anyone reusing the pattern, it proves that a failed ArrayResize() does not destroy the array's existing contents: it writes five known values into a small array, deliberately requests an unreasonable oversized resize so it fails, and then checks that the original five values and the original size are still exactly there. That is what makes "check the return value and keep using the array" the actually correct response to a failed resize, rather than treating a resize failure as unrecoverable. Notes and limitations - The reported "largest successful size" is only accurate for THIS run on THIS machine at THIS moment - it is not a documented platform constant and will vary with available RAM, other running programs, and MetaTrader build. - The probe steps by doubling, so the reported ceiling can overshoot the true boundary by up to the growth factor - it finds the last successful doubling step, not the exact byte-for-byte limit. Lower InpGrowthFactor toward 1.1-1.2 for a tighter (but slower) estimate. - The safety caps exist specifically to stop the probe from trying to allocate an unreasonable amount of memory and freezing the terminal. Raise them deliberately and in small increments if you need to test further, not by an order of magnitude in one step. - The failed-resize safety proof uses a single deliberately oversized request (2,000,000,000 elements) that is expected to fail on any real machine; on a machine with implausible amounts of free memory it could theoretically succeed, in which case the script says so and skips the proof for that run rather than reporting a false result.
Script · MT5 · v1.0 · Free
About Array Limit Prober
Array Limit Prober is a script for MetaTrader 5. It has 5 settings, such as Start size doubles, Growth factor and Safety cap doubles. MQL source code included.
Files in the download: ArrayLimitProber.ex5, ArrayLimitProber.mq5, ArrayLimitProber.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Start size doubles | 1000 | First array size to try (elements) |
| Growth factor | 2.0 | Multiply size by this each successful step |
| Safety cap doubles | 20000000 | Never attempt more than this many elements (~160 MB for doubles) |
| Start size strings | 1000 | First string-array size to try (elements) |
| Safety cap strings | 2000000 | String elements carry per-element overhead, so a lower cap |
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: MT5 Script · MQL5 Source Code