Download Radix sort (The fastest numeric sort) for MetaTrader 5

Radix sort (The fastest numeric sort)

Radix sort (The fastest numeric sort)

This software component for MetaTrader 5 is built to enhance the capabilities of your trading environment. This library provides a collection of modular, reusable code. It is utilized by developers to organize common functions, allowing for the integration of complex logic across multiple Expert Advisors, indicators, or scripts without the need for code duplication.

MT5 library Pack 📂

How to Setup and Use Radix sort (The fastest numeric sort)

1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.

2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.

3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.

4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.

Frequently Asked Questions

Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.

Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.

Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.

Description & Settings

RadixSort Algorithm
RadixSort sorts numeric data (integers or float) by considering a string of numbers where digit by digit sort starting from least significant digit position to most significant digit position.
The algorithm is better explained on that Wikipedia page
Time Complexity and Performance Radix sort has linear time complexity, it operates in O(n * k) time, where: n = the number of elements to sort k = the maximum element width (number of bytes) of the elements to sort
The algorithm iterates over k byte places in LSD (least significant digit) order; for each byte place, it iterates over all n elements to sort them by the k-th byte.
RadixSort Implementation in MQL
This is a highly-optimized implementation of LSD RadixSort in MQL using radix 256 (8-bits). This could be useful for sorting huge arrays with millions of numbers.
This implementation is based on radix sort by Pierre Terdiman, published at , with select optimizations published by Michael Herf at and by Eddy L O Jansson at .
The function is at least
3-10 times faster
than MQL's built-in function.
The function accepts any-dimensional arrays of simple type (char, uchar, short, ushort, int, uint, long, ulong, bool, color, datetime, float, double) as a parameter. However, sorting is always applied to the first (zero) dimension.
An array is always sorted in the ascending order irrespective of the AS_SERIES flag value.
Note that, the algorithm falls back to ArraySort() if the array contains less than some threshold of items (currently 128).
Radix sort should be the default for sorting numeric data as it operates in O(n * k) time. Comparison-based sorting algorithms (like quicksort, mergesort and heapsort) run in O(n * log n) time. Thus, Radix sort is comparatively faster, the larger the array size. The downside of radix sort is that it needs more memory (temporary array) to do its work.
This is a benchmark script that demonstrates the speed advantage of RadixSort() over MQL's ArraySort():
To replace MQL's ArraySort() by RadixSort() in your old mq5 or mqh files, just add these two lines at the top of the file:

You May Also Like

RobotFX does not own any of the code provided on this platform. All tools are freely available on the internet; we simply index and re-offer them for download. We are not responsible for any financial losses that may occur. Trading responsibilities rely solely on the traders downloading and using the displayed Expert Advisors, indicators, and scripts. These tools are provided for educational purposes only and may require modification or optimization to align with a trader's specific strategy or needs.
© ROBOTFX - Best MetaTrader Expert Advisors & Indicators