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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Why were you thinking it's not an option to “find out how much you need to copy and copy exactly this amount” ?
Because I don’t remember a single case where I knew the exact date, but did not know the number of bars. I don't know what might cause the situation where you know the exact date before copying the bars. Usually the date is unknown to me too😄
Perhaps this is due to the fact that I have little experience with MT5...
Perhaps this is due to the fact that I have little experience with MT5...
That's why I asked my question. I have not yet decided on the approach to use in MT5 for copying quotes. In MT4 I have direct access to the chart without having to copy anything or allocate memory.
I'm still wondering which approach would be best for MT5. When I don’t know in advance exactly how many bars I will need (to find some “last signal,” for example).
iBarShift() is not returning incorrect values. I have never seen it and I used it very intensively.
Hi @Alain Verleyen
Thanks for your reply.
What I meant to say was that iTime(Symbol,HigherTimeFrame,iBarShift(Symbol,LowerTimeFrame)) was returning 1970.01.00 00:00, which I think is the start date of data series and caused by iBarShift returning -1 value.
I even tried to use following function and avoid getting return value as -1, but failed to get desired results.
The requirement is to find first PERIOD_M1 bar index (to be passed into CopySeries()) for say time = 2024.01.29 00:00, where M1 bar will never be at 00:00 Hrs:Minute as broker starts at 01:01.
Hence bool exact = true does not work and false return index prior to the 'time' specified.
I even tried following function to get first bar of lower time frame [https://www.mql5.com/en/articles/599#access_bar_time] but this time even this failed to work.
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.
@Alain Verleyen This is what my ultimate goal is :)
However I am still struggling with single symbol.
@Alain Verleyen This is what my ultimate goal is :)
However I am still struggling with single symbol.
You need to understand and deal, with the asynchronous nature of the data functions.
Using loop or sleep is a bad approach. When a data function returns -1 it (usually) means the data are not ready. The best approach is then to use events, either waiting the next tick, or forcing some events with a timer or custom event.
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.
I mean ArrayCopyRates. It's always the slowest method (which is logical as it gets all data of a given symbol/period).
This is retrieving 50000 bars on 28 symbols, 1 timeframe, on MT4.
The best approach is then to use events, either waiting the next tick, or forcing some events with a timer or custom event.
Thanks @Alain Verleyen
any pointer to article / help on this will be highly appreciated.
Dose adding below function (got it from one of the article in the Forum), in the code will help to make sure data is synchronized?
I have tried to modify OnTick() in Base Class method as below.
@Alain Verleyen #: I mean ArrayCopyRates. It's always the slowest method (which is logical as it gets all data of a given symbol/period). This is retrieving 50000 bars on 28 symbols, 1 timeframe, on MT4.
Due to a website malfunction, your embedded image was not properly saved. Please repost the image. Thank you!
Due to a website malfunction, your embedded image was not properly saved. Please repost the image. Thank you!
Thanks @Alain Verleyen
any pointer to article / help on this will be highly appreciated.
Dose adding below function (got it from one of the article in the Forum), in the code will help to make sure data is synchronized?
I have tried to modify OnTick() in Base Class method as below.
I have not seen any useful article on this. Only some discussions on this forum, please search.