Automatically downloading history?

 
I would like to collect .HST files automatically in MT4.
At the moment i click EURUSD -> M1 and then i have to scroll back for MT4 to download data into .HST. Could i somehow do it in MQL4? i have tried to use indicators with high periods, if indicator needs bars which have not been downloaded, it should download them right? But no, it will download some of the data for some reason but not all. For each timeframe i get excatly same amount of candles. For example i get 2052 candles for EURUSD and AUDUSD on M1, but i get 2048 candles for EURUSD and AUDUSD on M5. But i am using period of 4000(max), so it should download 4000 candles...

Every time i run my EA i delete .hst files from VirtualStore/Program files/MT4/history/live. (i use live account)

This is what i am doing in my EA, basically i am just calculating MA and hoping it will download the needed bars:
ma1 = iMA("EURUSD.arm", PERIOD_M1, 4000, 0, MODE_SMMA, PRICE_MEDIAN, 0);

Does anybody have any ideas how i could get all the possible data from the broker?

I already looked into macroing my mouse and keyboard, but it dose not seem a very good solution.
 
olympus999:


Every time i run my EA i delete .hst files from VirtualStore/Program files/MT4/history/live. (i use live account)

Why ?  if you want more history it is not a good idea to delete what you already have and then replace it with less . . .

What do you have  Max bars in history   set to ?

 

From your code you can try to get the history you need by trying to get  the time, open, close, high, or low for a bar  (iTime(), iOpen(), etc),  then check if you have received an error 4066,  if you have wait and then retry,  if you keep getting error 4066 then your Broker does not have the data you need.

 
olympus999: i delete .hst files from VirtualStore/Program files/MT4/history/live. (i use live account)
Don't install in \program files* on Vista/7/8
 
RaptorUK:

Why ?  if you want more history it is not a good idea to delete what you already have and then replace it with less . . .

What do you have  Max bars in history   set to ?

 

From your code you can try to get the history you need by trying to get  the time, open, close, high, or low for a bar  (iTime(), iOpen(), etc),  then check if you have received an error 4066,  if you have wait and then retry,  if you keep getting error 4066 then your Broker does not have the data you need.


I should have added, i deleted history for testing purposes. So that everytime i tried something i would start from 0.

Max bars in history is set to maximum number allowed.

I will try your solution and i will get back to you!

WHRoeder:
Don't install in \program files* on Vista/7/8

It is not installed in program files, history files are stored there. Metatrader itself is in program files(x86). For some reason it puts .HST files in a totaly different place.
 
olympus999:

It is not installed in program files, history files are stored there. Metatrader itself is in program files(x86). For some reason it puts .HST files in a totaly different place.
It's a bad idea to install in   \Program Files *   as you will potentially be affected by UAC issues.  To avoid UAC issues install in a directory such as  C:\MT4Installs\broker_name\  
 
olympus999:

It is not installed in program files, history files are stored there. Metatrader itself is in program files(x86). For some reason it puts .HST files in a totaly different place.
That's the point. Don't install in \program files*
 
RaptorUK:
It's a bad idea to install in   \Program Files *   as you will potentially be affected by UAC issues.  To avoid UAC issues install in a directory such as  C:\MT4Installs\broker_name\  


I did it. Now all my history files are saved "C:\MT4Installs\broker_name\history\demo" . nice :)

I tried iTime and iHigh. They did not work.
Lets focuse on M1 timeframe only, it is the problem one. In M1 i still get 2048 bars. If i try:
double asd = 
iHigh("AUDCAD",PERIOD_M1,2200);
Print(asd);

Output will be zero.

if i try:
double asd = iHigh("AUDCAD",PERIOD_M1,2000);
Print(asd);

I get the right output.

I also tried to geterror. I always got no error. Error code was always 0.
Code i tried with:

double asd = iHigh("AUDCAD.arm",PERIOD_M1,2200);

   int err = GetLastError();

   Print("error(",err,"): ");


When i tried to scroll back chart manually i got ~2500 bars of M1 data from my broker. 

Can somebody give any ideas how i could make it work?

 
olympus999:


I did it. Now all my history files are saved "C:\MT4Installs\broker_name\history\demo" . nice :)

I tried iTime and iHigh. They did not work.
Lets focuse on M1 timeframe only, it is the problem one. In M1 i still get 2048 bars. If i try:


Can somebody give any ideas how i could make it work?

I already told you . . .

RaptorUK:

Why ?  if you want more history it is not a good idea to delete what you already have and then replace it with less . . .

What do you have  Max bars in history   set to ?

 

From your code you can try to get the history you need by trying to get  the time, open, close, high, or low for a bar  (iTime(), iOpen(), etc),  then check if you have received an error 4066,  if you have wait and then retry,  if you keep getting error 4066 then your Broker does not have the data you need.

Where are you testing for error 4066 ?
 
I am confused. What do you mean under "Where are you testing for error 4066 ?"?
i test it in metaquotes. I am running expert advisor. 
This is the code i use to test it:

double asd = iHigh("AUDCAD.arm",PERIOD_M1,2200);

   int err = GetLastError();

   Print("error(",err,"): ");

 

There is no test there, only a print statement.

Why didn't you post the error number? Why didn't you post Bars value also.

 
I always got error code equal to zero, i got no errors.
This function printed out 0 always.

Bars values are also 0 if they are over 2048.
Reason: