-
Notifications
You must be signed in to change notification settings - Fork 0
/
eTime.mqh
86 lines (74 loc) · 2.8 KB
/
eTime.mqh
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
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2020, CompanyName |
//| https://www.companyname.net |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class eTime
{
public:
datetime OpenDaily(datetime date);
datetime CloseDaily(datetime date);
datetime Yesterday(datetime date, const int days_ago=1);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
datetime eTime::OpenDaily(datetime date)
{
MqlDateTime time_mql, time_i;
TimeToStruct(date, time_mql);
time_mql.hour = 00;
time_mql.min = 00;
time_mql.sec = 00;
int date_i = time_mql.day;
int shift_i = iBarShift(Symbol(), PERIOD_CURRENT, StructToTime(time_mql));
datetime time_shift = iTime(Symbol(), PERIOD_CURRENT, shift_i);
TimeToStruct(time_shift, time_i);
if(time_i.day != date_i)
{
shift_i--;
time_shift = iTime(Symbol(), PERIOD_CURRENT, shift_i);
}
return time_shift;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
datetime eTime::CloseDaily(datetime date)
{
MqlDateTime time_mql;
TimeToStruct(date, time_mql);
time_mql.hour = 23;
time_mql.min = 59;
time_mql.sec = 00;
int date_i = time_mql.day;
int shift_i = iBarShift(Symbol(), PERIOD_CURRENT, StructToTime(time_mql));
datetime time_shift = iTime(Symbol(), PERIOD_CURRENT, shift_i);
return time_shift;
}
//+------------------------------------------------------------------+
datetime eTime::Yesterday(datetime date, const int days_ago=1)
{
int oneDay = 60*60*24,
forDay = 0;
datetime time_i = date ;
MqlDateTime time_ii;
do
{
TimeToStruct(time_i, time_ii);
time_i = time_i - oneDay;
if(!(time_ii.day_of_week == 0 || time_ii.day_of_week == 1))
{
forDay++;
}
}
while(forDay<days_ago);
return time_i;
}
//+------------------------------------------------------------------+