Search Timeframe By Price

 

Hello everyone, 

I just learned about iBarShift which returns a candle ID by date, I would like the same by price.

The docs mentions ArrayBsearch would only work on sorted arrays, Im trying to sort a copy of &high[] on the code below. Im a bit lost, as im getting the same result no matter if i sort or not.

// // MAIN
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{

  double HIGH[];
  ArrayCopySeries( HIGH, MODE_HIGH, Symbol(), 0 );
  ArraySort(HIGH,WHOLE_ARRAY,0,MODE_ASCEND);
  
  
  int limit;   
  limit = rates_total - ( prev_calculated < 1 ? 1 : prev_calculated );
  for( int i = 0 ; i < limit ; i++){
    B_HIGH[i] = ArrayBsearch( HIGH, high[i] , WHOLE_ARRAY, i+1 , MODE_DESCEND );    
  }
  

   return rates_total;
}
 

On the separated window, im outputing the sorted array HIGH. Thats not what i was expecting. Any lights on the matter will be much appreciated,

Mag

SORTED PRICE