-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_to_csv.mq4
64 lines (48 loc) · 1.98 KB
/
data_to_csv.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
//+------------------------------------------------------------------+
//| Data_to_CSV.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Inovance"
#property link "https://www.inovancetech.com/"
#property description "Save OHLCV data to a csv file."
#property version "1.00"
#property strict
#property indicator_chart_window
//Filename
input string FileName = "PriceData.csv";
//+------------------------------------------------------------------+
//| Initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//Define variables
int limit,i;
int counted_bars = IndicatorCounted();
//Make sure on most recent bar
if(counted_bars>0) counted_bars--;
//Set limit
limit = Bars - counted_bars - 1;
//Main loop
for(i = limit - 1; i>=0; i--)
{
//Create and Open file
int handle=FileOpen(FileName,FILE_CSV|FILE_READ|FILE_WRITE,",");
//Name column headers
FileWrite(handle,"Open Timestamp","Open","High","Low","Close","Volume");
//Go to end of file
FileSeek(handle,0,SEEK_END);
//Record data
FileWrite(handle,Time[i],Open[i],High[i],Low[i],Close[i],Volume[i]);
//Close file
FileClose(handle);
}
return(0);
}