TickDataCollector
Download scriptThis tool is designed to act as a real-time data logger for your trading platform. Its primary purpose is to capture and export live market information into an external file format that can be easily read by other software, such as Excel or Google Sheets.
Here is a breakdown of how the logic works:
Data Collection Process
Whenever the market moves, the script automatically captures six key pieces of information for every one-minute interval:
- Date and Time: When the price action occurred.
- Open Price: The price at the start of the minute.
- High Price: The highest price reached during that minute.
- Low Price: The lowest price reached during that minute.
- Closing Price: The final price at the end of the minute.
- Volume: The amount of trading activity recorded for that period.
How it Functions
- Setup Phase: When you first load the indicator, it automatically identifies which currency pair or asset you are currently viewing. It then attempts to create a dedicated data file on your computer. If it successfully creates this file, it sets up a header row (titles for the data columns) so the information is organized correctly.
- Live Monitoring: As the market runs, the script constantly "watches" the current one-minute candle. Every time the market updates, it grabs the latest figures and writes them as a new line in your data file.
- Cleanup: When you remove the indicator from your chart, the script safely closes the connection to the file to ensure that no data is corrupted and the file is saved properly.
Summary of Use
Essentially, this script serves as a bridge between your trading platform and your personal records. It automates the tedious task of manually recording price movements, providing you with a clean, chronological CSV file of market history for later analysis.
//+------------------------------------------------------------------+
//| PriceQtIndicator.mq4 |
//| linx |
//| https://login.mql5.com/en/users/linx |
//+------------------------------------------------------------------+
#property copyright "linx"
#property link "https://login.mql5.com/en/users/linx"
string symbol;
int handle;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
symbol = Symbol();
handle=FileOpen(symbol+"_tick.csv", FILE_CSV|FILE_WRITE,',');
if (handle>0)
FileWrite(handle, "datatime", "open", "high", "low", "close", "volume");
else
Alert("Failed to open data file. Please check if you have write priviledge!");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
if (handle>0)
FileClose(handle);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//int counted_bars=IndicatorCounted();
//----
if (handle>0) {
FileWrite(handle,iTime(symbol,PERIOD_M1,0), iOpen(symbol,PERIOD_M1,0),
iHigh(symbol,PERIOD_M1,0), iLow(symbol,PERIOD_M1,0),
iClose(symbol,PERIOD_M1,0), iVolume(symbol,PERIOD_M1,0));
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments