Hello!
I tried to find the last bar when the time was 00:00:00 using ArrayBsearch for theTime array:
End_Bar=ArrayBsearch(Time,D'00:00:00',WHOLE_ARRAY,1,MODE_ASCEND);
The value of End_Bar that was returned is 1!
WHY does it happen?
It mean bar one. The return of ArrayBsearch is index of element. In your case is bar one of Time [].
BTW the last bar is located at bar 0
- D'00:00:00' is the DAY you compiled the code, a CONSTANT, not today's date.
datetime bod = StrToTime("00:00"); // Beginning of the day //or more efficiently: datetime now = Time[0], bod = now - now % 86400;
- Don't need to use Bsearch.
int iBod = iBarShift(NULL,0, bod);
Remembers sometimes there is no bar matching, Like on GMT+0 brokers, Sunday is a 2 hour day. Bsearch would return failure, while iBarShift would return the first bar of Sunday.
It mean bar one. The return of ArrayBsearch is index of element. In your case is bar one of Time [].
BTW the last bar is located at bar 0
I understand what does it mean.
My question is - Why doesnt it searc for the closest bar (22,23...) that the time there is 00:00:00, and instead it returns me the value of the bar i start to search from?
(Time[1]=23:30:00)
I understand what does it mean.
My question is - Why doesnt it searc for the closest bar (22,23...) that the time there is 00:00:00, and instead it returns me the value of the bar i start to search from?
(Time[1]=23:30:00)
My apology, I miss understood. The answer is I don't know :). However, you're looking for the last bar that the time is 00:00:00, right ?. I hope I'm not misunderstood again, can we do this : ?
for (int pos = 1; pos < Bars ; pos ++) { if (TimeHour (Time [pos]) == 0 && TimeMinute (Time [pos]) == 0 && TimeSeconds (Time [pos]) == 0) { int Last_Bar = pos; break; } }
BTW, WHRoeder point #2 is correct ("Remember ...")
My apology, I miss understood. The answer is I don't know :). However, you're looking for the last bar that the time is 00:00:00, right ?. I hope I'm not misunderstood again, can we do this : ?
BTW, WHRoeder point #2 is correct ("Remember ...")
Ok thx anyway ))
I think ill use this solution.
It was just interesting to me why it doesnt work.
Ok thx anyway ))
I think ill use this solution.
It was just interesting to me why it doesnt work.
Oh ?!?.
Oh ?!?.
I wanted to find a solution and to understand why it doesnt work - what i did wrong ))
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello!
I tried to find the last bar when the time was 00:00:00 using ArrayBsearch for theTime array:
End_Bar=ArrayBsearch(Time,D'00:00:00',WHOLE_ARRAY,1,MODE_ASCEND);
The value of End_Bar that was returned is 1!
WHY does it happen?