Download MetaTrader 5
To add comments, please log in or register
Having questions to the author of an article? Discuss them on the Forum!
Quantum Capital International Group Ltd
215
Yang Chih Chou 2014.12.08 03:11 

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
7875
Keith Watford 2014.12.08 04:38  
The array has to be sorted first
whroeder1
13596
whroeder1 2014.12.08 14:04  
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