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

Array Class - Library for MetaTrader 5 | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 2 reads | 0 comments |

Sometimes we need to add an element to an array, or insert an element.

Standard Mql array functions are efficient but do not provide such functionality.

For example, if you need to find a certain element, you can use ArrayBsearch to search only in a sorted array.

They also don't support complex data types.

This class fills this gap and provides some commonly used array manipulation methods:

 class array { people :
Template < type name > integer add(T src,T &dst[]);
Template < type name > integer copy(T &dst[], T &srs[], boolean clean = 0 , integer start time = 0 , integer source start = 0 , integer source count = entire array );
Template < type name > boolean insert(T src, T &dst[], integer position);
Template < type name > integer search (T element, T &array[], integer start = 0 );
Template < type name > integer FindReverse(T element, T &array[], integer start = 0 );
Template < type name > average of doubles (T &src[]);
Template < type name > DoubleSum (T&src[]);
Template < type name > double maximum(T&src[]);
Template < type name > double minimum value (T&src[]);

Template < type name > integer Addbyref(T &src,T &dst[]);
Template < type name > Boolean value Insertbyref(T &src,T &dst[], integer position);
Template < type name > Boolean value insert (T &dst[], T &src[], starting with integer dst);
Integer string to code ( string source code, short &dst[], integer starting position = 0 , integer count = - 1 ); protected :
  type type;
  };

Usage examples of the Arrays class.

 blank start ()
  {
Integer a[],asrc[]= { 1 , 2 , 3 , 4 };
Integer b[],bsrc[]= { 5 , 6 , 7 };
arraycopy (a, asrc);
arraycopy (b, bsrc);
/**/ array array;
  Array.Insert(a,b, 0 ); //Insert array into array Array.Insert ( 0 , one, 3 ); //Insert element into array Array.Add( 8 ,one); //Add element to array double sum=array.Sum(a);  
Double avg = array.average(a);
Double max=arrays.Max(a);
What to look for integer = 2 ;
Integer findindex=arrays.Find(findwhat,a);
Integer findrev=arrays.FindReverse(findwhat,a);
integer size = array size (a);
/**/ String print= String format ( "size: %d, sum: %g, average: %g, maximum: %g, "%d" found in pos:%d, "%d" speed found in pos:%d" ,
                            size, sum, average, maximum, search content, search index, search content, search results);
short print code[];
  arrays.StringToCodes(print,printcodes); //Convert the string to an array of character codes for printing (printing);
arrayprint (a);
ArrayPrint (PrintCode);
  }

Output:


Attachment download

📎 arrays.mq5 (3.16 KB)

📎 floatingpoint.mqh (1.14 KB)

📎 types.mqh (1.46 KB)

📎 arrays.mqh (8.15 KB)

Source: MQL5 #29630

Verification code Refresh