logtickdata

Author: Copyright � 2014, matija14
logtickdata

This script is designed to serve as a real-time data logger for your trading platform. Its primary purpose is to capture and record every individual price update—known as a "tick"—for a specific financial instrument and save that information into a structured file on your computer.

How the Logic Works

1. Initialization and File Setup When you first load this script onto your chart, it automatically prepares a dedicated data file. It creates a CSV file (a standard spreadsheet-friendly format) named specifically after the currency pair or asset you are currently viewing. The system ensures that it doesn't overwrite existing data; instead, it moves to the end of the file to begin recording new information.

2. Real-Time Monitoring The script operates in the background of your trading platform. Every time the market price fluctuates—even by the smallest possible amount—the script triggers an action. It "listens" for these movements continuously without requiring any manual input from you.

3. Data Capture For every single price movement detected, the script captures two specific pieces of information:

  • The Exact Timestamp: The precise date and time the price change occurred.
  • The Current Price: The most recent "Bid" price (the price at which you could sell) at that exact micro-moment.

4. Saving and Syncing The script then writes these two pieces of data into your CSV file, separated by a semicolon to keep the columns organized. A crucial part of its logic is the "flush" command: this ensures that the data is written to your hard drive immediately. This prevents data loss in the event of a software crash or power outage, ensuring that every tick captured up until that second is safely saved.

5. Cleanup When you remove the script from your chart or close the program, it performs a clean shutdown by properly closing the file connection and removing any status messages from your screen, leaving your data file ready to be opened in programs like Excel for further analysis.

Miscellaneous
Uses files from the file systemIt writes information to file
13 Views
0 Downloads
0 Favorites
logtickdata
//+------------------------------------------------------------------+
//|                                                  LogTickData.mq4 |
//|                                       Copyright © 2014, matija14 |
//|                                              matija14@gmail.com  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, matija14"
#property link      "matija14@gmail.com"
#property version   "1.0"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Input Parameters Definition                                      |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Local Parameters Definition                                      |
//+------------------------------------------------------------------+
string lbl = "LogTickData.";
int handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
  //------------------------------------------------------------------
  handle = FileOpen("TickData_"+Symbol()+".csv", FILE_CSV|FILE_WRITE|FILE_READ|FILE_SHARE_READ);
  if (handle > 0) FileSeek(handle, 0, SEEK_END);
  Comment("logging tick data...");
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  //------------------------------------------------------------------
  if (handle > 0) FileClose(handle);
  Comment("");
  //------------------------------------------------------------------
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[]         // Spread
)
{
  //------------------------------------------------------------------
  FileWrite(handle, TimeToStr(TimeCurrent())+";"+DoubleToStr(Bid, _Digits));
  FileFlush(handle);
  //------------------------------------------------------------------
  return (rates_total);
}
//+------------------------------------------------------------------+

Comments