//+------------------------------------------------------------------+ //| ArrayFunctions.mq4 | //| cubesteak | //| http://www.cubesteak.net | //+------------------------------------------------------------------+ #property copyright "cubesteak" #property link "http://www.cubesteak.net" ////////////////////////////////////////////////////////////// // Function: SearchArray(ArrayToSearch, ValueToSearch,NumToCount,StartFrom,Dir) // Return Values: // Positive Number = position of value // -1 = not found ////////////////////////////////////////////////////////////// int SearchArray(double ArrayToSearch[],double ValueToSearch, int NumToCount=WHOLE_ARRAY, int StartFrom=0,int Dir=MODE_ASCEND) { // Print ("searching for "+ValueToSearch+" counting "+NumToCount+" starting from "+StartFrom+" in Dir "+Dir); int LastIndexNo = ArraySize(ArrayToSearch)-1; ArraySort(ArrayToSearch,NumToCount,StartFrom,Dir); int index = ArrayBsearch(ArrayToSearch,ValueToSearch,NumToCount,StartFrom,Dir); // get the position if (ArrayToSearch[index] == ValueToSearch) return (index); //checking for actual match and not "closest index" else return (-1); } ////////////////////////////////////////////////////////////// // Function: SearchSecondDim(ReturnArray, ArrayToSearch, ValueToSearch,Dir) // Return Values: // Returns True or False, with ReturnArray passed by ref to give position // ReturnArray [0] = ArrayToSearch first dim location // ReturnArray [1] = ArrayToSearch second dim location // if ReturnArray [0] = -1 = not found // // NOTE: ReturnArray[2] need to be declared prior to using this function. // Example 1: // // double MySearchArray[10][5]; // ArrayInitialize(MySearchArray,0); // MySearchArray [7][5] = 7; // double foo[2]; // this is the temp array that will store the search location // bool FoundIt = SearchSeconDim (foo,MySearchArray,7,MODE_ASCEND); // searching for 7 // // This will set foo[0]==7 and foo[1]==5. Also, FoundIt will be "true". // // Example 2: // // double MySearchArray[10][5]; // ArrayInitialize(MySearchArray,0); // MySearchArray [7][5] = 7; // double foo[2]; // this is the temp array that will store the search location // bool FoundIt = SearchSeconDim (foo,MySearchArray,10,MODE_ASCEND); // searching for 10 // // This will set foo[0]==-1 and foo[1]==-1 since the value isn't anywhere in the array's second dimension. // Also, FoundIt will be "false". // ////////////////////////////////////////////////////////////// bool SearchSecondDim(double& ReturnArray[],double ArrayToSearch[][],double ValueToSearch,int Dir=MODE_ASCEND) { ArrayInitialize(ReturnArray,-1); int i,j; if (Dir == MODE_DESCEND) { ArraySort(ArrayToSearch,WHOLE_ARRAY,0,MODE_DESCEND); for (i=0;i