Download MetaTrader 5

Loading More History Before Running EA

To add comments, please log in or register
d.bignotti
119
d.bignotti  

Hello guys,

i'm building an ea that store PERIOD_M30 mqlRates structure for different symbol and do some statistical calcualtion,  the problem currently is that i need approx 10 000 bar laoded to make my calculation, but the graph has more or less 2000 bars when you laod it the first time or you don't navigate manually in it from right to left. 

 

So now i need to load it manually, is there a way to automate this task in some way?  Right now i can't get value past the 2000 bar already showed, if i try to get value past bar i get error or value=0.

 

I know there's some advice in this post (https://www.mql5.com/en/forum/124619#comment_3253773), but i really need to automate it. 

Problem loading historical data
Problem loading historical data
  • www.mql5.com
Hello, I have some issues loading historical data. I want to test an expert advisor for which I need lots of 1Min Historical data. 1...
honest_knave
Moderator
2326
honest_knave  

From https://docs.mql4.com/series 

If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).
Timeseries and Indicators Access - MQL4 Reference
Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
Timeseries and Indicators Access - MQL4 Reference
d.bignotti
119
d.bignotti  
honest_knave:

From https://docs.mql4.com/series 

Can't really elaborate about this, when i use ArrayCopySeries an the example you mentioned, the function copy approx 2000 bars, not more, if i want more i need to manually load bars navigating the chart. I need 10 000/15 000.

Problem loading historical data
Problem loading historical data
  • www.mql5.com
Hello, I have some issues loading historical data. I want to test an expert advisor for which I need lots of 1Min Historical data. 1...
Fernando Carreiro
2911
Fernando Carreiro  
d.bignotti: Can't really elaborate about this, when i use ArrayCopySeries an the example you mentioned, the function copy approx 2000 bars, not more. I need 10 000/15 000.

The broker may not have more data than that! This is not MT5, but MT4 we are talking about, right?

You can try, increasing the number of bars a Chart has available to you, but it will only be as much as the Broker offers.

If however, the chart you are using for the EA is not M30, then open up an M30 chart, and scroll back as far as you can and see if that is the case.

Then try your EA again, after the chart is filled.

I am suggesting this, because it seems that your code is not properly handling error 4066 and 4073, that requires you to delay the operation until it has had time to collect the data.

I suggest you also see the following thread: https://www.mql5.com/en/forum/158938 (Make sure you read the entire thread, all the way to the end).

Anyone know how to develop a multicurrency indicator ?
Anyone know how to develop a multicurrency indicator ?
  • www.mql5.com
Anyone know how to develop a multicurrency indicator ? I want to choose BETWEEN 1 to 10 different currencies and 5 bars for each currency...
d.bignotti
119
d.bignotti  
Fernando Carreiro:

The broker may not have more data than that! This is not MT5, but MT4 we are talking about, right?

You can try, increasing the number of bars a Chart has available to you, but it will only be as much as the Broker offers.

If however, the chart you are using for the EA is not M30, then open up an M30 chart, and scroll back as far as you can and see if that is the case.

Then try your EA again, after the chart is filled.

I am suggesting this, because it seems that your code is not properly handling error 4066 and 4073, that requires you to delay the operation until it has had time to collect the data.

I suggest you also see the following thread: https://www.mql5.com/en/forum/158938 (Make sure you read the entire thread, all the way to the end).

My broker for m30 currently offer approx 17 000 bar, and yes we are talking about mt4, why do you ask me about mt4 or mt5?

 

The chart i'm using for ea is a casual M30 chart, actually i use iOpen, iHigh ect, and ask the EA to create a custom structure with 50 day of past data  of M30 bar, but value past bar 2000 is empty or wrong.

 

If, as u mentioned I scroll back the chart i get right value of the struct, mqlrates, iClose whatever. I'm not getting problem receiving data, the problem is getting enough data for me to compute.

Maybe i can't explain, my english is really bad. 

 

I'm reading your thread anyway. i'll let you know. 

Fernando Carreiro
2911
Fernando Carreiro  
d.bignotti: My broker for m30 currently offer approx 17 000 bar, and yes we are talking about mt4, why do you ask me about mt4 or mt5?

The chart i'm using for ea is a casual M30 chart, the actually i use iOpen, iHigh ect, and ask the EA to create a custom structure with 50 day of past data  of M30 bar, but value past bar 2000 is empty or wrong.

If, as u mentioned I scroll back the chart i get right value of the struct, mqlrates, iClose whatever.

I'm reading your thread anyway. i'll let you know. 

Is this problem you are having, perhaps only in the Strategy Tester or also on Live?

Either way, you do need to implement the handling of error 4066 and 4073. Also, you should also check the TERMINAL_MAXBARS property, and I quote:

If the whole interval of requested data is out of the available data on the server, the function returns -1. If data outside TERMINAL_MAXBARS (maximal number of bars on the chart) is requested, the function will also return -1.

The reason I asked about MT5 was more of rhetorical query, to call your attention to the fact the MT4 accounts don't usually offer much historical data as opposed to MT5 accounts.

