CheckLoadHistory examples in Indicator MQL5

 

Hey everyone. Greetings from Down Under.

I have been trying to implement an indicator that downloads higher timeframe price data in MQL5. I have used various versions of the CheckLoadHistory() functions, including this one https://www.mql5.com/en/docs/series/timeseries_access and this one https://www.mql5.com/en/code/1251.

The first one is written as a script and works perfectly, when used as a script. I have tried it as both a function and embedded within the indicator but it only works AFTER recompiling of the Indicator. 

The second one is written as a function and I have the same problem. When the indicator is first attached to the chart, it returns zero bars. If after attachment I compile the indicator again, it then downloads the HTF bars.

Incidentally, they seem to work fine from EA's.

I fully expect that I am missing something obvious here. Nonetheless  I am wondering if:

1) has anyone experienced this same problem?

2) and does anyone have an example of a working CheckLoadHistory() function implemented in an Indicator?


Hopefully my amateur description is not too cryptic and someone out there has had this issue before me and figured out how to make it work. 

Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
  • www.mql5.com
Before price data become available in the MetaTrader 5 terminal, they must be received and processed. To receive data, connection to the MetaTrader 5 trade server must be established. Data are received in the form of packed blocks of minute bars from the server upon the request of a terminal. The mechanism of server reference for data doesn't...
 

Just by way of further explanation:

- I have looked at multiple MTF indicators on here and have not found one that uses LoadCheckHistory(). They appear to use CopyRates() and CopyBuffer() directly. However everything that I have read is telling me that it is critical to assemble the HTF data first!

- I contemplated calling the CheckLoadHistory() script from the indicator, but this appears to be well beyond my self-taught programming skills.



cheers

 
I was also trying to use CheckLoadHistory() in an indicator and it didn't work. From what I understand the problem is that there are Sleep() commands in that function, that don't work when they are called from an indicator. See https://www.mql5.com/en/docs/common/sleep. Therefore I switched to call that function from an EA.
Documentation on MQL5: Common Functions / Sleep
Documentation on MQL5: Common Functions / Sleep
  • www.mql5.com
Sleep - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5