collect_forexite_quotes

Author: Copyright � 2007, Mathemat
collect_forexite_quotes
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
0 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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---