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

Combinatorics - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 2 reads | 0 comments |

Initial library for combining functions.

Combinatorics is a branch of mathematics that studies discrete structures, sets ( combinators , permutations , arrangements and enumerated combinatorics ) and the relationships between them (e.g., partially ordered sets ). Combinatorics is related to many other fields of mathematics such as algebra , geometry , probability theory and has a wide range of applications in different fields of knowledge (e.g. genetics , computer science , statistical physics ).

1) First function:

 //+------------------------------------------------------------------+
//| Numeric factorial |
//+------------------------------------------------------------------+
double factorial( integer x);

Factorial is commonly used in combinatorics , number theory and functional analysis .

Factorial is a function that grows extremely fast. It grows faster than a polynomial to any degree and slower than an exponential function (but slower than a biexponential function).

That's why the return value must be of double type. This is done because the factorial grows too fast and is already 13! A type that does not conform to the range length of a.

2) The second function:

 //+------------------------------------------------------------------+
//| combination (combination) |
//+------------------------------------------------------------------+
Double combination ( integer n, integer k);

Combination allows selecting a unique set of elements from a set of N elements. Each set will have k elements.

Therefore, the number of such sets will be the number of combinations:

C(k,N) = C(3,10) = 120.

ie. There are 3 signals on each signal, with 120 unique combinations.

3) The third function:

 //+------------------------------------------------------------------+
//| Combination with repetition (combination) |
//+------------------------------------------------------------------+
double_combination ( integer n, integer k);

Combining with repetition recognizes that certain elements can appear multiple times in a set. Suppose there are five fruits. The set of 3 elements has 2 oranges and 1 apple. Such combinations are repeated combinations. Orange repeated.

For the set of 10 signals and the possible set (3 signals) we found many combinations with repetitions:

~C(k,N)=~C(3,10)=220.

4) The fourth function:

 //+------------------------------------------------------------------+
//| Arrangement |
//+------------------------------------------------------------------+
double arrangement( integer n, integer k);

The difference between permutations and combinations is that it is not the suite that matters, but the order of the elements in the suite. Suppose there are 2 sets containing 3 elements: apple-orange-banana, apple-banana-orange. As far as combinations are concerned, we have only one combination (a set of actors). But in terms of permutations, there are two combinations (where contestants change order within a group).

Obviously there will be more permutations than combinations. For example, from the set of signals (10 signals) and the set of possible signals (3 signals) we can get as many permutations as possible:

A(k,N) = A(3,10) = 720.

5) The fifth function:

 //+------------------------------------------------------------------+
//| Repeat arrangement |
//+------------------------------------------------------------------+
double_arrange ( integer n, integer k);

ie. As is the case with composition, it is recognized that elements in a set can be repeated.

Then for the set of 10 signals and the possible set (3 signals), we will get some repeated permutations like this:

~A(k,N)=~A(3,10)=1000.

6) The sixth function:

 //+------------------------------------------------------------------+
//| Arrange |
//+------------------------------------------------------------------+
double permutation( integer N);

Arrangements let us know how many ways there are to change the order of elements in a set.

So for the set of signals (10 signals) we can get as many permutations as possible:

P(N) = P(10) = 3 628 800.

For a set of 3 signals we can get as many permutations as possible:

Number of permutation returns factorial . Therefore, there is a difference between the number of permutations of 3 elements and 10 elements.

7) The seventh function:

 //+------------------------------------------------------------------+
//| Repeat arrangement |
//+------------------------------------------------------------------+
double_permutation ( integer &nM[]);

ie. As is the case with composition, it is recognized that elements in a set can be repeated.

Just pass as argument an array where each element indicates how many times it can be repeated.

For example, if there are 3 signals and each signal is repeated once, then:

~P(N) = ~P({1,1,1}) = 6.

ie. ~P({1,1,1}) = P(3).

Assuming that the first signal can be repeated 2 times, then:

~P({2,1,1}) = 12.


Attachment download

📎 combinatorics.mqh (4.81 KB)

Source: MQL5 #1197

Verification code Refresh