Bibliothèque: Chargeur d'histoire

 

Chargeur d'histoire:

Module fonctionnel de l'Expert Advisor multidevise pour organiser l'accès à toute donnée historique avec traitement du résultat de la requête.

Author: Nikolay Kositsin

 
Automated-Trading:

HistoryLoader:

Auteur : Nikolay Kositsin

Erreur de syntaxe à la ligne 91 (H manquant)."SERIES_SYNCRONIZED" devrait être "SERIES_SYNCHRONIZED".
 
elib:
Erreur de syntaxe à la ligne 91 (H manquant). "SERIES_SYNCRONIZED" devrait être "SERIES_SYNCHRONIZED".

Rien ne dure éternellement sous la lune !

//+------------------------------------------------------------------+
//| vérification de l'historique pour le téléchargement|
//+------------------------------------------------------------------+
int CheckLoadHistory(string symbol,ENUM_TIMEFRAMES period,datetime start_date)
  {
//----+
   datetime first_date=0;
   datetime times[100];
//--- vérifier le symbole et la période
   if(symbol == NULL || symbol == "") symbol = Symbol();
   if(period == PERIOD_CURRENT)     period = Period();
//--- vérifier si le symbole est sélectionné dans le MarketWatch
   if(!SymbolInfoInteger(symbol,SYMBOL_SELECT))
     {
      if(GetLastError()==ERR_MARKET_UNKNOWN_SYMBOL) return(-1);
      if(!SymbolSelect(symbol,true)) Print(__FUNCTION__,"() : Échec de l'ajout du caractère ",symbol,"dans la fenêtre de MarketWatch !!!");
     }
//--- vérifier si les données sont présentes
   SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date);
   if(first_date>0 && first_date<=start_date) return(1);
//--- ne pas demander le chargement de ses propres données s'il s'agit d'un indicateur
   if(MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR && Period()==period && Symbol()==symbol)
      return(-4);
//--- deuxième tentative
   if(SeriesInfoInteger(symbol,PERIOD_M1,SERIES_TERMINAL_FIRSTDATE,first_date))
     {
      //--- il y a des données chargées pour construire des séries temporelles
      if(first_date>0)
        {
         //--- forcer la construction de séries temporelles
         CopyTime(symbol,period,first_date+PeriodSeconds(period),1,times);
         //--- date de vérification
         if(SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date))
            if(first_date>0 && first_date<=start_date) return(2);
        }
     }
//--- nombre maximum de barres dans le graphique à partir des options du terminal
   int max_bars=TerminalInfoInteger(TERMINAL_MAXBARS);
//--- Chargement de l'historique des symboles
   datetime first_server_date=0;
   while(!SeriesInfoInteger(symbol,PERIOD_M1,SERIES_SERVER_FIRSTDATE,first_server_date) && !IsStopped())
      Sleep(5);
//--- fixer la date de début du chargement
   if(first_server_date>start_date) start_date=first_server_date;
   if(first_date>0 && first_date<first_server_date)
      Print(__FUNCTION__,"(): Warning: first server date ",first_server_date," for ",symbol,
            " does not match to first series date ",first_date);
//--- charger les données étape par étape
   int fail_cnt=0;
   while(!IsStopped())
     {
      //--- attendre la construction de la série temporelle
      while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStopped())
         Sleep(5);
      //--- demander des barres construites
      int bars=Bars(symbol,period);
      if(bars>0)
        {
         if(bars>=max_bars) return(-2);
         //--- demande de premier rendez-vous
         if(SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date))
            if(first_date>0 && first_date<=start_date) return(0);
        }
      //--- la copie de la partie suivante force le chargement des données
      int copied=CopyTime(symbol,period,bars,100,times);
      if(copied>0)
        {
         //--- vérification des données
         if(times[0]<=start_date) return(0);
         if(bars+copied>=max_bars) return(-2);
         fail_cnt=0;
        }
      else
        {
         //--- pas plus de 100 tentatives infructueuses
         fail_cnt++;
         if(fail_cnt>=100) return(-5);
         Sleep(10);
        }
     }
//----+stopped
   return(-3);
  }
//+------------------------------------------------------------------+
 

Il ne fonctionne pas, il meurt au premier caractère....

Voici le code

//+------------------------------------------------------------------+ 
//|TestLoadHistory.mq5 | 
//| Copyright 2009, MetaQuotes Software Corp. 
//| https ://www.mql5.com 
//+------------------------------------------------------------------+ 
#property copyright "2009, MetaQuotes Software Corp." 
#property link      "https://www.mql5.com" 
#property version   "1.02" 
#property script_show_inputs 

//--- paramètres d'entrée 

