Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
MetaQuotes Software Corp.
Moderator
181005
MetaQuotes Software Corp. 2008.01.28 11:01 

Tick Collector 'TickSave':

The Expert Advisor collects tick history for specified symbols into csv-files.

Author: Andrey Khatimlianskii

davidb012
67
davidb012 2008.02.11 22:00  
This is a great idea, unfortunately, I can't get it to do anything! Maybe something wrong with the code or with the way I installed it, but its not creating any .csv files anywhere on my pc.
MQL4 Comments
16319
MQL4 Comments 2008.03.19 05:40  
Works perfect for me, you might want to check under your install folder, it will be in \experts\files\[Ticks]
MQL4 Comments
16319
MQL4 Comments 2009.04.13 11:48  

Hi komposter,

Thanks for your TickSave code. It appears to work fine under Windows XP, but not under Vista. There, I think it would need some rights to create the directories and files. Could you adapt the code for Vista?

Also, I would like to have some volume information. However, I think MT4 does not provide volumes at the tick level. Is this correct? Is there a way around, perhaps?

Thank you & regards,

Andrei

MQL4 Comments
16319
MQL4 Comments 2010.11.23 09:21  

Unfortunately depending on currency you put this EA on it has potential to loose lots of ticks of other currencies. I solved that problem by putting my EA on each currency I want to record, it gives much more reliable recording.

//+------------------------------------------------------------------+
//|                                        Tick_recorder_v2.mq4      |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Jake"
#property link      ""
#property show_inputs
extern   string realfolder="real";
extern   string testfolder="test";
int         fh;
datetime    lasttime;
double      volume,lastvolume;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
   if(StringLen(StringTrimRight(realfolder))==0)realfolder="real";
   if(StringLen(StringTrimRight(testfolder))==0)testfolder="test";
   lasttime=StrToTime(TimeYear(TimeCurrent()-DayOfWeek()*60*60*24)+"."+TimeMonth(TimeCurrent()-DayOfWeek()*60*60*24)+"."+TimeDay(TimeCurrent()-DayOfWeek()*60*60*24));
   if(IsTesting())
   {
      fh=FileOpen(file_name()+"_ticks.tic",FILE_WRITE|FILE_BIN);
      FileClose(fh);
   }
   fh=FileOpen(file_name()+"_ticks.tic",FILE_WRITE|FILE_READ|FILE_BIN);
   if(fh==-1) {Print("cannot open file");return(-1);}
   bool b=FileSeek(fh,0,SEEK_END); 
   lastvolume=Volume[0];
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   FileFlush(fh);
   FileClose(fh);      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   if(fh==-1) {Print("no file");return(-1);}
   datetime currenttime=StrToTime(TimeYear(TimeCurrent()-DayOfWeek()*60*60*24)+"."+TimeMonth(TimeCurrent()-DayOfWeek()*60*60*24)
   +"."+TimeDay(TimeCurrent()-DayOfWeek()*60*60*24));
   if(lasttime<currenttime)
   {
      lasttime=currenttime;
      FileFlush(fh);
      FileClose(fh);
      if(IsTesting())
      {
         fh=FileOpen(file_name()+"_ticks.tic",FILE_WRITE|FILE_BIN);
         FileClose(fh);
      }
      fh=FileOpen(file_name()+"_ticks.tic",FILE_WRITE|FILE_READ|FILE_BIN);
   }         
//----
   if(lastvolume>Volume[0])
   {
      lastvolume=Volume[0];
      volume=Volume[0];
   }
   else
   {
      volume=Volume[0]-lastvolume;
      lastvolume=Volume[0];
   }
   if(volume==0)volume=1;
   int k=FileWriteInteger(fh,TimeCurrent());
   int l=FileWriteDouble(fh,Bid);
   int m=FileWriteDouble(fh,Ask);
   int n=FileWriteDouble(fh,volume);

//----
   return(0);
}
string file_name()
{
   int day1,month1;
   string year=TimeYear(lasttime);
   month1=TimeMonth(lasttime);
   if(month1<10)string month="0"+month1; else month=month1;
   day1=TimeDay(lasttime);
   if(day1<10)string day="0"+day1; else day=day1;
   string filename=(Symbol()+StringTrimRight("\\ ")+year+StringTrimRight("\\ ")+Symbol()+year+month+day);
   if(IsTesting())
   {
      filename=StringTrimRight(testfolder+"\\ ")+filename;
   }
   else
   {
      filename=StringTrimRight(realfolder+"\\ ")+filename;
   }
   return(filename);
}
//+------------------------------------------------------------------+
MQL4 Comments
16319
MQL4 Comments 2011.12.03 06:20  
thk for share,.but why it only works on the symbol EURUSD, and it does not work on another chart?
/
To add comments, please log in or register