Download MetaTrader 5

How to search different dimensions of the same array?

To add comments, please log in or register
nadiawicket
397
nadiawicket  

ArrayBsearch

Searches for a specified value in a multidimensional numeric array sorted in the ascending order. The search is performed in the first dimension taking into account the AS_SERIES flag.



I need to be able to individually search every each individual one of the 5 dimensions in my 5 dimension array, not just the first. Was looking for some sort of "array dimension" parameter in ArrayBsearch(), couldn't find it. I feel creating a huge one with just from here to here is something and from there to there to be not exactly right for my task.

Anybody know how to do this? This even worth it? Sounds like its maybe just more lag. Going for best RAM usage and most latency free. https://www.mql5.com/en/forum/125291 suggests just copying the second dimension into a new one, searching , and such, which just sounds like not really the most latency efficient way. Ive got the following code but can't have it search in a specific dimension only. Any insight? Thanks a million in advanced.

1. Creating 5 single dimensional arrays the best way or

2, Use just one huge one or

3. Search multiple dimensions?

4. Copy paste second array into a new one and search new one? (sounds slow for RAM)

What's the most lag free way?


template<typename T1,typename T2>
bool ArrayFind(const T1 &array1[],const T2 value,uint begin=0,uint count=WHOLE_ARRAY)
  {
   int size=ArraySize(arrayname);
   if(count==WHOLE_ARRAY)
      count=size-begin;
   if(begin+count>size)
      return(false);
   for(int x=begin;x<count;x++)
      if(op[x]==value)
         return(true);
   return(false);
  }
nadiawicket
397
nadiawicket  

On a side note, is MarketInfo(_Symbol,MODE_ASK) the same as Ask in terms of lag/memory allocation/speed? I've heard MarketInfo(_Symbol,MODE_ASK) is a lot better because it auto updates more than just Ask. Is there any advantage to any of them?

1, The system reading out the characters of MarketInfo(_Symbol,MODE_ASK) make it slower than Ask or not? Any real RAM/latency advantage of either?

2. They both return the exact same values all the time. Is there absolutely any difference? Computer processing time affected at all?

Ernst Van Der Merwe
5078
Ernst Van Der Merwe  
nadiawicket:

ArrayBsearch

Searches for a specified value in a multidimensional numeric array sorted in the ascending order. The search is performed in the first dimension taking into account the AS_SERIES flag.



I need to be able to individually search every each individual one of the 5 dimensions in my 5 dimension array, not just the first. Was looking for some sort of "array dimension" parameter in ArrayBsearch(), couldn't find it. I feel creating a huge one with just from here to here is something and from there to there to be not exactly right for my task.

Anybody know how to do this? This even worth it? Sounds like its maybe just more lag. Going for best RAM usage and most latency free. https://www.mql5.com/en/forum/125291 suggests just copying the second dimension into a new one, searching , and such, which just sounds like not really the most latency efficient way. Ive got the following code but can't have it search in a specific dimension only. Any insight? Thanks a million in advanced.

1. Creating 5 single dimensional arrays the best way or

2, Use just one huge one or

3. Search multiple dimensions?

4. Copy paste second array into a new one and search new one? (sounds slow for RAM)

What's the most lag free way?



An array can have a maximum of 4 dimensions.

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int array1[2][3][5][8];
   int i=1;
   for(int j=0;j<2;j++)
      for(int k=0;k<3;k++)
         for(int l=0;l<5;l++)
            for(int m=0;m<8;m++)
               array1[j][k][l][m]=i<<=1;

   int value1=4194304;

   if(ArrayFind(array1,value1))
      Print("Value found!");
  }
//+------------------------------------------------------------------+
template<typename T1,typename T2>
bool ArrayFind(const T1 &array[][][][],const T2 value)
  {
   int size[4]={0};
   for(int i=0;i<4;i++)
      size[i]=ArrayRange(array,i);
   for(int i=0;i<size[0];i++)
      for(int j=0;j<size[1];j++)
         for(int k=0;k<size[2];k++)
            for(int l=0;l<size[3];l++)
               if(array[i][j][k][l]==(T1)value)
                  return(true);
   return(false);
  }
nadiawicket
397
nadiawicket  

Thanks!!

Saved me a lifetime of puzzle solving and then some; I would've never come up with that.

