Close_to_File2
Download scriptThis script is designed to automate the process of exporting historical market data from your trading platform into external files. Rather than requiring you to manually copy and paste data from various charts, it systematically gathers specific information and saves it into a structured format for later use in spreadsheets or other analytical tools.
Core Functionality
The primary purpose of this tool is to "scrape" price history for a predefined list of currency pairs. It scans through multiple timeframes simultaneously, ensuring that you have a comprehensive dataset without having to switch between different windows manually.
How it Works
- Target Assets: The script is configured to monitor a specific group of major currency pairs (such as GBPUSD, EURUSD, AUDUSD, EURCHF, and EURJPY).
- Multi-Timeframe Coverage: For every currency pair listed, the script automatically gathers data across four distinct time intervals: 1-minute, 5-minute, 1-hour, and 4-hour periods.
- Data Collection: For every historical candle available in these timeframes, the script captures six essential pieces of market information:
- The exact time of the price point.
- The opening price.
- The lowest price reached.
- The highest price reached.
- The closing price.
- The trading volume.
- Automated Export: Once the data is collected, the script generates individual CSV files for each currency and timeframe combination. These files are named dynamically (for example, using the currency name combined with the timeframe) so that your saved data remains organized and easy to locate.
Practical Use Case
This tool is ideal for traders or analysts who need to perform "offline" analysis. By running this script, you can quickly populate a folder with clean, organized data files. This allows you to move your technical analysis out of the trading platform and into a spreadsheet where you can perform complex calculations, custom charting, or long-term historical audits.
//+------------------------------------------------------------------+
//| RSI_to_File.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.ru/"
#define NR_SYMB 6
#property show_inputs
string SymbolsArray[NR_SYMB]={"","GBPUSD","EURUSD","AUDUSD","EURCHF","EURJPY"};
//+------------------------------------------------------------------+
//| string SymbolByNumber |
//+------------------------------------------------------------------+
string GetSymbolString(int Number)
{
//----
string res="";
res=SymbolsArray[Number];
//----
return(res);
}
//+------------------------------------------------------------------+
//| âîçâðàùàåò ïåðèîä |
//+------------------------------------------------------------------+
/*
int PeriodNumber(int number)
{
int per_min;
switch (number)
{
case 0: per_min=PERIOD_M1;break;
case 1: per_min=PERIOD_M5;break;
case 2: per_min=PERIOD_M15;break;
case 3: per_min=PERIOD_M30;break;
case 4: per_min=PERIOD_H1;break;
case 5: per_min=PERIOD_H4;break;
default: per_min=PERIOD_D1;break;
}
return(per_min);
}
*/
//+------------------------------------------------------------------+
//| âûâîäèò â ôàéë êîòèðîâêè + çíà÷åíèÿ èíäèêàòîðà |
//+------------------------------------------------------------------+
void RSI_output(string SymbolName,int PeriodMinutes)
{
int size=iBars(SymbolName,PeriodMinutes);
//----
if (size==0) return;
int handle=FileOpen(SymbolName+PeriodMinutes+".csv",FILE_WRITE|FILE_CSV,",");
if (handle<0) return;
//FileWrite(handle,"TIME,OPEN,LOW,HIGH,CLOSE,VOLUME");
//FileWrite(handle,"N10,N8.5,N8.5,N8.5,N8.5,N6");
for (int i=size-1;i>=0;i--)
{
FileWrite(handle,
iTime(SymbolName,PeriodMinutes,i),
//TimeToStr(iTime(SymbolName,PeriodMinutes,i)),
iOpen(SymbolName,PeriodMinutes,i),
iLow(SymbolName,PeriodMinutes,i),
iHigh(SymbolName,PeriodMinutes,i),
iClose(SymbolName,PeriodMinutes,i),
iVolume(SymbolName,PeriodMinutes,i)
//iCustom(SymbolName,PeriodMinutes,"RSI",0,i)
);
}
FileClose(handle);
//----
return;
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
int SymbolCounter,PeriodCounter;
//----
for (SymbolCounter=1;SymbolCounter<NR_SYMB;SymbolCounter++)
{
RSI_output(GetSymbolString(SymbolCounter),PERIOD_M1);
RSI_output(GetSymbolString(SymbolCounter),PERIOD_M5);
RSI_output(GetSymbolString(SymbolCounter),PERIOD_H1);
RSI_output(GetSymbolString(SymbolCounter),PERIOD_H4);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments