質問編集履歴

1

コードの修正

2020/12/27 10:53

投稿

nisei2
nisei2

スコア19

test CHANGED
File without changes
test CHANGED
@@ -16,11 +16,91 @@
16
16
 
17
17
  ```MQL4
18
18
 
19
+ int OnInit()
20
+
21
+ {
22
+
23
+ EventSetTimer(1);
24
+
25
+ return(INIT_SUCCEEDED);
26
+
27
+ }
28
+
29
+
30
+
31
+ void OnDeinit(const int reason)
32
+
33
+ {
34
+
35
+ EventKillTimer();
36
+
37
+ }
38
+
39
+
40
+
41
+ void OnTimer()
42
+
43
+ {
44
+
45
+ static int timeHour = -1;
46
+
47
+ if(Hour() == timeHour) return;
48
+
49
+ timeHour = Hour();
50
+
51
+
52
+
53
+ string cookie=NULL,headers;
54
+
55
+ char post[],result[];
56
+
57
+ int res;
58
+
59
+ //--- to enable access to the server, you should add URL
60
+
61
+ //--- in the list of allowed URLs (Main Menu->Tools->Options, tab "Expert Advisors"):
62
+
63
+ string url="https://fx.minkabu.jp/references/holidays";
64
+
65
+ //--- Reset the last error code
66
+
67
+ ResetLastError();
68
+
69
+ //--- Loading a html page
70
+
71
+ int timeout=5000; //--- Timeout below 1000 (1 sec.) is not enough for slow Internet connection
72
+
73
+ res=WebRequest("GET",url,cookie,NULL,timeout,post,0,result,headers);
74
+
75
+ //--- Checking errors
76
+
77
+ if(res==-1)
78
+
79
+ {
80
+
81
+ Print("Error in WebRequest. Error code =",GetLastError());
82
+
83
+ //--- Perhaps the URL is not listed, display a message about the necessity to add the address
84
+
85
+ MessageBox("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
86
+
87
+ }
88
+
89
+ else
90
+
91
+ {
92
+
93
+ //--- Load successfully
94
+
95
+ PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
96
+
97
+
98
+
19
99
  string text = CharArrayToString(result,0,WHOLE_ARRAY,CP_UTF8);
20
100
 
21
101
  string str = NULL;
22
102
 
23
-
103
+
24
104
 
25
105
  for(int i = 0; i < StringLen(fs-s fc-sub w25); i++){
26
106
 
@@ -30,7 +110,7 @@
30
110
 
31
111
  string strTime = StringSubstr(text, i + 7, 5);
32
112
 
33
-
113
+
34
114
 
35
115
  //国名の取得に変更したい
36
116
 
@@ -40,7 +120,7 @@
40
120
 
41
121
  string strStar = StringSubstr(text, posStar0, posStar1 - posStar0);
42
122
 
43
-
123
+
44
124
 
45
125
  //イベントの取得に変更したい
46
126
 
@@ -50,9 +130,9 @@
50
130
 
51
131
  string strEvent = StringSubstr(text, posEvent0, posEvent1 - posEvent0);
52
132
 
53
-
54
133
 
134
+
55
- str += strTime + " " + strStar + " " + strEvent + "\n";
135
+ str += strTime + " " + strStar + " " + strEvent + "\n";
56
136
 
57
137
  }
58
138
 
@@ -60,6 +140,8 @@
60
140
 
61
141
  Comment(str);
62
142
 
63
- }
143
+ }
144
+
145
+ }
64
146
 
65
147
  ```