I have a 101 element array (shown):
I have a 101 element array (shown):
her's my code now:
ArrayResize(Array,count); ArraySort(Array,WHOLE_ARRAY,0,MODE_ASCEND); for(int x=0;x<count;x++)Print(x," ",DoubleToStr(BendArray[x],5)); int c = ArrayBsearch(Array,NormalizeDouble(1.60349,5),WHOLE_ARRAY,0,MODE_ASCEND); Print(DoubleToStr(c,0));
I won't list the whole array again just snippets. So using the example above c = 59.
I can go on with other examples but the result is the same. Sometimes (rarely) it will get the right index - it's all very erratic.
her's my code now:
I won't list the whole array again just snippets. So using the example above c = 59.
I can go on with other examples but the result is the same. Sometimes (rarely) it will get the right index - it's all very erratic.
Maybe it's a double comparison issue, maybe 1.60349 in cell 60 is fractionally greater than 1.60349 so the nearest lower value is found instead, cell 59
You could try this modification . . .
double HalfAPoint = Point / 2.0; // <--- added ArrayResize(Array,count); ArraySort(Array,WHOLE_ARRAY,0,MODE_ASCEND); for(int x=0;x<count;x++)Print(x," ",DoubleToStr(BendArray[x],5)); int c = ArrayBsearch(Array, 1.60349 + HalfAPoint, WHOLE_ARRAY,0,MODE_ASCEND); // <--- modified Print(DoubleToStr(c,0));
To go a step further I changed everything to 8 digit precision.
ArrayResize(Array,count); ArraySort(Array,WHOLE_ARRAY,0,MODE_ASCEND); for(int x=0;x<count;x++)Print(x," ",DoubleToStr(BendArray[x],8)); int c = ArrayBsearch(Array,NormalizeDouble(1.60156250,8),WHOLE_ARRAY,0,MODE_ASCEND); Print(DoubleToStr(c,0));
with example above c = 52!!
I thought it was going to work first of all because the first few tests were correct. Then the above happened...
If this is real it's not good!
int count = 0; for(int j=0;j<=Bars;j++) { if(...condition met....) { Array[count] = iHigh(NULL,Period_H4,j); count++; } }
Maybe it's a double comparison issue, maybe 1.60349 in cell 60 is fractionally greater than 1.60349 so the nearest lower value is found instead, cell 59
You could try this modification . . .
Sorry, my mistake, the modification should of course be . . .
int c = ArrayBsearch(Array, 1.60349 - HalfAPoint, WHOLE_ARRAY,0,MODE_ASCEND); // <--- modified
But isn't using 8 digit precision the ultimate test?
Try this (not tested) :
int count = 0; for(int j=0;j<=Bars;j++) { if(...condition met....) { Array[count] = NormalizeDouble(iHigh(NULL,Period_H4,j),Digits); count++; } }
and then
ArrayResize(Array,count); ArraySort(Array,WHOLE_ARRAY,0,MODE_ASCEND); for(int x=0;x<count;x++)Print(x," ",DoubleToStr(BendArray[x],8)); int c = ArrayBsearch(Array,NormalizeDouble(1.60156250,Digits),WHOLE_ARRAY,0,MODE_ASCEND);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a 101 element array (shown):