Download MetaTrader 5

ArrayBsearch BUG Question

To add comments, please log in or register
Quantum Capital International Group Ltd
207
Yang Chih Chou  

Dear Metaquotes

i use this  code to test arraybsearch i feel the result is incorrect

int OnInit()

  {

//---

   ArrayResize(array,10);

   array[0]=64;

   array[1]=128;

   array[2]=52;

   array[3]=78;

   array[4]=30;

   array[5]=21;

   array[6]=88;

   array[7]=977;

   array[8]=2110;

   array[9]=887;

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//---

   

   Print(array[4]);

   Print(ArrayBsearch(array,30,WHOLE_ARRAY,0,MODE_ASCEND));

   

  }

//+------------------------------------------------------------------+ 

 

Array[4] is 30

why  ArrayBsearch(array,30,WHOLE_ARRAY,0,MODE_ASCEND) is 0

 

thank you! 

Keith Watford
Moderator
10635
Keith Watford  
The array has to be sorted first
whroeder1
15692
whroeder1  
fxchess:

Dear Metaquotes

why ArrayBsearch(array,30,WHOLE_ARRAY,0,MODE_ASCEND) is 0
  1. Only us users here. MetaQuotes is at the Service Desk
  2. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  3. ArrayBsearch - MQL4 Documentation clearly says:

    Note

    Binary search processes only sorted arrays. To sort numeric arrays use the ArraySort() function.

To add comments, please log in or register