Introsort (Introspective sort) using Function Pointers
Info
The Introsort (Introspective sort) using Function Pointers is a Library for MetaTrader 5 that introspective sortintro or introspective sort is a hybrid sorting algorithm that provide fast performance. It is a comparison based sorting algorithm based on three phases.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Introsort (Introspective sort) using Function Pointers
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.
What this tool does
Introspective SortIntro or Introspective sort is a hybrid sorting algorithm that provide fast performance.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: introsort - array sorting algorithm - another powerful library for MetaTrader 5 traders.
Introspective Sort
Intro or Introspective sort is a hybrid sorting algorithm that provide fast performance. It is a comparison based sorting algorithm based on three phases. It uses the quicksort sort along with heapsort and insertion-sort algorithms.
Also recommended: Introsort (Introspective sort) - similar library with strong performance on MetaTrader 5.
Quick SortQuick sort is a divide and conquer algorithm which works by selecting a pivot element in the array, then partitions the other elements into two subarrays checking the condition whether the elements are greater or smaller. On average the quick sort alogirthm takes O(nlog(n)) time, with worst case complexity of O(n2).
Heap Sort
Heap sort algoirthm is a binary-heap based comparison based sorting method. It is an unstable sorting algorithm with worst case and average case time complexity of O(nlog(n)), and best case time complexity of O(n).
Insertion Sort
Insertion sort algorithm is a simple sorting method that builds the final sorted array one item at a time. It's time complexity for worst case and average case is O(n2) and best case is O(n).
Introsort algorithm combines the good parts of these three algorithms. It begins with quick sort, switching to heapsort when the recursion depth exceeds a level based on the number of elements begin sorted and switchs to insertion sort when the number of elements are less than some threshold value.
If the partition size is such that there is a possibility to exceed the maximum depth limit then the Introsort switches to Heapsort.
If the partition size is too small then Quicksort switches to Insertion Sort.
If the partition size is under the limit and not too small, then it performs a simple quicksort.
Introsort has particularly good runtime behavior. It is one of the fastest comparison sorting, algorithms in use today, and is the usual implementation of the std::sort algorithm provided with the C++ STL, Microsoft .NET Framework Class Library, GNU Standard C++ library, and LLVM libc++ library.
References
:
Code:
Comparison function Less:
You can specify your own comparison function. If no function is specified, ascending sort is used. A custom Less() function takes two arguments and contains logic to decide their relative order in the sorted array. The idea is to provide flexibility so that Introsort() can be used for any type (including user defined types) and can be used to obtain any desired order (increasing, decreasing or any other). For example, to sort an array of objects or structures (user defined types) in a custom sort order:
Convenient macros to sort array of structures (e.g., MqlRates):
You may also like: String - Library of functions for working with strings - excellent alternative for library users on MetaTrader 5.
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.