Download history in MQL4 EA - page 2

 

fly7680: will the data be downloaded again from the Broker server?

When data is downloaded from the server, are it allocated to the Ram on PC or to another folder? I say this because as long as the MT4 is open, in the AppData \ Roaming \ MetaQuotes \ Terminal \ A6DFBB1B8DE9672D2328FF3445436DEC \ history folder there is no data, when the MT4 is closed, the data is actually copied to that folder

  1. It will be updated.
  2. Terminal caches the data instead of writing to the disk a hundred thousand times per day. Why are you looking at its internals? When you get into a cab/Uber/etc. do you just ride or do you ask the driver for a colonoscopy?
 
whroeder1:
  1. It will be updated.
  2. Terminal caches the data instead of writing to the disk a hundred thousand times per day. Why are you looking at its internals? When you get into a cab/Uber/etc. do you just ride or do you ask the driver for a colonoscopy?
thanks for the answer whroeder1 but I did not understand the second answer sorry what do you mean?
 

hello

this code solved my problem

 
Samih Abdelli:

hello

this code solved my problem


do you have an example of your code?
 
Ingvar Engelbrecht:

I need 15M 1H 4H 1D 1W  for all 28 pairs for 30 periods back in my EA.

I have used a very good tool in MQL5 published  here but is there a way of doing this in MQl4?

Thank you for this discussion, It also very useful to me too.. chaiya
 
fly7680:


do you have an example of your code?

Yes I have


//+------------------------------------------------------------------+
//|                                              DownloadHistory.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window

#define HR2400 PERIOD_D1 * 60    // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
#define SYMBOL string
#define THIS_SYMBOL ""
//+------------------------------------------------------------------+
int OnInit()
  {
//---



//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
if(!download_history(PERIOD_CURRENT) ) return prev_calculated;

 
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
bool  download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   return download_history(_Symbol, period); 
}
//+------------------------------------------------------------------+
bool  download_history(
      SYMBOL            symbol=THIS_SYMBOL,
      ENUM_TIMEFRAMES   period=PERIOD_CURRENT){
   if(symbol == THIS_SYMBOL)     symbol = _Symbol;
   if(period == PERIOD_CURRENT)  period = _Period;
   datetime today = DateOfDay();
   ResetLastError();
   datetime other = iTime(symbol, period, 0);
   if(_LastError == 0 && today == DateOfDay(other)) return true;   
   if(_LastError != ERR_HISTORY_WILL_UPDATED && _LastError != ERR_NO_HISTORY_DATA)
      Print(StringFormat("iTime(%s,%i) Failed: %i", symbol, period,_LastError));
   return false;
}
//+------------------------------------------------------------------+
 
   if(_LastError == 0 
   && today == DateOfDay(other)) return true;

Douglas Eiras found a problem with the above code. If the period is weekly or monthly, obviously today's date won't equal the start of the bar. Remove the second test.

 

So, if I understand well, this function download_history() is only puting the time of the last candle into the variable "other", then we check if it is the day/hour/minute we actually are now. and it does that until the answer is the good one.

When the function call iTime() function, it will automatically force mt4 to download the history.

Is that correct ?
 
Samih Abdelli:

Yes I have


Thank you for share it
 
Charly Oudy: When the function call iTime() function, it will automatically force mt4 to download the history. Is that correct ?

Any candle related function does that. The test is for the error and not to continue until download completes.

Reason: