Help: array out of range, though in do...while loop I have tried to check error and exit - page 2

 
Anil Varma #:
iBarShift() 

use this function instead of in-built function

int myiBarShift(datetime mytime, ENUM_TIMEFRAMES TF)
{
   int ret = iBarShift(Symbol(), TF, mytime, false)-1;
   
   if (ret<0) ret=0;
   if (ret>iBars(Symbol(), TF)) ret = iBars(Symbol(), TF);
   
   for (int j=ret; j<iBars(Symbol(), TF); j++) 
      if (iTime(Symbol(), TF, j) < mytime) return((j-1>=0)?j-1:0);
   
   return(-1);   
}

mytime: the time you need ti find its index

TF: Time-frame you want to find index in that time frame

 
Vladislav Boyko #:

As I already said, I don't have a reliable solution for copying timeseries in mql5.

Here and here I pointed out a bug in your code from your first post that resulted in an array out of bounds. I'm afraid I can't help you with anything else.

Hi

Sorry, as you took my reply in a wrong way.

I was not seeking solution from you, but posted for other members to know the limitation of CopySeries().

Regards.

 
Mahdi Ebrahimzadeh #:

use this function instead of in-built function

mytime: the time you need ti find its index

TF: Time-frame you want to find index in that time frame

Hi @Mahdi Ebrahim

Just saw your post now and thanks a lot for the custom iBarShift().

Will try it and revert.

Regards.

 
Anil Varma #:

@Vladislav Boyko

Greetings and hope you are doing well.

I have tried all possible ways to use CopySeries() function and following are my observation after failing to succeed in any one of them.

1] If you have timeStart and timeStop parameters and not idxStart and NoOfCount values, this function creates lot of difficulties to convert time to index values. iBarShift()  has its own issues for returning incorrect values for many reasons.

2] The problem aggravates, if your start time is on a different timeframe than timeframe required for copying data.

3] MQL should consider another variation of this function with timePosStart and timePosEnd

iBarShift() is not returning incorrect values. I have never seen it and I used it very intensively.

It can return -1, which is not an incorrect value, you need to deal with it.

Yes, variation of CopySeries using time would be nice. But in the meantime you have to deal with what is provided.

 
Alain Verleyen #:
I used it very intensively.
Alain Verleyen #:
Yes, variation of CopySeries using time would be nice. But in the meantime you have to deal with what is provided.

Did I understand correctly that you use iBarShift to find out how many bars you need to copy?

 
Vladislav Boyko #:

Did I understand correctly that you use iBarShift to find out how many bars you need to copy?

Sometimes.
 
Alain Verleyen #:
Sometimes.

This is very interesting.

I still continue to work on mql4, where working with timeseries is much easier (thanks to ArrayCopyRates). But for mql5, I was thinking of either copying a fixed number of bars with each Tick/Calculate (the number of bars that will definitely be enough), or storing and updating own snapshot of the necessary charts.

I didn’t think that the option “find out how much you need to copy and copy exactly this amount” is common in serious programs, such as your programs.

On the other hand, this may be due to the fact that your programs have a GUI. That is, the need to copy data once when the user presses a button.

 
Vladislav Boyko #:
or storing and updating own snapshot of the necessary charts

Roughly speaking, such a thing would emulate the work of MT4 when using ArrayCopyRates. That is, copy the entire chart once, and then with each Tick/Calculate event update only 2 recent bars.

But I think it's quite difficult to develop code that does the job above reliably.

 
Vladislav Boyko #:

This is very interesting.

I still continue to work on mql4, where working with timeseries is much easier (thanks to ArrayCopyRates). But for mql5, I was thinking of either copying a fixed number of bars with each Tick/Calculate (the number of bars that will definitely be enough), or storing and updating own snapshot of the necessary charts.

I didn’t think that the option “find out how much you need to copy and copy exactly this amount” is common in serious programs, such as your programs.

On the other hand, this may be due to the fact that your programs have a GUI. That is, the need to copy data once when the user presses a button.

I am mainly working on multi-symbols and multi-timeframes indicators/EA. So it's not only getting data for 1 symbol on 1 given timeframe, but up to 35 symbols and 2 or more timeframes. And it needs to work in all situations, when you attach an indicator on a chart, but also when you restart the platform, when it's the week-end, when the computer goes in sleep mode, etc... There is also the need to synchronize data among symbols, and sometimes also among timeframes. It's a complex task. There is never any option which can't be considered when you have a problem to solve.

CopySeries() was introduced as it's the ONLY way to have synchronized data in all circumstances. Unfortunately it currently works with index/count only, so you have to deal with it.

ArrayCopyRates is not an option, it's too slow. Storing/updating a snapshot is not an option either, you will introduce more complexity and you will not solve anything

Why were you thinking it's not an option to “find out how much you need to copy and copy exactly this amount” ?

 
Alain Verleyen #:
ArrayCopyRates is not an option, it's too slow.

I was just measuring the time for ArrayCopyRates yesterday. The advisor spends ~15 microseconds with each tick to keep 3 charts up to date (very old and bad computer).

15 microseconds is ArrayCopyRates + RefreshRates + checks. After these 15 microseconds, you have 3 complete, up-to-date charts at your disposal.

But ArrayCopyRates is closely related to the MT4 architecture. Perhaps due to the different architecture, OnTick in MT5 has much lower latency. I find ArrayCopyRates to be very fast for MT4.

MT5 does not have ArrayCopyRates due to the way the terminal works differently (because of this, MT5 is faster and has more features). Perhaps you meant CopyRates and not ArrayCopyRates.

Reason: