QuickSort for Ordering Trading Positions by Open Price
Summary
The document explains quicksort, a recursive method for sorting an array by selecting a pivot and partitioning values around it. It outlines a partition process using left and right pointers, swapping out-of-order values until the pointers meet, then recursively sorting the resulting subarrays. It states average-case complexity of O(n log n) and worst-case complexity of Θ(n²).
The example applies the method in MetaTrader 5 to sort open positions by their opening prices, in ascending or descending order, while retaining each position’s ticket alongside its sort key. Sample output shows EURUSD positions listed with prices in ascending order. This is an implementation example rather than a trading strategy or performance study; it gives no evidence about trading returns, and the document does not discuss pivot-selection alternatives or handling of edge cases.
Key ideas
- Quicksort partitions an array around a pivot and recursively sorts the resulting sections.
- The described partition process scans inward from both ends and swaps values that are on the wrong side of the pivot.
- The document reports average-case complexity of O(n log n) and worst-case complexity of Θ(n²).
- The example sorts trading positions by open price while keeping each ticket associated with its price.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.