-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathData_T1_and_T6_to_csv.c
82 lines (69 loc) · 2.42 KB
/
Data_T1_and_T6_to_csv.c
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
// Source: https://gitlab.com/snippets/34036
function run()
{
Weekend = 0;
History=".t1";
set(TICKS);
BarPeriod = 0.1/60.0;
UnstablePeriod = 0;
LookBack = 0;
StartDate = 2015;
EndDate = 2015;
string format = "\n%04i.%02i.%02i %02i:%02i:%.2g,%f";
char fileName[40];
sprintf(fileName, "History\\%s.csv", strx(Asset,"/","")); // remove slash from forex pairs
if(is(INITRUN))
file_write(fileName, "Date,Price", 0);
else
file_append(fileName, strf(format,
year(),month(),day(),hour(),minute(),second(),
price()));
}
//----------------------------------------------------------------------------------
string Source = "..\\Zorro\\History\\AAPL.t6";
string Target = "History\\Export1.csv";
function main()
{
file_delete(Target);
if(strstr(Source,".t6")) {
T6 *Ticks = file_content(Source);
int nTicks = file_length(Source)/sizeof(T6);
while(nTicks--)
{
T6 *t = Ticks+nTicks;
file_append(Target,strf("%s,%.5f,%.5f,%.5f,%.5f\n",
strdate("%Y/%m/%d %H:%M:%S", t->time),
(var)t->fOpen, (var)t->fHigh, (var)t->fLow, (var)t->fClose));
}
} else if(strstr(Source,".t1")) {
T1 *Ticks = file_content(Source);
int nTicks = file_length(Source)/sizeof(T1);
while(nTicks--)
{
T1 *t = Ticks+nTicks;
file_append(Target,strf("%s,%.5f\n",
strdate("%Y/%m/%d %H:%M:%S", t->time),
(var)t->fVal));
}
}
printf("\nDone!");
}
// ------------------------------------------------------------------------------------------
// Export historic price data to a .csv file
// f.i. "31/12/12 00:00, 1.32205, 1.32341, 1.32157, 1.32278"
string Format = "%02i/%02i/%02i %02i:%02i, %.5f, %.5f, %.5f, %.5f\n"
function run()
{
BarPeriod = 1440;
StartDate = 2008;
EndDate = 2012;
LookBack = 0;
string line = strf(Format,
day(),month(),year()%100,hour(),minute(),
priceOpen(),priceHigh(),priceLow(),priceClose());
if(is(INITRUN))
file_delete("Data\\export.csv");
else
file_append("Data\\export.csv",line);
}
// ------------------------------------------------------------------------------------------