RSI_to_File
Download scriptThis script is designed to automate the collection and exportation of specific market data from your trading platform into a structured file format. Instead of manually tracking every price movement, this tool systematically scans multiple currency pairs and timeframes to gather technical indicators for external analysis.
Core Functionality
The primary purpose of this script is to generate CSV (Comma Separated Values) files containing historical price data combined with the Relative Strength Index (RSI)—a common momentum oscillator used by traders.
How the Logic Works
The script operates through a structured sequence of automated steps:
1. Target Selection The tool contains a pre-defined list of 12 major currency pairs (such as EURUSD, GBPJPY, and USDCHF). It is programmed to monitor these specific markets automatically rather than requiring you to select them one by one.
2. Timeframe Coverage For every currency pair listed, the script cycles through several different time intervals simultaneously. This includes various standard trading periods ranging from 15-minute charts up to daily views, ensuring that you receive a comprehensive data set across different market speeds.
3. Data Extraction Process Once the script identifies a currency and its corresponding timeframe, it performs the following actions:
- Data Retrieval: It pulls the "Open," "High," "Low," and "Close" prices, along with the volume for every historical candle available in that period.
- Indicator Calculation: It simultaneously calculates the RSI value for each of those specific points in time.
- File Creation: It automatically creates a new file for each unique combination (e.g., a specific file for "GBPUSD on an H1 timeframe").
4. Sequential Exporting The logic follows a "nested" loop system. This means the script doesn't just look at one currency at a time; it takes the first currency and records all its timeframes, then moves to the next currency and repeats the process until the entire list is exhausted.
Final Output
The end result of running this script is a series of organized files. Each file serves as a complete historical record where each row represents a specific moment in time, showing exactly what the price was doing alongside the RSI indicator value at that exact second. This allows for easy transition of data from the trading platform into spreadsheet software like Microsoft Excel for deeper study or custom reporting.
//+------------------------------------------------------------------+
//| 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/"
#property show_inputs
string SymbolsArray[13]={"","USDCHF","GBPUSD","EURUSD","USDJPY","AUDUSD","USDCAD","EURGBP","EURAUD","EURCHF","EURJPY","GBPJPY","GBPCHF"};
//+------------------------------------------------------------------+
//| 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+"_RSI.csv",FILE_WRITE|FILE_CSV);
if (handle<0) return;
FileWrite(handle,"Time seconds;Time;Open;Low;High;Close;Volume;RSI");
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<13;SymbolCounter++)
{
for (PeriodCounter=2;PeriodCounter<=6;PeriodCounter++)
{
//Print("NewBar on ",GetSymbolString(SymbolCounter),PeriodNumber(PeriodCounter),"M");
RSI_output(GetSymbolString(SymbolCounter),PeriodNumber(PeriodCounter));
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments