collect_forexite_quotes

Download script
Author: Copyright � 2007, Mathemat
collect_forexite_quotes

This script is designed to automate the process of gathering historical financial data from a specific web source (Forexite.com) and consolidating it into a single, organized file that you can use within the MetaTrader platform.

Instead of having to manually open, copy, and paste hundreds of individual daily files one by one, this tool handles that labor for you automatically. Here is a breakdown of how it works:

Data Collection Process

The script follows a structured "search and gather" logic based on the date range you provide:

  • Target Selection: You define which currency pair (symbol) you want to track (for example, Gold/XAUUSD) and the specific start and end dates for your historical data.
  • Automated File Navigation: The tool looks into a specific folder on your computer where the daily files are stored. It moves through the calendar day-by-day, automatically constructing the correct filename for each date to match the source website's naming convention.
  • Smart Filtering: As it reads through the data, the script acts as a filter. It scans all information within the daily files but only extracts the rows that match your chosen currency pair. This ensures that your final report isn't cluttered with irrelevant data.
  • Weekend Handling: The logic includes a built-in check to recognize weekends. Since financial markets are closed on Saturdays and Sundays, the script is programmed to skip those dates automatically to avoid errors or empty files.

Output & Efficiency

Once the script has finished scanning all valid files within your chosen timeframe, it performs the following actions:

  • Consolidation: It takes all the relevant data points it found across multiple days and writes them into one continuous master file (saved as a .csv format).
  • Real-Time Progress: While the script is running, it provides visual feedback on your screen, showing you how many days it has successfully processed so far.
  • Finalization: Once the task is complete, it closes all connections and leaves you with a single, clean file ready for analysis or use in your trading strategies.
Price Data Components
Series array that contains open time of each bar
Miscellaneous
It reads information from a fileUses files from the file systemIt writes information to file
12 Views
0 Downloads
0 Favorites
collect_forexite_quotes
//+------------------------------------------------------------------+
//|                                      import_forexite_history.mq4 |
//|                                       Copyright © 2007, Mathemat |
//|                                                                  |
//+------------------------------------------------------------------+

/* Íà îñíîâå îáðàáîòêè òåêñòîâûõ ôàéëîâ ñ forexite.com â ôîðìàòå äëÿ Ìåòàñòîêà âûáèðàåò
òîëüêî êîòèðîâêè íóæíîãî èíñòðóìåíòà è ñîáèðàåò èõ â îäèí ôàéë. Äàòû èç òåêóùåãî òûñÿ÷åëåòèÿ. */

#property copyright "Copyright © 2007, Mathemat"
#property show_inputs

extern string _sSymbol  = "XAUUSD";
extern string _fromDate = "2002.01.01";
extern string _toDate   = "2007.06.13";


/* ñ÷èòûâàåò âñå èç îäíîãî ôàéëà, ôîðìèðóÿ äëèííóþ ñòðîêó ñ ðàçäåëèòåëÿìè */
string ReadAllStrings( int handle, string ss )
{
   string s; 
   string res = "";
   while(!FileIsEnding( handle ) )
   {
      s = FileReadString( handle );
      if ( StringFind( s, ss ) > -1 )  res = res + s + "\n";
   }
   return ( StringTrimRight( res ) );
}



/* äàòû âî âíóòðåííåì ôîðìàòå ÌÒ4. Âîçâðàùàåò ñëåäóþùóþ ïðàâèëüíóþ äàòó 
âî âíóòðåííåì ñòðîêîâîì ôîðìàòå. */
string nextDayInternal( string curDayInternal )
{
   string res = TimeToStr( StrToTime( curDayInternal ) + 1440 * 60, TIME_DATE );
   return( res );
}



/* Ïåðåâîäèò äàòó â ôîðìàòå YYYY.MM.DD (âíóòðåííèé ÌÒ4) â ôîðìàò èìåíè ôàéëà ñ Forexite.com */
string InternalDateToForexiteFilename( string dateInternal )
{
   datetime dt = StrToTime( dateInternal );
   
   string sDay   = DoubleToStr( TimeDay( dt ), 0 );
   if ( StringLen( sDay ) == 1 ) sDay = "0" + sDay;
   
   string sMonth = DoubleToStr( TimeMonth( dt ), 0 ) ;
   if ( StringLen( sMonth ) == 1 ) sMonth = "0" + sMonth;
   
   string sYear  = StringSubstr( DoubleToStr( TimeYear( dt ), 0 ), 2, 2 );
   
   return( sDay + sMonth + sYear + ".txt" );
}


int start()
{
   int counterOpened = 0;
   string filename;
   string fileWritten;
   string s;
   string path = "\\Forexite\\";
   int handleWritten = FileOpen( _sSymbol + "_ALL.csv", FILE_CSV|FILE_WRITE, " " );
   
   string sDate = _fromDate;
   while( StrToTime( sDate ) <= StrToTime( _toDate ) )
   {
      filename = InternalDateToForexiteFilename( sDate );
      if ( MathAbs( TimeDayOfWeek( StrToTime( sDate ) ) - 3 ) == 3 )  
      {
         sDate = nextDayInternal( sDate );
      }   
      else   
      {
         int handle = FileOpen( path + filename, FILE_CSV | FILE_READ );
         if ( handle < 0 )    
         {
            Print( filename + ": no file present" ); 
            sDate = nextDayInternal( sDate );
         }   
         else               
         {
            counterOpened++;
            s = ReadAllStrings( handle, _sSymbol );
            FileWrite( handleWritten, s );
            FileClose( handle );
            FileFlush( handleWritten );
            Comment( "Days processed: " + counterOpened );
            sDate = nextDayInternal( sDate );
         }   
      }   
   }   
   FileClose( handleWritten );
   Comment( "" );
   return(0);
}

Comments