//+------------------------------------------------------------------+ 
//| Fonction de démarrage du programme de script| 
//+------------------------------------------------------------------+ 
void OnStart()
  {


   int      all_symbols=SymbolsTotal(false);   string  sym_name="";
   Print("Load symbols ",all_symbols);

   for(int k=0;k<all_symbols;k++)
      if((sym_name=SymbolName(k,false))!="")
        {
         SymbolSelect(sym_name,true);

         Print(k," Symbol name ",sym_name);

datetime time= (TimeCurrent()-60*60*24*5);


         int res=CheckLoadHistory(sym_name,PERIOD_M1,time);

         switch(res)
           {
            case -1 : Print("Unknown symbol ",sym_name);             break;
            case -2 : Print("Requested bars more than max bars in chart ",sym_name); break;
            case -3 : Print("Program was stopped ",sym_name);                        break;
            case -4 : Print("Indicator shouldn't load its own data ",sym_name);      break;
            case -5 : Print("Load failed ",sym_name);                                break;
            case  0 : Print("Loaded OK ",sym_name);                                  break;
            case  1 : Print("Loaded previously ",sym_name);                          break;
            case  2 : Print("Loaded previously and built ",sym_name);                break;
            default : Print("Unknown result ",sym_name);
           }

         datetime first_date;
         SeriesInfoInteger(sym_name,PERIOD_M1,SERIES_FIRSTDATE,first_date);
         int bars=Bars(sym_name,PERIOD_M1);
         Print("First date ",first_date," - ",bars," bars");
       }
//--- 

//--- 
  }
//+------------------------------------------------------------------+
//| vérification de l'historique pour le téléchargement|
//+------------------------------------------------------------------+
int CheckLoadHistory(string symbol,ENUM_TIMEFRAMES period,datetime start_date)
  {
//----+
   datetime first_date=0;
   datetime times[100];
//--- vérifier le symbole et la période
   if(symbol == NULL || symbol == "") symbol = Symbol();
   if(period == PERIOD_CURRENT)     period = Period();
//--- vérifier si le symbole est sélectionné dans le MarketWatch
   if(!SymbolInfoInteger(symbol,SYMBOL_SELECT))
     {
      if(GetLastError()==ERR_MARKET_UNKNOWN_SYMBOL) return(-1);
      if(!SymbolSelect(symbol,true)) Print(__FUNCTION__,"() : Échec de l'ajout du caractère ",symbol,"dans la fenêtre de MarketWatch !!!");
     }
//--- vérifier si les données sont présentes
   SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date);
   if(first_date>0 && first_date<=start_date) return(1);
//--- ne pas demander le chargement de ses propres données s'il s'agit d'un indicateur
   if(MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR && Period()==period && Symbol()==symbol)
      return(-4);
//--- deuxième tentative
   if(SeriesInfoInteger(symbol,PERIOD_M1,SERIES_TERMINAL_FIRSTDATE,first_date))
     {
      //--- il y a des données chargées pour construire des séries temporelles
      if(first_date>0)
        {
         //--- forcer la construction de séries temporelles
         CopyTime(symbol,period,first_date+PeriodSeconds(period),1,times);
         //--- date de vérification
         if(SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date))
            if(first_date>0 && first_date<=start_date) return(2);
        }
     }
//--- nombre maximum de barres dans le graphique à partir des options du terminal
   int max_bars=TerminalInfoInteger(TERMINAL_MAXBARS);
//--- Chargement de l'historique des symboles
   datetime first_server_date=0;
   while(!SeriesInfoInteger(symbol,PERIOD_M1,SERIES_SERVER_FIRSTDATE,first_server_date) && !IsStopped())
      Sleep(5);
//--- fixer la date de début du chargement
   if(first_server_date>start_date) start_date=first_server_date;
   if(first_date>0 && first_date<first_server_date)
      Print(__FUNCTION__,"(): Warning: first server date ",first_server_date," for ",symbol,
            " does not match to first series date ",first_date);
//--- charger les données étape par étape
   int fail_cnt=0;
   while(!IsStopped())
     {
      //--- attendre la construction de la série temporelle
      while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStopped())
         Sleep(5);
      //--- demander des barres construites
      int bars=Bars(symbol,period);
      if(bars>0)
        {
         if(bars>=max_bars) return(-2);
         //--- demande de premier rendez-vous
         if(SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date))
            if(first_date>0 && first_date<=start_date) return(0);
        }
      //--- la copie de la partie suivante force le chargement des données
      int copied=CopyTime(symbol,period,bars,100,times);
      if(copied>0)
        {
         //--- vérification des données
         if(times[0]<=start_date) return(0);
         if(bars+copied>=max_bars) return(-2);
         fail_cnt=0;
        }
      else
        {
         //--- pas plus de 100 tentatives infructueuses
         fail_cnt++;
         if(fail_cnt>=100) return(-5);
         Sleep(10);
        }
     }
//----+stopped
   return(-3);
  }
//+------------------------------------------------------------------+

et il meurt ici

while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStopped())
 

Bonjour Nikolay

Historyloader.mqh a seulement une fonction de

int CheckLoadHistory(string symbol,ENUM_TIMEFRAMES period,datetime start_date)

il n'a pas de fonction Loadhistory() comme mentionné.
 
Nikolay Kositsin:

Rien ne dure éternellement sous la lune !

Merci beaucoup, ça marche pour moi !