TickLogger

This tool is designed to act as an automated data recorder for your trading platform. Its primary purpose is to capture and save every movement in the market price (known as "ticks") into a structured spreadsheet format that you can review later.

How it Works

1. Automated File Organization When you first launch the script, it automatically creates a new record file on your computer. To keep your data organized, it names this file using the specific currency pair you are trading combined with the current date. This ensures that your logs remain separated by asset and day, preventing data from becoming cluttered.

2. Data Recording Process The script operates in real-time. Every time the market price moves—even by the smallest possible fraction—the tool performs three specific actions:

  • It identifies the exact date and time of the movement.
  • It captures the current "Bid" and "Ask" prices (the sell and buy prices).
  • It writes this information into a comma-separated file (CSV), which is easily opened in software like Microsoft Excel or Google Sheets.

3. Precision Time Formatting To ensure the recorded data is professional and easy to read, the script includes a specialized formatting logic. It automatically adjusts the time stamps so that single digits (like 1:05 AM) are padded with zeros (becoming 01:05). This keeps the columns aligned in your spreadsheet, making it much easier to perform analysis or create charts from the saved history.

4. Seamless Operation The script manages its own resources efficiently. It opens the connection to the file as soon as it starts, stays active to record every update continuously, and safely closes the file connection once you stop the script. This ensures that your data is saved correctly without manual intervention.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
Uses files from the file systemIt writes information to file
12 Views
0 Downloads
0 Favorites
TickLogger
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                   TickLogger.mq4 |
//|                                               Paul Hampton-Smith |
//+------------------------------------------------------------------+

int handle;

int init()
{
   Comment("Waiting for tick");
   handle = FileOpen(Symbol() + TimeToStr(CurTime(),TIME_DATE) + "_tick_log.csv", FILE_CSV|FILE_READ|FILE_WRITE, ',' );
   FileSeek(handle,0,SEEK_END);
   FileWrite(handle,MyTimeToString(CurTime()),Bid,Ask);
}

int deinit()
{
   FileClose(handle);
}

int start()
{
   Comment("Logging ticks");
   FileWrite(handle,MyTimeToString(CurTime()),Bid,Ask);
   return(0);
}

string MyTimeToString(datetime dt)
{
   // output format dd/mm/yyyy mm:hh:ss
   string strDayPad;
   int nDay = TimeDay(dt);
   if (nDay >= 0 && nDay <= 9) strDayPad = "0";
   else strDayPad = "";

   string strMonthPad;
   int nMonth = TimeMonth(dt);
   if (nMonth >= 0 && nMonth <= 9) strMonthPad = "0";
   else strMonthPad = "";
   
   string strHourPad;
   int nHour = TimeHour(dt);
   if (nHour >= 0 && nHour <= 9) strHourPad = "0";
   else strHourPad = "";
   
   string strMinutePad;
   int nMinute = TimeMinute(dt);
   if (nMinute >= 0 && nMinute <= 9) strMinutePad = "0";
   else strMinutePad = "";

   string strSecondPad;
   int nSecond = TimeSeconds(dt);
   if (nSecond >= 0 && nSecond <= 9) strSecondPad = "0";
   else strSecondPad = "";

   return(StringConcatenate(strDayPad,nDay,"/",strMonthPad,nMonth,"/",TimeYear(dt)," ",strHourPad,nHour,":",strMinutePad,nMinute,":",strSecondPad,nSecond));
}

Comments