-
Notifications
You must be signed in to change notification settings - Fork 46
/
DataWriter_v5.01.mq4
204 lines (162 loc) · 7.21 KB
/
DataWriter_v5.01.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//+------------------------------------------------------------------+
//| DataWriter.mq4 |
//| Copyright 2018, Vladimir Zhbanko |
//+------------------------------------------------------------------+
#include <06_NormalizeDouble.mqh>
#property copyright "Copyright 2018, Vladimir Zhbanko"
#property link "https://vladdsm.github.io/myblog_attempt/"
#property version "5.02"
#property strict
/*
PURPOSE: Retrieve price and Indicator data for an asset
USE: Data will be used for Decision Support System in R - Version For Stock Assets
WANT TO LEARN HOW TO USE?
https://www.udemy.com/your-home-trading-environment/?couponCode=LAZYTRADE-GIT
https://www.udemy.com/your-trading-robot/?couponCode=LAZYTRADE-GIT
*/
extern string Header1 = "-----EA Main Settings-------";
extern int UseBarsHistory = 400;
extern int UseBarsCollect = 333;
extern int chartPeriod = 15; //min
extern bool CollectClosePrice = True;
extern string DashboardComment = "Record financial assets data to files"; // change this comment for descriptive purposes
string FileNamePrx1 = "AI_CP";
/*
Content:
2. Function writeDataCP collect Close Price data
3. Function writeDataOP collect Open Price data
4. Function writeDataLP collect Low Price data
5. Function writeDataHP collect High Price data
6. Function writeDataRSI collect Rsi data
7. Function writeDataBullPow collect BullPower data
8. Function writeDataBearPow collect BearPower data
9. Function writeDataAtr collect Atr data
10.Function writeDataMacd collect MACD data
*/
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//useful to generate files when market is closed
if(CollectClosePrice)writeDataCP(FileNamePrx1 + string(chartPeriod) + "-" + string(UseBarsCollect) + ".csv", chartPeriod, UseBarsCollect);
//show dashboard
ShowDashboard(DashboardComment, 0,
FileNamePrx1 + string(chartPeriod) + "-" + string(UseBarsCollect) + ".csv", 0,
"..", 0,
"..", 0,
"..", 0,
"..", 0,
"..", 0);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// should generate unique time every minute https://www.mql5.com/en/forum/133366
static datetime Time0;
if(Time0 == Time[0])
{
}
else
{
// record time to variable
Time0 = Time[0];
//code that only executed in the beginning and once every bar
if(CollectClosePrice)writeDataCP(FileNamePrx1 + string(chartPeriod) + "-" + string(UseBarsCollect) + ".csv", chartPeriod, UseBarsCollect);
//show dashboard
ShowDashboard(DashboardComment, 0,
FileNamePrx1 + string(chartPeriod) + "-" + string(UseBarsCollect) + ".csv", 0,
"..", 0,
"..", 0,
"..", 0,
"..", 0,
"..", 0);
}
}
//+------------------------------------------------------------------+
void writeDataCP(string filename, int charPer, int barsCollect)
// function to record 28 currencies pairs close price to the file (file to be used by all R scripts)
{
//---- stocks
double tesla;
string data; //identifier that will be used to collect data string
datetime TIME; //Time index
// delete file if it's exist
FileDelete(filename);
// open file handle
int handle = FileOpen(filename,FILE_CSV|FILE_READ|FILE_WRITE);
FileSeek(handle,0,SEEK_SET);
// generate data now using for loop
//----Fill the arrays
//loop j calculates surfaces and angles from beginning of the day
for(int j = 0; j < barsCollect; j++) //j scrolls through bars of the day
{
TIME = iTime(Symbol(), chartPeriod, j); //Time of the bar of the applied chart symbol
//--- calculating close price for every currency
tesla = iClose("#TeslaMotor",chartPeriod,j);
data = string(TIME)+","+string(tesla);
FileWrite(handle,data); //write data to the file during each for loop iteration
}
//
FileClose(handle); //close file when data write is over
//---------------------------------------------------------------------------------------------
}
//+------------------------------------------------------------------+
//| Dashboard - Comment Version
//+------------------------------------------------------------------+
void ShowDashboard(string Descr0, int magic,
string Descr1, int Param1,
string Descr2, double Param2,
string Descr3, int Param3,
string Descr4, double Param4,
string Descr5, int Param5,
string Descr6, double Param6
)
{
// Purpose: This function creates a dashboard showing information on your EA using comments function
// Type: Customisable
// Modify this function to suit your trading robot
//----
string new_line = "\n"; // "\n" or "\n\n" will move the comment to new line
string space = ": "; // generate space
string underscore = "________________________________";
Comment(
new_line
+ Descr0 + space + IntegerToString(magic)
+ new_line
+ underscore
+ new_line
+ new_line
+ Descr1 + space + IntegerToString(Param1)
+ new_line
+ Descr2 + space + DoubleToString(Param2, 1)
+ new_line
+ underscore
+ new_line
+ new_line
+ Descr3 + space + IntegerToString(Param3)
+ new_line
+ Descr4 + space + DoubleToString(Param4, 1)
+ new_line
+ underscore
+ new_line
+ new_line
+ Descr5 + space + IntegerToString(Param5)
+ new_line
+ Descr6 + space + DoubleToString(Param6, 1)
+ new_line
+ underscore
+ "");
}
//+------------------------------------------------------------------+
//| End of Dashboard - Comment Version
//+------------------------------------------------------------------+