Download MetaTrader 5

Array Question

To add comments, please log in or register
Tony Chavez
236
Tony Chavez  

Is there a way to search an array and see how many times a value range happens?


Example in SQL would be something like: Select count(*) From table Group By Column


What I am trying to do is search last 100 bars search how many bars comes within a certain range of the highest bar for the time frame and see how many bars come within a certain range of the lowest bar for the time frame.

Abejorro
184
Abejorro  

Tony Chavez:

Example in SQL would be something like: Select count(*) From table Group By Column


I would suggest 1)'ArrayCopy' (optional)  -  2) 'ArraySort'  -  3) any quick find and then a counting loop with your ranges.

SQL is just a convenient story above the same way.

whroeder1
16096
whroeder1  

Tony Chavez: Is there a way to search an array and see how many times a value range happens?

What I am trying to do is search last 100 bars search how many bars comes within a certain range of the highest bar for the time frame and see how many bars come within a certain range of the lowest bar for the time frame.

  1. "Is there a way?" How do you think iHighest works? It just goes one by one keeping tract of the highest seen. You just have to do the same, you code it.
    double hi = High[iHighest(_Symbol, PERIOD_CURRENT, MODE_HIGH, 100, 0)];
    double lo =  Low[ iLowest(_Symbol, PERIOD_CURRENT, MODE_LOW,  100, 0)];
    double range = 0.10 * (hi - lo);
    int    nHi = 0, nLo = 0;
    for(int iBar = 0; iBar < 100; ++iBar){
       if(hi - High[iBar] < range) ++nHi;
       if( Low[iBar] - lo < range) ++nLo;
    }
    Is that so hard?
  2. No need for the sort as Abejorro suggests, there would be no savings there.
To add comments, please log in or register