Client Terminal Properties - Environment State - Standard Constants, Enumerations and Structures - MQL4 Reference
Client Terminal Properties - Environment State - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Client Terminal Properties - Environment State - Standard Constants, Enumerations and Structures - MQL4 Reference
d.bignotti
119
d.bignotti  
Fernando Carreiro:

Is this problem you are having, perhaps only in the Strategy Tester or also on Live?

Either way, you do need to implement the handling of error 4066 and 4073. Also, you should also check the TERMINAL_MAXBARS property, and I quote:

The reason I asked about was more of rhetorical query, to call your attention to the fact the MT4 accounts don't usually offer much historical data as opposed to MT5 accounts.

I'm not working on strategy tester, only live.

 

I'll try to explain in different way, my english is really bad probably everyone is understanding a different thing.

I do not get any error using iFunction or mqlRates, the problem is that there's not enough data on the chart to compute until i manually load bar scrolling back the chart, even if i'm trying to use iFuntion and M30 on the Symbol i requested data for i still can't get all the data i need.

Is this caused by error 4066 and 4073? Or is another thing? 

TERMINAL_MAXBARS is 2147483647. 

 

As an example i'm running a simple script ON EURUSD M30

void OnStart()
  {

   Print(ChartGetInteger(ChartID(),CHART_FIRST_VISIBLE_BAR,0));

   Print(iTime(Symbol(),PERIOD_CURRENT,10000));

  }

 

first run i get CHART_FIRST_VISIBLE_BAR =2000 and of course iTime gives me 1970.00.01 00.00 as a date.

the i scroll the chart a bit and i get  CHART_FIRST_VISIBLE_BAR =12350 and now i get the right date.

Fernando Carreiro
2911
Fernando Carreiro  
d.bignotti: I do not get any error using iFunction or mqlRates, the problem is that there's not enough data on the chart to compute until i manually load bar scrolling back the chart, even if i'm trying to use iFuntion and M30 on the Symbol i requested data for i still can't get all the data i need. Is this caused by error 4066 and 4073? Or is another thing? TERMINAL_MAXBARS is 2147483647. 

"mqlRates" is not a function, it is a Data structure! So what function are you using to populate it? Show your code!

We cannot possibly help further as we do not know how you are implementing this "data collection" process or even if you are properly checking the error conditions or not!

EDIT: Your "Chart" example code, further shows that you are not handling processing correctly regarding to Errors 4066 and 4073!

d.bignotti
119
d.bignotti  
Fernando Carreiro:

"mqlRates" is not a function, it is a Data structure! So what function are you using to populate it? Show your code!

We cannot possibly help further as we do not know how you are implementing this "data collection" process or even if you are properly checking the error conditions or not!

EDIT: Your "Chart" example code, further shows that you are not handling processing correctly regarding to Errors 4066 and 4073!

something like this could get rid of every error i'm getting right now?

 

input string symbol="EURAUD";
input int day=1000;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   D1DateTime(day);

  }
//+------------------------------------------------------------------+
//|DayStart Function                                                 |
//+------------------------------------------------------------------+
datetime D1DateTime()
  {

   int count=1;

   datetime time=iTime(symbol,PERIOD_D1,day);//Calculate Time of day
   int err=GetLastError();
   Print("First Error---",(string)err);
   while((err==4066 || err==4073) && !IsStopped())
     {
      time=iTime(symbol,PERIOD_D1,day);
      err=GetLastError();
      Print("Count---",count," Second Error---",(string)err);
      count++;
     }
   if(err==4051) Print("Input too High");
   if(err!=4051 && time==0) Print("Another Error");

   Print("Input---",day,"   Time---",time);
   return(time);
  }
//+------------------------------------------------------------------+


Edit: i'm getting the same error in some cases, i was running the script on EURUSD M15 chart, i was trying to load EURAUD  with 3000 day of input, i was getting error 4051, then when i manuanually opened EURAUD, and scrolled back the chart i was getting nearly 5000 bars. and then when i rerunned the script i was getting the right date for 3000 input.
 

Fernando Carreiro
2911
Fernando Carreiro  

d.bignotti: something like this could get rid of every error i'm getting right now?

Edit: i'm getting the same error in some cases, i was running the script on EURUSD M15 chart, i was trying to load EURAUD  with 3000 day of input, i was getting error 4051, then when i manuanually opened EURAUD, and scrolled back the chart i was getting nearly 5000 bars. and then when i rerunned the script i was getting the right date for 3000 input.

  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:
... During the first 73607 iterations (that lasted approximately 516ms) ...

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.

iBars - Timeseries and Indicators Access - MQL4 Reference
iBars - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iBars - Timeseries and Indicators Access - MQL4 Reference
Gyula Szajlai
110
Gyula Szajlai  
Fernando Carreiro:

The broker may not have more data than that! This is not MT5, but MT4 we are talking about, right?

You can try, increasing the number of bars a Chart has available to you, but it will only be as much as the Broker offers.


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)  .

12
To add comments, please log in or register