easy way to detect the end of a data hole with the 'new' mql5 functions .. how?

 

In the history data of m1 I have a hole - ok, can happen.

E.g. if I want to 'start to feed' as of a date that is within that data hole I get the last existing m1-bar so to say the left end of the hole:

datetime tA[], t0 = TimeCurrent() - 5040000; // ~60 days => ~ 2017.06.14 02:46:10
int nA = CopyTime(sym,PERIOD_M1,t0,3,tA);

Now tA[] has three items: {D'2017.03.22 18:04',..,D'2017.03.22 18:06'}

Now I'd like to get the first m1-bar after that hole - so to say the right end of the hole and I try:

nA = CopyTime(sym,PERIOD_M1,tA[2],5,tA);

start_time of CopyTime() = tA[2] = D'2017.03.22 18:06'

and I 'd like to get the time of the next 5 m1-bars - but what I get is the bars: {D'2017.03.22 18:02',..,D'2017.03.22 18:06'}

So instead of getting following bars I get previous bars?

Is that a feature or a bug?

Is there an intelligent way (no iteration over all minutes or a binary search!!) to found the first following bar.

In mt4 it is so easy as I get what I want just by:

iTime( sym, PERIOD_M1, b) - iTime( sym, PERIOD_M1, b+1)

where iTime(_Symbol, PERIOD_M1, b+1) is the left end and iTime(_Symbol, PERIOD_M1, b) the right end of the hole.


PS: _LastError remains 0 even though there are no data for the requested date!

 

I just realized that this can trap you in an endless loop!

If you e.g. request the next 2 bars by:

datetime Arr[] = {tOld,tNew};
CopyTime(_Symbol,PERIOD_M1, Arr[1]+60, 2, Arr);

If now tNew is the 'left-end' of the hole, you'll never progress as you will get again and again tOld and tNew!

 
Carl Schreiber:

In the history data of m1 I have a hole - ok, can happen.

E.g. if I want to 'start to feed' as of a date that is within that data hole I get the last existing m1-bar so to say the left end of the hole:

Now tA[] has three items: {D'2017.03.22 18:04',..,D'2017.03.22 18:06'}

Now I'd like to get the first m1-bar after that hole - so to say the right end of the hole and I try:

start_time of CopyTime() = tA[2] = D'2017.03.22 18:06'

and I 'd like to get the time of the next 5 m1-bars - but what I get is the bars: {D'2017.03.22 18:02',..,D'2017.03.22 18:06'}

So instead of getting following bars I get previous bars?

Is that a feature or a bug?

The starting date is always the most recent date. Works as expected.

Is there an intelligent way (no iteration over all minutes or a binary search!!) to found the first following bar.

In mt4 it is so easy as I get what I want just by:

where iTime(_Symbol, PERIOD_M1, b+1) is the left end and iTime(_Symbol, PERIOD_M1, b) the right end of the hole.

So what, it's the same with mql5. How did you get your 'b' with mql4 ?

Get your 'b' index and use it with CopyTime() instead of using a starting date.

 
So what, it's the same with mql5.

NO! The function iTime(..) is not existing in the reference of the (mt4-) editor for mql5 - only the mql4 reference knows it!

That's why I wanted to use the functions for/of mql5 that already exist in mql4.

How did you get your 'b' with mql4 ?

Quite simple:

b = iBarShift(sym,PERIOD_M1,t0);

where t0 is the date within the data hole so I get a b which is the last bar before the hole: iTime(..,b) and iTime(..,b+1) is the first bar after the hole.

iTime() and Time[] exists for indicators, EAs, and scripts so it can be used for a code that is intended to be used by those three.

Get your 'b' index and use it with CopyTime() instead of using a starting date.

That is impossible as CopyTime() (and CopyRates() and all the other Copy..() ) return the size of the array that has been set!

