ArrayBsearch()数组搜索【数组篇-MQL4函数】
int ArrayBsearch( double array[], double value, void count, void start, void direction)如果没有发现事件,值会返回到第一个维度的数组或者最近的一个数组。此函数不能用在字符型或连续数字的数组上(除打开柱的连续数组)。
注解: 双元查找只能够存储数。存储数字数组使用ArraySort() 函数。
参数:
array[] - 需要搜索的数组.
value - 将要搜索的值
count - 搜索的数量,默认搜索所有的数组.
start - 搜索的开始点,默认从头开始.
direction - 搜索的方向:MODE_ASCEND 顺序搜索,MODE_DESCEND 倒序搜索.
示例:
datetime daytimes[];
int shift=10,dayshift;
// 全部 Time[] 数组被排列在后面的形式
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
if(Time>=daytimes) dayshift=0;
else
{
dayshift=ArrayBsearch(daytimes,Time,WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<PERIOD_D1) dayshift++;
}
Print(TimeToStr(Time)," corresponds to ",dayshift," day bar opened at ",
TimeToStr(daytimes));
页:
[1]