nadiawicket
397
nadiawicket  
In your example code, you use the array dimension M in the top portion and do not in the arrayfind portion. This looks unintentional; typo?
            array1[j][k][l][m]=i<<=1;


Ive highlighted for reference:

   int array1[2][3][5][8];
   int i=1;
   for(int j=0;j<2;j++)
      for(int k=0;k<3;k++)
         for(int l=0;l<5;l++)
            for(int m=0;m<8;m++)
               array1[j][k][l][m]=i<<=1;

   int value1=4194304;

   if(ArrayFind(array1,value1))
      Print("Value found!");
      
  }
  
//+------------------------------------------------------------------+
template<typename T1,typename T2>
bool ArrayFind(const T1 &array[][][][],const T2 value)
  {
   int size[4]={0};
   for(int i=0;i<4;i++)
      size[i]=ArrayRange(array,i);
   for(int i=0;i<size[0];i++)
      for(int j=0;j<size[1];j++)
         for(int k=0;k<size[2];k++)
            for(int l=0;l<size[3];l++)
               if(array[i][j][k][l]==(T1)value)
                  return(true);
   return(false);
  }
nadiawicket
397
nadiawicket  

1. How do I specify in which dimension to add value1?

2. How do I retrieve the actual values instead of a yes or no?

Thanks in advanced, its an impossible puzzle.

here go another 40 hours.

whroeder1
15917
whroeder1  
nadiawicket: How do I retrieve the actual values instead of a yes or no?
  1. Your original question was "I need to be able to individually search every each individual one of the 5 dimensions." You must already the value to be able to search.
  2. That many dimensions is probably faulty thinking.
    A car has 4 wheels and 1 engine. The engine has air filter and n cylinders. You wouldn't use a multi-dimension array for that. You would use multiple single-dimension arrays of each type.
    struct Wheel{ bool isFlat; ... }
    struct Cylinder{ bool compression; ... };
    struct AirFilter{ ... };
    struct Engine{
       AirFilter filter;
       Cylinder  cylinder[];
    };
    struct Car{
       enum wheelOrder{WO_FL, WO_FR, WO_RL, WO,RR, WO_COUNT};
       Wheel wheel[WO_COUNT];
       Engine engine;
    }
    Car car;
    PrintFormat("Car's 2nd cylinder's compression is %i", 
                car.engine.cylinder[1].compression);
    PrintFormat("Car's Left Rear wheel is flat: %i", 
                car.wheel[WO_LR].isFlat);
    What are the types of values you are storing?
nadiawicket
397
nadiawicket  
whroeder1:
  1. Your original question was "I need to be able to individually search every each individual one of the 5 dimensions." You must already the value to be able to search.
  2. That many dimensions is probably faulty thinking.
    A car has 4 wheels and 1 engine. The engine has air filter and n cylinders. You wouldn't use a multi-dimension array for that. You would use multiple single-dimension arrays of each type.
    What are the types of values you are storing?

While I'm currently into storing previous indicator values, previous tick data , bids asks and order details like order opens, Id like to be able to master arrays for use with any type of data .

I'm almost there.

Is there any way to specify in what specific dimension to add value1 ? What dimension is it being added to in the example above?  Can't figure it out.

nadiawicket
397
nadiawicket  
Alert(array1[i][1]);

as per https://stackoverflow.com/questions/39672871/how-to-code-a-multidimensional-dynamic-array

yields invalid array access. I need to be able to retrieve the specific values in the specific dimensions . Any ideas?

How to code a Multidimensional Dynamic Array?
How to code a Multidimensional Dynamic Array?
  • stackoverflow.com
How to code a Multidimensional Dynamic Array in MQL4? I'm fairly new to coding MQL4. Currently coding my first EA and just learnt about Arrays. I was wondering, how to code a dynamic array? What I'm trying to do is when my EA is initialized, for the past 100 bars...
nadiawicket
397
nadiawicket  
   int array1[j][1]=4194304;

sais invalid index value

array1[1][1]=4194304;

sais invalid array access

whroeder1
15917
whroeder1  
nadiawicket: While I'm currently into storing previous indicator values, previous tick data , bids asks and order details like order opens, Id like to be able to master arrays for use with any type of data .
You just described a one-dimension array of a struct (indicator, tick, market.)
12
To add comments, please log in or register