iBarShift() is as well not existing in mql5 acc. to the mql5-reference. As far I studied the MQL5-reference there is no alternative to functions Copy..()   :(

So tell me how can I find the other end of the data hole using mql5-functions - without the system "try and error"??

Form my point of view all the Copy..-functions should

  1. be able to 'jump' easily to the other side of the data hole and
  2. should set _LastError to something like ERR_MISSING_DATA (is not existing)

As this is not the case it is strong argument not to switch to MQL5.

And especially for multi-timeframe and multi-symbol systems I definitely don't like the idea to request the complete history for everything and keep adjusting them while walking from the past to the present - just because the MQL5-functions cannot deal with data holes.

 
Carl Schreiber:

NO! The function iTime(..) is not existing in the reference of the (mt4-) editor for mql5 - only the mql4 reference knows it!

That's why I wanted to use the functions for/of mql5 that already exist in mql4.

Quite simple:

where t0 is the date within the data hole so I get a b which is the last bar before the hole: iTime(..,b) and iTime(..,b+1) is the first bar after the hole.

Time[] exists for indicators, EAs, and scripts so it can be used for a code that is intended to be used by those three.

That is impossible as CopyTime() (and CopyRates() and all the other Copy..() ) return the size of the array that has been set!

iBarShift() is as well not existing in mql5 acc. to the mql5-reference. As far I studied the MQL5-reference there is no alternative to functions Copy..()   :(

So tell me how can I find the other end of the data hole using mql5-functions - without the system try and error??

Form my point of view all the Copy..-functions should

  1. be able to 'jump' easily to the other side of the data hole and
  2. should set _LastErro to something like ERR_MISSING_DATA (is not existing)

As this is not the case it is strong argument to to switch to MQL5.

And especially for multi-timeframe and multi-symbol systems I definitely don't like the idea to request the complete history for everything and keep adjusting them while walking from the past to the present - just because the MQL5-functions cannot deal with data holes.


You can check holes without have check all buffer if you know how calculate how many bars must have a arbitrary range date. As I think you will know number of bars in a range date is lower than real date because in history don't exits weekends.

I have my own version of ibarshift and I use this approach for adjust return value if I have a hole

 

:-) Keep cool, I know there is no iTime() function with mql5. I didn't say you to use iTime(), I said to use the same logic. iBarshift() can be found here.

There is nothing you can do with mql4 that can't be done with mql5, just learn how to do it. That's the price for efficiency, mql5 is faster by a factor 3 at least.

 
Alain Verleyen:

:-) Keep cool, I know there is no iTime() function with mql5. I didn't say you to use iTime(), I said to use the same logic. iBarshift() can be found here.

There is nothing you can do with mql4 that can't be done with mql5, just learn how to do it. That's the price for efficiency, mql5 is faster by a factor 3 at least.

Reading your comment looks incomplete implementation of ibarshift. Then its useless


What I discovered, remarkably, is that all four versions are bugged, in the sense they don't reproduce exactly the MQL4 iBarShift(). Indeed, when the datetime given as input parameter, don't match with the opening of a candle, all versions return a wrong value.

 

Well CopyRates() and the other Copy..()-functions 'find' the left end bar of the data hole like iBarShift() - so this is not the problem!

But how do I get with the Copy..()-function easily on the 'other side' of the data hole - this I'd like to know!

But when you say:

There is nothing you can do with mql4 that can't be done with mql5, just learn how to do it.

how would you do it?

 
Juan Fernandez:

Reading your comment looks incomplete implementation of ibarshift. Then its useless


What I discovered, remarkably, is that all four versions are bugged, in the sense they don't reproduce exactly the MQL4 iBarShift(). Indeed, when the datetime given as input parameter, don't match with the opening of a candle, all versions return a wrong value.

?

I provided a working version. Try it.

 
Juan Fernandez:

Reading your comment looks incomplete implementation of ibarshift. Then its useless


What I discovered, remarkably, is that all four versions are bugged, in the sense they don't reproduce exactly the MQL4 iBarShift(). Indeed, when the datetime given as input parameter, don't match with the opening of a candle, all versions return a wrong value.

No, as the reference says:

the function will return -1 or the nearest bar index (depending on exact parameter).

And if you have a data hole you can't get the exact date! But we should have a proper way to detect and to deal with that (set _LastError and jump to the other end of the hole) - this is missing!

 
Alain Verleyen:

?

I provided a working version. Try it.


Thanks but I have my own version. Anyway I only pointed your own comment. If are working fine then perfect ;)

Reason: