Skip to content

Instantly share code, notes, and snippets.

@WinstonN
Forked from currencysecrets/ArrayFunctions.mq4
Last active January 8, 2018 19:14
Show Gist options
  • Select an option

  • Save WinstonN/d1fa1fb7090048c836981fae459f5435 to your computer and use it in GitHub Desktop.

Select an option

Save WinstonN/d1fa1fb7090048c836981fae459f5435 to your computer and use it in GitHub Desktop.
Array utility functions for MetaTrader 4. Helpful functions for doing some of the repetitive tasks in MQL.
/*
* clearArray
* This function deletes all items in array (sets it to EMPTY_VALUE) and resizes array according to size (default = 1).
* @param int& theArray - passing the array by reference
* @param int size - size of the array (default = 1)
* @return int blank array of size
*/
int clearArray( int& theArray[], int size = 1 ) {
ArrayResize( theArray, size );
ArrayInitialize( theArray, EMPTY_VALUE );
return( theArray );
}
/*
* addToArray
* This function appends an integer value to an integer array.
* @param int& theArray - passing the array by reference
* @param int val - the item to be appended (no checks on val)
* @return int the array with appended value
*/
int addToArray( int& theArray[], int val ) {
ArrayResize( theArray, ArraySize( theArray ) + 1 );
theArray[ ArraySize( theArray ) - 1 ] = val;
return( theArray );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment