Attrib_to_File4_EURUSD
Download scriptThis script is designed to automate the collection of specific technical analysis data from financial markets and save it into a structured file format. Instead of providing live signals, its primary purpose is "data mining"—extracting raw numbers that can be used later for deeper statistical analysis or machine learning training.
Core Functionality
The script scans historical price data for specific currency pairs (such as EURUSD) and performs the following actions:
- Multi-Timeframe Analysis: It simultaneously looks at data across four different timeframes: 1-minute, 5-minute, 1-hour, and 4-hour charts.
- Moving Average Calculation: For each of these timeframes, it calculates three different Simple Moving Averages (SMAs) based on periods of 5, 10, and 15 units.
- Difference Mapping: Rather than just recording the average prices, the script calculates the differences between these averages (e.g., the gap between the 5-period average and the 10-period average). It does this for the current candle, as well as the previous two candles.
- Data Export: All of these calculated differences, along with the time and closing price, are compiled into a single row and saved into a CSV (Comma Separated Values) file.
How the Logic Works Step-by-Step
- Initialization: The script identifies which financial symbols to analyze based on a predefined list.
- Historical Loop: It starts at the beginning of the available price history and moves forward candle by candle.
- Time Alignment: For every 1-minute candle, it finds the corresponding candles on the larger timeframes (5m, 1h, 4h). This ensures that the data being saved is perfectly synchronized in time.
- Math Processing:
- It takes the SMA values for the current moment and subtracts them to find "spreads."
- It repeats this for the previous two moments (to capture momentum or trend changes).
- File Generation: It creates a file specifically named after the currency pair (e.g.,
EURUSD1_at.csv) and writes all the gathered numerical data into it.
Summary for the User
In simple terms, this script is an automated data harvester. It goes through months or years of trading history, calculates various "gaps" between moving averages across multiple timeframes, and organizes all that information into a spreadsheet-ready file. This type of tool is commonly used by researchers who want to feed large amounts of historical market behavior into a database for further study.
//+------------------------------------------------------------------+
//| 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]={"","EURUSD"};
//+------------------------------------------------------------------+
//| 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);
}
*/
//+------------------------------------------------------------------+
//| âûâîäèò â ôàéë êîòèðîâêè + çíà÷åíèÿ èíäèêàòîðà |
//+------------------------------------------------------------------+
double x0,x1,x2,x3,x4,x5,x6,x7,x8,x9;
double y0,y1,y2,y3,y4,y5,y6,y7,y8,y9;
double z0,z1,z2,z3,z4,z5,z6,z7,z8,z9;
double at0,at1,at2,at3,at4,at5,at6,at7,at8;
double at9,at10,at11,at12,at13,at14,at15,at16,at17;
double at18,at19,at20,at21,at22,at23,at24,at25,at26;
void Ma_output(
string SymbolName,
int PeriodMinutes1,
int PeriodMinutes5,
int PeriodMinutes60,
int PeriodMinutes240
)
{
int size=iBars(SymbolName,PeriodMinutes1);
//----
if (size==0) return;
int handle=FileOpen(SymbolName+"1_at.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--)
{
datetime time1=iTime(SymbolName,PeriodMinutes1,i);
int b5=iBarShift(SymbolName,PeriodMinutes5,time1,true);
int b60=iBarShift(SymbolName,PeriodMinutes60,time1,true);
int b240=iBarShift(SymbolName,PeriodMinutes240,time1,true);
if(b5>=0)
{
x0=iClose(SymbolName,PeriodMinutes5,b5);
/*
svm_test_attrib_dyn_1[j][0]=( ma5_M5[i] -ma10_M5[i])/Point;
svm_test_attrib_dyn_1[j][1]=(ma10_M5[i]- ma15_M5[i])/Point;
svm_test_attrib_dyn_1[j][2]=( ma5_M5[i] -ma15_M5[i])/Point;
*/
x1=iMA(SymbolName,PeriodMinutes5,5,0,MODE_SMA,PRICE_CLOSE,b5);
x2=iMA(SymbolName,PeriodMinutes5,10,0,MODE_SMA,PRICE_CLOSE,b5);
x3=iMA(SymbolName,PeriodMinutes5,15,0,MODE_SMA,PRICE_CLOSE,b5);
at0=x1-x2;
at1=x2-x3;
at2=x1-x3;
/*
svm_test_attrib_dyn_1[j][9]=( ma5_M5[i+1] -ma10_M5[i+1])/Point;
svm_test_attrib_dyn_1[j][10]=(ma10_M5[i+1]- ma15_M5[i+1])/Point;
svm_test_attrib_dyn_1[j][11]=( ma5_M5[i+1] -ma15_M5[i+1])/Point;
*/
y1=iMA(SymbolName,PeriodMinutes5,5,0,MODE_SMA,PRICE_CLOSE,b5+1);
y2=iMA(SymbolName,PeriodMinutes5,10,0,MODE_SMA,PRICE_CLOSE,b5+1);
y3=iMA(SymbolName,PeriodMinutes5,15,0,MODE_SMA,PRICE_CLOSE,b5+1);
at9=y1-y2;
at10=y2-y3;
at11=y1-y3;
/*
svm_test_attrib_dyn_1[j][18]=( ma5_M5[i+2] -ma10_M5[i+2])/Point;
svm_test_attrib_dyn_1[j][19]=(ma10_M5[i+2] -ma15_M5[i+2])/Point;
svm_test_attrib_dyn_1[j][20]=( ma5_M5[i+2] -ma15_M5[i+2])/Point;
*/
z1=iMA(SymbolName,PeriodMinutes5,5,0,MODE_SMA,PRICE_CLOSE,b5+2);
z2=iMA(SymbolName,PeriodMinutes5,10,0,MODE_SMA,PRICE_CLOSE,b5+2);
z3=iMA(SymbolName,PeriodMinutes5,15,0,MODE_SMA,PRICE_CLOSE,b5+2);
at18=z1-z2;
at19=z2-z3;
at20=z1-z3;
}
if(b60>=0)
{
/*
svm_test_attrib_dyn_1[j][3]=( ma5_H1[i] -ma10_H1[i])/Point;
svm_test_attrib_dyn_1[j][4]=(ma10_H1[i]- ma15_H1[i])/Point;
svm_test_attrib_dyn_1[j][5]=( ma5_H1[i] -ma15_H1[i])/Point;
*/
x4=iMA(SymbolName,PeriodMinutes60,5,0,MODE_SMA,PRICE_CLOSE,b60);
x5=iMA(SymbolName,PeriodMinutes60,10,0,MODE_SMA,PRICE_CLOSE,b60);
x6=iMA(SymbolName,PeriodMinutes60,15,0,MODE_SMA,PRICE_CLOSE,b60);
at3=x4-x5;
at4=x5-x6;
at5=x4-x6;
/*
svm_test_attrib_dyn_1[j][12]=( ma5_H1[i+1] -ma10_H1[i+1])/Point;
svm_test_attrib_dyn_1[j][13]=(ma10_H1[i+1]- ma15_H1[i+1])/Point;
svm_test_attrib_dyn_1[j][14]=( ma5_H1[i+1] -ma15_H1[i+1])/Point;
*/
y4=iMA(SymbolName,PeriodMinutes60,5,0,MODE_SMA,PRICE_CLOSE,b60+1);
y5=iMA(SymbolName,PeriodMinutes60,10,0,MODE_SMA,PRICE_CLOSE,b60+1);
y6=iMA(SymbolName,PeriodMinutes60,15,0,MODE_SMA,PRICE_CLOSE,b60+1);
at12=y4-y5;
at13=y5-y6;
at14=y4-y6;
/*
svm_test_attrib_dyn_1[j][21]=( ma5_H1[i+2] -ma10_H1[i+2])/Point;
svm_test_attrib_dyn_1[j][22]=(ma10_H1[i+2] -ma15_H1[i+2])/Point;
svm_test_attrib_dyn_1[j][23]=( ma5_H1[i+2] -ma15_H1[i+2])/Point;
*/
z4=iMA(SymbolName,PeriodMinutes60,5,0,MODE_SMA,PRICE_CLOSE,b60+2);
z5=iMA(SymbolName,PeriodMinutes60,10,0,MODE_SMA,PRICE_CLOSE,b60+2);
z6=iMA(SymbolName,PeriodMinutes60,15,0,MODE_SMA,PRICE_CLOSE,b60+2);
at21=z4-z5;
at22=z5-z6;
at23=z4-z6;
}
if(b240>=0)
{
/*
svm_test_attrib_dyn_1[j][6]=( ma5_H4[i] -ma10_H4[i])/Point;
svm_test_attrib_dyn_1[j][7]=(ma10_H4[i]- ma15_H4[i])/Point;
svm_test_attrib_dyn_1[j][8]=( ma5_H4[i] -ma15_H4[i])/Point;
*/
x7=iMA(SymbolName,PeriodMinutes240,5,0,MODE_SMA,PRICE_CLOSE,b240);
x8=iMA(SymbolName,PeriodMinutes240,10,0,MODE_SMA,PRICE_CLOSE,b240);
x9=iMA(SymbolName,PeriodMinutes240,15,0,MODE_SMA,PRICE_CLOSE,b240);
at6=x7-x8;
at7=x8-x9;
at8=x7-x9;
/*
svm_test_attrib_dyn_1[j][15]=( ma5_H4[i+1] -ma10_H4[i+1])/Point;
svm_test_attrib_dyn_1[j][16]=(ma10_H4[i+1]- ma15_H4[i+1])/Point;
svm_test_attrib_dyn_1[j][17]=( ma5_H4[i+1] -ma15_H4[i+1])/Point;
*/
y7=iMA(SymbolName,PeriodMinutes240,5,0,MODE_SMA,PRICE_CLOSE,b240+1);
y8=iMA(SymbolName,PeriodMinutes240,10,0,MODE_SMA,PRICE_CLOSE,b240+1);
y9=iMA(SymbolName,PeriodMinutes240,15,0,MODE_SMA,PRICE_CLOSE,b240+1);
at15=y7-y8;
at16=y8-y9;
at17=y7-y9;
/*
svm_test_attrib_dyn_1[j][24]=( ma5_H4[i+2] -ma10_H4[i+2])/Point;
svm_test_attrib_dyn_1[j][25]=(ma10_H4[i+2] -ma15_H4[i+2])/Point;
svm_test_attrib_dyn_1[j][26]=( ma5_H4[i+2] -ma15_H4[i+2])/Point;
*/
z7=iMA(SymbolName,PeriodMinutes240,5,0,MODE_SMA,PRICE_CLOSE,b240+2);
z8=iMA(SymbolName,PeriodMinutes240,10,0,MODE_SMA,PRICE_CLOSE,b240+2);
z9=iMA(SymbolName,PeriodMinutes240,15,0,MODE_SMA,PRICE_CLOSE,b240+2);
at24=z7-z8;
at25=z8-z9;
at26=z7-z9;
}
FileWrite(handle,
iTime(SymbolName,PeriodMinutes1,i),
iClose(SymbolName,PeriodMinutes1,i),
x0, //Close M5
at0,
at1,
at2,
at3,
at4,
at5,
at6,
at7,
at8,
at9,
at10,
at11,
at12,
at13,
at14,
at15,
at16,
at17,
at18,
at19,
at20,
at21,
at22,
at23,
at24,
at25,
at26
);
}
FileClose(handle);
//----
return;
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
int SymbolCounter,PeriodCounter;
//----
for (SymbolCounter=1;SymbolCounter<NR_SYMB;SymbolCounter++)
{
Ma_output(GetSymbolString(SymbolCounter),PERIOD_M1,PERIOD_M5,PERIOD_H1,PERIOD_H4);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments