Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Permutations and Combinations - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 2 reads | 0 comments |

This doesn't happen very often, but every once in a while it is necessary to iterate over all combinations or permutations of a set of objects. Or more specifically, given a set of N objects, you want to consider k of them at a time (for each combination or permutation).

In fact, combination and permutation algorithms can be used as a brute force approach to solving certain problems, by trying every possible combination or permutation until the best solution is found.

The cyclic k-permutation algorithm can be used in the real world to solve parts of the Traveling Salesman Problem (TSP) or other similar problems, such as finding candidate currencies for triangular arbitrage in foreign exchange.

Here are solutions to each problem and more. The following general algorithm allows access to every combination or permutation of a sequence of length N, k items at a time.

We have made every effort to make this API library as fast as possible. Reviewed many algorithms and libraries for combinations/permutations and performed extensive benchmarking, code analysis, and micro-optimizations.

The heap algorithms in this library have been reimplemented in a more efficient way, providing faster performance than their standard implementation.


Attachment download

📎 permut_library.mqh (25.64 KB)

📎 combinations_demo.mq5 (6.12 KB)

📎 currencyarbitrage_demo.mq5 (24.13 KB)

Source: MQL5 #25724

Verification code Refresh