Still no solution. Here's another version that can produce a good initialization for a reduced number of Bars, but comment out line 114
(// AdjustOldestBar(tfBarsCount_ary, rates_total-1);) and all the lower timeframes (with lots of bars) still fail after 3,875 (and
continuing) events have been received by OnCalculate.
Terminal Caluculations were NOT complete for OnCalculate, at the start of call count: 3875
SetTerminalData CopyBuffer for caller OnCalculate on caller count 3875, for AUDUSD in time frame PERIOD_M1 failed with error 4806, Requested data not found
Thru
SetTerminalData CopyBuffer for caller OnCalculate on caller count 3875, for AUDUSD in time frame PERIOD_M30 failed with error 4806, Requested data not found
- the higher timeframes have gotten data.
The bar counts seem to start working on the 2nd OnCalculate call
TestMQLRatesAndBars_2 (AUDUSD,M30) SetBarCounts Called by OnCalculate "Bars" succeeded on caller count 1. Bar count for AUDUSD in time frame PERIOD_M2 is 100000
thrue
TestMQLRatesAndBars_2 (AUDUSD,M30) SetBarCounts Called by OnCalculate "Bars" succeeded on caller count 1. Bar count for AUDUSD in time frame PERIOD_MN1 is 198
TestMQLRatesAndBars_2 (AUDUSD,M30) Terminal Bar counts READY for OnCalculate, call count: 2
This version use calls to Custom Events in the OnCalculate handler to trigger data initialization - I used the events handler as I don't think it a good idea to delay OnCalculate while doing things to trigger data downloads.
- I'd like to be able to directly ask the terminal how many bars have data for each time frame, but haven't identified a way to do that.
Is it possible that Bars and iBars do not trigger data downloads, but getting a handle and asking the terminal for data (iATR) does? Seems like that would be a bug... To that end, this version includes getting a handle for iATR and asking the terminal for the data. However, creating an indicator buffer and populating data in it is overhead not needed in many indicators.
Any experts offering ideas? Anyone with better ways to start up that will work better....
It's a bit hard to understand what you are trying to do.
When you request data on a symbol/timeframe different from current chart, it's ALWAYS possible to have a data error, so you can't "initialize
data". You just need to wait the next tick and try again. If you don't want to wait the next tick the trouble start.
Ah, a clearer statement of the Goal.
- Get the number of bars available for analysis in each timeframe for any symbol.
- Be able to get the 'rates' information for any (all) of the bars in each timeframe.
- If no guarantee of being able to get rates information for all bars, get the oldest bar with available rates information (assuming its
always complete, newest to oldest).
I've been having some trouble converting some MQ4 stuff to MQ5 because of the inability to get that info.
Please See:
https://www.mql5.com/en/code/26316, Bars and Rates Information Utility
At this point, I'm left guessing that Bar 999,999 will always be the oldest bar that CopyRates will work for. But, CopyRates is not always available for that bar immediately, it can take some time before the terminal is prepared to deliver the data after its first request.
- Is there a direct way to ask the terminal what the oldest bar CoypRates will work for is, for a given Symbol and timeframe?
If I could get an affirmative on that question (with the method), all would be well.
I believe iHigh, iLow, IOpen, IClose all have the same data availablity as CopyRates.
- www.mql5.com
Ah, a clearer statement of the Goal.
- Get the number of bars available for analysis in each timeframe for any symbol.
- Be able to get the 'rates' information for any (all) of the bars in each timeframe.
- If no guarantee of being able to get rates information for all bars, get the oldest bar with available rates information (assuming
its always complete, newest to oldest).
I've been having some trouble converting some MQ4 stuff to MQ5 because of the inability to get that info.
Please See:
https://www.mql5.com/en/code/26316, Bars and Rates Information Utility
At this point, I'm left guessing that Bar 999,999 will always be the oldest bar that CopyRates will work for. But, CopyRates is not always available for that bar immediately, it can take some time before the terminal is prepared to deliver the data after its first request.
- Is there a direct way to ask the terminal what the oldest bar CoypRates will work for is, for a given Symbol and timeframe?
If I could get an affirmative on that question (with the method), all would be well.
I believe iHigh, iLow, IOpen, IClose all have the same data availablity as CopyRates.
SeriesInfoInteger seems to be a better way to get the valid bars information, but it still suffers from returning bars as valid that CopyRates cannot get information for.
I made, and published, a twin indicator to the one referenced above that uses SeriesInfoInteger instead of Bars to get the bar counts.
- www.mql5.com
You just need to wait the next tick and try again
Apart from the fact that waiting for the second click is an unacceptable anomaly of the architecture which defines itself as "professional", and that when it's the weekend no second click arrives, I can also accept the compromise but the problem is that "prev_calculated" variable is already gone, to go and restore the cycle on the data you have to keep it if the reading is not successful.
The architecture is so flawed that not even explicitly calling CopyRates, cycled with a sleep, solves the problem. Necessarily wants a tick, ChartRedraw is completely useles. The ideal solution would be to invoke the "data refresh" key (right click, click on "update"), but "obviously" there is no such function helping about it.
I'm wondering does anyone know the equivalent key combination?, with windows GUI programming would it always be possible to write a DLL that resembles specifically clicking the "update" button.
Has anyone tried?
Apart from the fact that waiting for the second click is an unacceptable anomaly of the architecture which defines itself as "professional", and that when it's the weekend no second click arrives, I can also accept the compromise but the problem is that "prev_calculated" variable is already gone, to go and restore the cycle on the data you have to keep it if the reading is not successful.
The architecture is so flawed that not even explicitly calling CopyRates, cycled with a sleep, solves the problem. Necessarily wants a tick, ChartRedraw is completely useles. The ideal solution would be to invoke the "data refresh" key (right click, click on "update"), but "obviously" there is no such function helping about it.
I'm wondering does anyone know the equivalent key combination?, with windows GUI programming would it always be possible to write a DLL that resembles specifically clicking the "update" button.
Has anyone tried?
Becoming emotional leads nowhere.
The call of ChartSetSymbolPeriod with the same symbol and timeframe can be used to update the chart (similar to the terminal's Refresh command). In its turn, the chart update triggers re-calculation of the indicators attached to it. Thus, you are able to calculate an indicator on the chart even if there are no ticks (e.g., on weekends).
- www.mql5.com
- 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'm Looking for help on how to initialize terminal data before OnCalculate is called.
Attached is a sample indicator and associated log file showing the errors posted - I thought that after calling CopyRates for an 'old' bar, eventually the data would download and things would start working - but after days I am just getting error 4401, Requested history not found :
From OnInit:
Followed by OnCalculate:
How do I get the data initialized / get the history / during OnInit so CopyRates (and Bars or iBars) will return valid values once OnCalcualate starts?
(updated with cleaned up indicator and log file 8/03/2019}