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.

Revisions

  1. WinstonN revised this gist Jan 8, 2018. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions ArrayFunctions.mq4
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    * @param int size - size of the array (default = 1)
    * @return int blank array of size
    */
    int clearIntArray( int& theArray[], int size = 0 ) {
    void clearIntArray( int& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    @@ -18,7 +18,7 @@ int clearIntArray( int& theArray[], int size = 0 ) {
    * @param int size - size of the array (default = 1)
    * @return int blank array of size
    */
    int clearDoubleArray( double& theArray[], int size = 0 ) {
    void clearDoubleArray( double& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    @@ -31,7 +31,7 @@ int clearDoubleArray( double& theArray[], int size = 0 ) {
    * @param int size - size of the array (default = 1)
    * @return int blank array of size
    */
    int clearStringArray( string& theArray[], int size = 0 ) {
    void clearStringArray( string& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    @@ -44,7 +44,7 @@ int clearStringArray( string& theArray[], int size = 0 ) {
    * @param int val - the item to be appended (no checks on val)
    * @return int the array with appended value
    */
    int addToIntArray( int& theArray[], int val ) {
    void addToIntArray( int& theArray[], int val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    @@ -57,7 +57,7 @@ int addToIntArray( int& theArray[], int val ) {
    * @param double val - the item to be appended (no checks on val)
    * @return double the array with appended value
    */
    double addToDoubleArray( double& theArray[], double val ) {
    void addToDoubleArray( double& theArray[], double val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    @@ -70,7 +70,7 @@ double addToDoubleArray( double& theArray[], double val ) {
    * @param string val - the item to be appended (no checks on val)
    * @return string the array with appended value
    */
    string addToIntArray( string& theArray[], string val ) {
    void addToIntArray( string& theArray[], string val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    @@ -85,7 +85,7 @@ string addToIntArray( string& theArray[], string val ) {
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayIntToStr( int theArray[], string concatWith = "," ) {
    void arrayIntToStr( int theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
    @@ -102,7 +102,7 @@ string arrayIntToStr( int theArray[], string concatWith = "," ) {
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayDoubleToStr( double theArray[], string concatWith = "," ) {
    void arrayDoubleToStr( double theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
    @@ -119,7 +119,7 @@ string arrayDoubleToStr( double theArray[], string concatWith = "," ) {
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayStringToStr( string theArray[], string concatWith = "," ) {
    void arrayStringToStr( string theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
  2. @currencysecrets currencysecrets revised this gist Jan 11, 2013. 1 changed file with 64 additions and 4 deletions.
    68 changes: 64 additions & 4 deletions ArrayFunctions.mq4
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,37 @@
    /*
    * clearArray
    * clearIntArray
    * This function deletes all items in array (sets it to 0) 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 = 0 ) {
    int clearIntArray( int& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    }

    /*
    * clearDoubleArray
    * This function deletes all items in array (sets it to 0) 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 clearDoubleArray( double& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    }

    /*
    * clearStringArray
    * This function deletes all items in array (sets it to 0) and resizes array according to size (default = 1).
    * @param string& theArray - passing the array by reference
    * @param int size - size of the array (default = 1)
    * @return int blank array of size
    */
    int clearStringArray( string& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    @@ -53,13 +79,47 @@ string addToIntArray( string& theArray[], string val ) {


    /*
    * arrayToStr
    * arrayIntToStr
    * This function outputs a one-dimensional array to a string separated by concatWith variable.
    * @param int theArray - the array of items you seek to print
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayToStr( int theArray[], string concatWith = "," ) {
    string arrayIntToStr( int theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
    s = StringConcatenate( s, theArray[i], concatWith );
    }
    s = StringSubstr( s, 0, StringLen(s) - StringLen( concatWith ) );
    return ( s );
    }

    /*
    * arrayDoubleToStr
    * This function outputs a one-dimensional array to a string separated by concatWith variable.
    * @param double theArray - the array of items you seek to print
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayDoubleToStr( double theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
    s = StringConcatenate( s, theArray[i], concatWith );
    }
    s = StringSubstr( s, 0, StringLen(s) - StringLen( concatWith ) );
    return ( s );
    }

    /*
    * arrayStringToStr
    * This function outputs a one-dimensional array to a string separated by concatWith variable.
    * @param string theArray - the array of items you seek to print
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayStringToStr( string theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
  3. @currencysecrets currencysecrets revised this gist Jan 11, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ArrayFunctions.mq4
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ int addToIntArray( int& theArray[], int val ) {
    * @param double val - the item to be appended (no checks on val)
    * @return double the array with appended value
    */
    double addToIntArray( double& theArray[], double val ) {
    double addToDoubleArray( double& theArray[], double val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
  4. @currencysecrets currencysecrets revised this gist Jan 11, 2013. 1 changed file with 30 additions and 2 deletions.
    32 changes: 30 additions & 2 deletions ArrayFunctions.mq4
    Original file line number Diff line number Diff line change
    @@ -12,18 +12,46 @@ int clearArray( int& theArray[], int size = 0 ) {
    }

    /*
    * addToIArray
    * addToIntArray
    * 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 ) {
    int addToIntArray( int& theArray[], int val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    }

    /*
    * addToDoubleArray
    * This function appends a double value to a double array.
    * @param double& theArray - passing the array by reference
    * @param double val - the item to be appended (no checks on val)
    * @return double the array with appended value
    */
    double addToIntArray( double& theArray[], double val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    }

    /*
    * addToStringArray
    * This function appends a string value to a string array.
    * @param string& theArray - passing the array by reference
    * @param string val - the item to be appended (no checks on val)
    * @return string the array with appended value
    */
    string addToIntArray( string& theArray[], string val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    }



    /*
    * arrayToStr
    * This function outputs a one-dimensional array to a string separated by concatWith variable.
  5. @currencysecrets currencysecrets revised this gist Jan 11, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ArrayFunctions.mq4
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ int clearArray( int& theArray[], int size = 0 ) {
    }

    /*
    * addToArray
    * addToIArray
    * 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)
  6. @currencysecrets currencysecrets renamed this gist Jan 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @currencysecrets currencysecrets revised this gist Jan 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ArrayFunctions.mql4
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    */
    int clearArray( int& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    ArrayInitialize( theArray, 0 );
    if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
    return( theArray );
    }

  8. @currencysecrets currencysecrets revised this gist Jan 7, 2013. 1 changed file with 21 additions and 4 deletions.
    25 changes: 21 additions & 4 deletions ArrayFunctions.mql4
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    /*
    * clearArray
    * This function deletes all items in array (sets it to EMPTY_VALUE) and resizes array according to size (default = 1).
    * This function deletes all items in array (sets it to 0) 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 ) {
    int clearArray( int& theArray[], int size = 0 ) {
    ArrayResize( theArray, size );
    ArrayInitialize( theArray, EMPTY_VALUE );
    ArrayInitialize( theArray, 0 );
    return( theArray );
    }

    @@ -22,4 +22,21 @@ int addToArray( int& theArray[], int val ) {
    ArrayResize( theArray, ArraySize( theArray ) + 1 );
    theArray[ ArraySize( theArray ) - 1 ] = val;
    return( theArray );
    }
    }

    /*
    * arrayToStr
    * This function outputs a one-dimensional array to a string separated by concatWith variable.
    * @param int theArray - the array of items you seek to print
    * @param string concatWith - the string you wish to concatenate items with (default = ",")
    * @return string the array concatenated to a string
    */
    string arrayToStr( int theArray[], string concatWith = "," ) {
    string s = "";
    int a = ArraySize( theArray );
    for( int i = 0; i < a; i++ ) {
    s = StringConcatenate( s, theArray[i], concatWith );
    }
    s = StringSubstr( s, 0, StringLen(s) - StringLen( concatWith ) );
    return ( s );
    }
  9. @currencysecrets currencysecrets created this gist Jan 7, 2013.
    25 changes: 25 additions & 0 deletions ArrayFunctions.mql4
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /*
    * 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 );
    }