Get The very first date in the history on server, How?

 

Hello there,

I'm trying to find out if history of a symbol-timeframe is fully loaded or not within my mql4 expert.

there is this function ...

bool  SeriesInfoInteger( 
   string                     symbol_name,     // symbol name 
   ENUM_TIMEFRAMES            timeframe,       // period 
   ENUM_SERIES_INFO_INTEGER   prop_id,         // property ID 
   long&                      long_var         // variable for getting info 
   );

with this identifier

SERIES_SERVER_FIRSTDATE

The very first date in the history of the symbol on the server regardless of the timeframe

datetime


that shows "The very first date in the history of the symbol on the server regardless of the timeframe" but it is regardless of the timeframe.


Is there a way to identify SERIES_SERVER_FIRSTDATE depending on the timeframe?


regards

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / History Database Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / History Database Properties
  • www.mql5.com
History Database Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

This code works for me. You can give it a try.


// FUNCTION LogAppend ----------------------------------------------
void LogAppend(string filename, string text)   {
   int filehandle=FileOpen(filename,FILE_READ|FILE_SHARE_READ|FILE_WRITE|FILE_TXT|FILE_COMMON);
   FileSeek(filehandle,0,SEEK_END);
   FileWrite(filehandle, text);
   FileClose(filehandle);
}

// FUNCTION FindFirstBar ----------------------------------------------
void FindFirstBar()   {

   string SymbolList [4];
   SymbolList [0] = "SP500";
   SymbolList [1] = "EURUSD";
   SymbolList [2] = "XAUUSD";
   SymbolList [3] = "BTCUSD";

   int TFlist[4];
   TFlist[0] = 60;
   TFlist[1] = 15;
   TFlist[2] = 5;
   TFlist[3] = 1;

   int SymbolIteration = 0;

   while(SymbolIteration < ArraySize(SymbolList)  {
      int TFIteration = 0;
      // ------------ change timeframe ------------
      while(TFIteration < ArraySize(TFlist))      {
         // ------------ detect oldest bar ------------
         int shift = 0;
         int firstbar = 0;
         while(1 > 0)   {
            Timestamp = iTime(SymbolList[SymbolIteration], TFlist[TFIteration], shift);
            if (Timestamp == 0)   {
               firstbar = shift - 1;
               Timestamp = iTime(SymbolList[SymbolIteration], TFlist[TFIteration], firstbar);
               ExactDate = IntegerToString(TimeYear(Timestamp)) + "-" + IntegerToString(TimeMonth(Timestamp)) + "-" + IntegerToString(TimeDay(Timestamp)) + "_" + IntegerToString(TimeHour(Timestamp)) + ":" + IntegerToString(TimeMinute(Timestamp));  
               LogText = "firstbar in TF " + TFlist[TFIteration] + " of " + SymbolList[SymbolIteration] + " is " + firstbar + ", on date " + ExactDate;
               LogAppend(LogFile, LogText);
               break;
            }
            shift++;
         }
         // ------------ collect data below ------------
         // ------------ collect data above ------------
         TFIteration++;
      }
      SymbolIteration++;
   }
}
Reason: