Sorting Trading Records by Multiple Keys in MQL5
Summary
This document explains a generic MQL5 sorter that reorders an item array according to up to three corresponding key arrays. Each key can be sorted in ascending or descending order, allowing users to set a hierarchy such as symbol first, then position open time, then price. Empty key arrays are ignored, so the same interface can handle a single-key sort.
A worked example sorts position tickets while keeping their symbols, timestamps, and prices aligned, then displays the records before and after sorting. The sample output demonstrates the requested ordering, but the article does not describe the implementation’s algorithm, complexity, stability, or behavior when arrays have mismatched lengths or equal keys. It is a programming utility rather than a trading signal or strategy, useful for organizing trading data in MQL5.
Key ideas
- The sorter orders an item array using up to three associated key arrays.
- Each key can have its own ascending or descending direction.
- Empty key arrays can be used when fewer than three sort keys are needed.
- The example keeps ticket records aligned with their symbols, times, and prices during sorting.
- The document does not explain performance characteristics or edge cases such as mismatched array lengths.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.