CSArrayFunctions





//+------------------------------------------------------------------+
//|                                               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<ArrayRange(ArrayToSearch,0);i++)
      {
         for (j=0;j<ArrayRange(ArrayToSearch,1);j++)
         {
            if (ArrayToSearch[i][j] == ValueToSearch)
            {
               ReturnArray[0]=i; // set locations
               ReturnArray[1]=j; // set locations
               return(true);  // return true
            }
         }
      }
      return(false); // return false
   }
   else
   {
      ArraySort(ArrayToSearch,WHOLE_ARRAY,0,MODE_ASCEND);
      for (i=0;i<ArrayRange(ArrayToSearch,0);i++)
      {
         for (j=0;j<ArrayRange(ArrayToSearch,1);j++)
         {
            if (ArrayToSearch[i][j] == ValueToSearch)
            {
               ReturnArray[0]=i;  // set location
               ReturnArray[1]=j;  // set location
               return (true);
            }
         }
      }
      return(false); // return -1 init array for not found
   }
}


//////////////////////////////////////////////////////////////
// Function: PrintSingleArray(ArrayToPrint)
// Return Values:
//   Void
//////////////////////////////////////////////////////////////

void PrintSingleArray(double ArrayToPrint[])
{
   int x;
   string ArrString;
      ArrString="";
      for (x=0;x<ArraySize(ArrayToPrint);x++)
      {
         ArrString = StringConcatenate(ArrString," ",ArrayToPrint[x]);
      }
      Print (ArrString);
}


//////////////////////////////////////////////////////////////
// Function: PrintDblArray(ArrayToPrint)
// Return Values:
//   Void
//////////////////////////////////////////////////////////////

void PrintDblArray(double ArrayToPrint[][])
{
   int x,y;
   string ArrString;
   for (x=0;x<ArrayRange(ArrayToPrint,0);x++)
   {
//      Print (x);
      ArrString="";
      for (y=0;y<ArrayRange(ArrayToPrint,1);y++)
      {
         ArrString = StringConcatenate(ArrString," ",ArrayToPrint[x][y]);
      }
      Print ("Row "+x+": "+ArrString);
   }
}






Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: