Loading More History Before Running EA - page 2

 
Gyula Szajlai: No matter which broker, no matter how high is the number of bars, MT4 downloads only 2048 bars data when automated.

When I need more I must scroll back manually on each symbol/timeframe chart.

If I don't do this I will never get the real value for example iHigh(Symbol(), Period(), 5000)  .

That is why I wrote and I quote:
... and you notice that only by scrolling the chart, you are able to obtain more bars, consider scrolling it programmatically in your EA with "ChartNavigate()".
ChartNavigate - Chart Operations - MQL4 Reference
ChartNavigate - Chart Operations - MQL4 Reference
  • docs.mql4.com
ChartNavigate - Chart Operations - MQL4 Reference
 
Fernando Carreiro:
  1. You should be using "iBars()" to first find out how many bars are available and if "day" is within that range. That is why you are getting Error 4051.
  2. After the 4066 or 4073 error, a simple count delay is not enough and you will also have to put a time delay with "Sleep()". You can see this in the tests I did on the thread I linked:

Also, should the iteration and sleep delays not be enough and you notice that only by scrolling the chart, you are able to obtain more bars, consider scrolling it programmatically in your EA with "ChartNavigate()".

PS! Also, consider using "CopyRates()" or "ArrayCopyRates()" instead.

mmh, the count is just an information actually, to count how many times the WHILE loop has runned before getting a value that is not error 4066 and 4073.

 

 Also, should the iteration and sleep delays not be enough and you notice that only by scrolling the chart, you are able to obtain more bars, consider scrolling it programmatically in your EA with "ChartNavigate()".

 

That is my friend, since the beginning of the thread i aws asking for something to automate the chart scrolling, that is the problem, getting value of bars that i can get only if scroll the chart. Or if i add an absurd delay like 60000 i can get value with a normal function? I'll try this. 

 

What's the difference using the mqlRates structure? I'm using iFunction currently. 

 
d.bignotti: mmh, the count is just an information actually, to count how many times the WHILE loop has runned before getting a value that is not error 4066 and 4073.

Also, should the iteration and sleep delays not be enough and you notice that only by scrolling the chart, you are able to obtain more bars, consider scrolling it programmatically in your EA with "ChartNavigate()".

That is my friend, since the beginning of the thread i aws asking for something to automate the chart scrolling, that is the problem, getting value of bars that i can get only if scroll the chart. Or if i add an absurd delay like 60000 i can get value with a normal function? I'll try this. 

What's the difference using the mqlRates structure? I'm using iFunction currently. 

Then why did you not read up on the Chart Operations in the documentation? It has an entire section devoted to that subject!

As for "mqlRates", it is more compatible with MQL5, and since it is an Array, it is more code efficient than using function calls (hence why I suggested using "CopyRates()" or "ArrayCopyRates()" instead).

Also, 60000 is an absurd delay if you are talking about milliseconds and not loop counts. My test delays were just 561 ms (which is about 1/2 second)! If you are talking loop counts, then use "Sleep()" as I explained.

CopyRates - Timeseries and Indicators Access - MQL4 Reference
CopyRates - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
CopyRates - Timeseries and Indicators Access - MQL4 Reference
 
Fernando Carreiro:

Then why did you not read up on the Chart Operations in the documentation? It has an entire section devoted to that subject!

As for "mqlRates", it is more compatible with MQL5, and since it is an Array, it is more code efficient than using function calls (hence why I suggested using "CopyRates()" or "ArrayCopyRates()" instead).

Also, 60000 is an absurd delay if you are talking about milliseconds and not loop counts. My test delays were just 561 ms (which is about 1/2 second)! If you are talking loop counts, then use "Sleep()" as I explained.

Ok thank you very much, i'll report back if i have any other question!
 
d.bignotti: Ok thank you very much, i'll report back if i have any other question!
By the way, the "CopyRates()" function allows you to specify, how many bars to collect, so try it before resorting to the Chart Scroll work-around.
 

If you do go with ChartNavigate, from my experience you have to keep calling it until you hit Max Bars in Chart (or the broker history limit, I guess). It seems to jump in 197 bar intervals.

Example on a fresh chart opened with no pre-existing history: 

#property strict

void OnStart()
  {
   ChartSetInteger(0,CHART_AUTOSCROLL,false);
   long maxbars=TerminalInfoInteger(TERMINAL_MAXBARS);
   printf("Max bars: %i", maxbars);
   printf("Chart starts with %i bars",Bars);
   for(int try=0; try<1000 && Bars<maxbars; try++)
     {
      RefreshRates();
      ChartNavigate(0,CHART_BEGIN,-10000);
      printf("Chart currently has %i bars",Bars);
      Sleep(50);
     }
   printf("Chart ends with %i bars",Bars);
  }

 

 
Fernando Carreiro:
By the way, the "CopyRates()" function allows you to specify, how many bars to collect, so try it before resorting to the Chart Scroll work-around.

As far as I know, CopyRates will only go as far back as there are bars on the chart.

Using my example above, you would only get 2048 rates copied even if you specified a higher number in CopyRates(). 

 
honest_knave: As far as I know, CopyRates will only go as far back as there are bars on the chart.

Using my example above, you would only get 2048 rates copied even if you specified a higher number in CopyRates(). 

Thanks! I also started to think that was the case, but since I have never needed that many bars of history before in my own EAs, I have never run into this problem before myself.
Reason: