回答編集履歴
2
シンタックスハイライト対応言語の変更に対応、回答の脱字修正。
test
CHANGED
@@ -1,379 +1,190 @@
|
|
1
|
-
ObjectCreate関数とマウスイベントを駆使して**ダイアログのように見えるもの**を描画しているだけです。
|
1
|
+
MT4のダイアログボックスは、ObjectCreate関数とマウスイベントを駆使して**ダイアログのように見えるもの**を描画しているだけです。
|
2
|
-
|
3
2
|
それだと作るのが大変なので、標準ライブラリにダイアログ用のクラスがあります。
|
4
|
-
|
5
3
|
MT4をインストールしたディレクトリのMQL4\Include\Controlsにソースがあります。
|
6
|
-
|
7
|
-
|
8
4
|
|
9
5
|
MT4ではなく[MT5のリファレンス](https://www.mql5.com/ja/docs/standardlibrary/controls)を見るのが早いと思います。
|
10
6
|
|
11
|
-
|
12
|
-
|
13
7
|
インジケータの動作中に移動平均の期間を変更するサンプル
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
```
|
9
|
+
```cpp
|
18
|
-
|
19
10
|
#property strict
|
20
|
-
|
21
11
|
#property indicator_chart_window
|
22
12
|
|
23
|
-
|
24
|
-
|
25
13
|
#property indicator_buffers 3
|
26
|
-
|
27
14
|
#property indicator_plots 3
|
28
15
|
|
29
|
-
|
30
|
-
|
31
16
|
#property indicator_color1 clrDodgerBlue
|
32
|
-
|
33
17
|
#property indicator_color2 clrGreen
|
34
|
-
|
35
18
|
#property indicator_color3 clrCrimson
|
36
19
|
|
37
|
-
|
38
|
-
|
39
20
|
#property indicator_width1 1
|
40
|
-
|
41
21
|
#property indicator_width2 2
|
42
|
-
|
43
22
|
#property indicator_width3 3
|
44
23
|
|
45
|
-
|
46
|
-
|
47
24
|
#include <Controls\Dialog.mqh>
|
48
|
-
|
49
25
|
#include <Controls\Button.mqh>
|
50
|
-
|
51
26
|
#include <Controls\Edit.mqh>
|
52
|
-
|
53
27
|
#include <MovingAverages.mqh>
|
54
28
|
|
55
|
-
|
56
|
-
|
57
29
|
input int InpPeriod1 = 62;
|
58
|
-
|
59
30
|
input int InpPeriod2 = 200;
|
60
|
-
|
61
31
|
input int InpPeriod3 = 800;
|
62
32
|
|
63
|
-
|
64
|
-
|
65
33
|
double ExtMa1[];
|
66
|
-
|
67
34
|
double ExtMa2[];
|
68
|
-
|
69
35
|
double ExtMa3[];
|
70
36
|
|
71
|
-
|
72
|
-
|
73
37
|
int Period1;
|
74
|
-
|
75
38
|
int Period2;
|
76
|
-
|
77
39
|
int Period3;
|
78
40
|
|
79
|
-
|
80
|
-
|
81
41
|
class CTestDialog : public CAppDialog
|
82
|
-
|
83
42
|
{
|
84
|
-
|
85
43
|
CEdit m_edit1;
|
86
|
-
|
87
44
|
CEdit m_edit2;
|
88
|
-
|
89
45
|
CEdit m_edit3;
|
90
|
-
|
91
46
|
CButton m_button;
|
92
47
|
|
93
|
-
|
94
|
-
|
95
48
|
public:
|
96
|
-
|
97
49
|
virtual bool Create(const long chart, const string name, const int subwin, const int x1, const int y1,const int x2,const int y2);
|
98
|
-
|
99
50
|
virtual bool OnEvent(const int id, const long &lparam, const double &dparam,const string &sparam);
|
100
|
-
|
101
51
|
void OnClickButton(void);
|
102
|
-
|
103
52
|
};
|
104
53
|
|
105
|
-
|
106
|
-
|
107
54
|
EVENT_MAP_BEGIN(CTestDialog)
|
108
|
-
|
109
55
|
ON_EVENT(ON_CLICK, m_button, OnClickButton)
|
110
|
-
|
111
56
|
EVENT_MAP_END(CAppDialog)
|
112
57
|
|
113
|
-
|
114
|
-
|
115
58
|
bool CTestDialog::Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2)
|
116
|
-
|
117
59
|
{
|
118
|
-
|
119
60
|
CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2);
|
120
61
|
|
121
|
-
|
122
|
-
|
123
62
|
int x = 5;
|
124
|
-
|
125
63
|
int y = 5;
|
126
|
-
|
127
64
|
int w = 60;
|
128
|
-
|
129
65
|
int h = 20;
|
130
|
-
|
131
66
|
int margin = 5;
|
132
67
|
|
133
|
-
|
134
|
-
|
135
68
|
m_edit1.Create(m_chart_id, m_name + "Edit1", m_subwin, x, y, x + w, y + h);
|
136
|
-
|
137
69
|
m_edit1.Text(IntegerToString(Period1));
|
138
|
-
|
139
70
|
Add(m_edit1);
|
140
|
-
|
141
|
-
|
142
71
|
|
143
72
|
y += h + margin;
|
144
73
|
|
145
|
-
|
146
|
-
|
147
74
|
m_edit2.Create(m_chart_id, m_name + "Edit2", m_subwin, x, y, x + w, y + h);
|
148
|
-
|
149
75
|
m_edit2.Text(IntegerToString(Period2));
|
150
|
-
|
151
76
|
Add(m_edit2);
|
152
|
-
|
153
|
-
|
154
77
|
|
155
78
|
y += h + margin;
|
156
79
|
|
157
|
-
|
158
|
-
|
159
80
|
m_edit3.Create(m_chart_id, m_name + "Edit3", m_subwin, x, y, x + w, y + h);
|
160
|
-
|
161
81
|
m_edit3.Text(IntegerToString(Period3));
|
162
|
-
|
163
82
|
Add(m_edit3);
|
164
|
-
|
165
|
-
|
166
83
|
|
167
84
|
y += h + margin;
|
168
85
|
|
169
|
-
|
170
|
-
|
171
86
|
m_button.Create(m_chart_id, m_name + "Button", m_subwin, x, y, x + w, y + h);
|
172
|
-
|
173
87
|
m_button.Text("Update");
|
174
|
-
|
175
88
|
Add(m_button);
|
176
89
|
|
177
|
-
|
178
|
-
|
179
90
|
return true;
|
180
|
-
|
181
91
|
}
|
182
92
|
|
183
|
-
|
184
|
-
|
185
93
|
void CTestDialog::OnClickButton(void)
|
186
|
-
|
187
94
|
{
|
188
|
-
|
189
95
|
int period1 = StrToInteger(m_edit1.Text());
|
190
|
-
|
191
96
|
int period2 = StrToInteger(m_edit2.Text());
|
192
|
-
|
193
97
|
int period3 = StrToInteger(m_edit3.Text());
|
194
98
|
|
195
|
-
|
196
|
-
|
197
99
|
if (period1 <= 0 || period2 <= 0 || period3 <= 3)
|
198
|
-
|
199
100
|
{
|
200
|
-
|
201
101
|
return;
|
202
|
-
|
203
102
|
}
|
204
103
|
|
205
|
-
|
206
|
-
|
207
104
|
Period1 = period1;
|
208
|
-
|
209
105
|
Period2 = period2;
|
210
|
-
|
211
106
|
Period3 = period3;
|
212
107
|
|
213
|
-
|
214
|
-
|
215
108
|
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, Period1 - 1);
|
216
|
-
|
217
109
|
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, Period2 - 1);
|
218
|
-
|
219
110
|
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, Period3 - 1);
|
220
111
|
|
221
|
-
|
222
|
-
|
223
112
|
ChartSetSymbolPeriod(0, NULL, PERIOD_CURRENT);
|
224
|
-
|
225
113
|
}
|
226
|
-
|
227
|
-
|
228
114
|
|
229
115
|
CTestDialog ExtDialog;
|
230
116
|
|
231
|
-
|
232
|
-
|
233
117
|
int OnInit()
|
234
|
-
|
235
118
|
{
|
236
|
-
|
237
119
|
Period1 = InpPeriod1;
|
238
|
-
|
239
120
|
Period2 = InpPeriod2;
|
240
|
-
|
241
121
|
Period3 = InpPeriod3;
|
242
122
|
|
243
|
-
|
244
|
-
|
245
123
|
SetIndexBuffer(0, ExtMa1);
|
246
|
-
|
247
124
|
SetIndexBuffer(1, ExtMa2);
|
248
|
-
|
249
125
|
SetIndexBuffer(2, ExtMa3);
|
250
126
|
|
251
|
-
|
252
|
-
|
253
127
|
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, Period1 - 1);
|
254
|
-
|
255
128
|
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, Period2 - 1);
|
256
|
-
|
257
129
|
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, Period3 - 1);
|
258
130
|
|
259
|
-
|
260
|
-
|
261
131
|
if(!ExtDialog.Create(0, "MA3", 0, 20, 20, 100, 160))
|
262
|
-
|
263
132
|
{
|
264
|
-
|
265
133
|
return INIT_FAILED;
|
266
|
-
|
267
134
|
}
|
268
|
-
|
269
|
-
|
270
135
|
|
271
136
|
ExtDialog.Run();
|
272
137
|
|
273
|
-
|
274
|
-
|
275
138
|
return INIT_SUCCEEDED;
|
276
|
-
|
277
139
|
}
|
278
140
|
|
279
|
-
|
280
|
-
|
281
141
|
void OnDeinit(const int reason)
|
282
|
-
|
283
142
|
{
|
284
|
-
|
285
143
|
ExtDialog.Destroy(reason);
|
286
|
-
|
287
144
|
}
|
288
145
|
|
289
|
-
|
290
|
-
|
291
146
|
int OnCalculate(const int rates_total,
|
292
|
-
|
293
147
|
const int prev_calculated,
|
294
|
-
|
295
148
|
const datetime &time[],
|
296
|
-
|
297
149
|
const double &open[],
|
298
|
-
|
299
150
|
const double &high[],
|
300
|
-
|
301
151
|
const double &low[],
|
302
|
-
|
303
152
|
const double &close[],
|
304
|
-
|
305
153
|
const long &tick_volume[],
|
306
|
-
|
307
154
|
const long &volume[],
|
308
|
-
|
309
155
|
const int &spread[])
|
310
|
-
|
311
156
|
{
|
312
|
-
|
313
157
|
ArraySetAsSeries(ExtMa1, false);
|
314
|
-
|
315
158
|
ArraySetAsSeries(ExtMa2, false);
|
316
|
-
|
317
159
|
ArraySetAsSeries(ExtMa3, false);
|
318
|
-
|
319
160
|
ArraySetAsSeries(close, false);
|
320
161
|
|
321
|
-
|
322
|
-
|
323
162
|
int minPeriod = MathMin(Period1, MathMin(Period2, Period3));
|
324
|
-
|
325
163
|
int first = MathMax(minPeriod - 1, prev_calculated - 1);
|
326
164
|
|
327
|
-
|
328
|
-
|
329
165
|
for (int i = first; i < rates_total; i++)
|
330
|
-
|
331
166
|
{
|
332
|
-
|
333
167
|
if (i == (Period1 - 1))
|
334
|
-
|
335
168
|
ExtMa1[i] = SimpleMA(i, Period1, close);
|
336
|
-
|
337
169
|
else if (i >= (Period1 - 1))
|
338
|
-
|
339
170
|
ExtMa1[i] = ExponentialMA(i, Period1, ExtMa1[i - 1], close);
|
340
171
|
|
341
|
-
|
342
|
-
|
343
172
|
if (i >= (Period2 - 1))
|
344
|
-
|
345
173
|
ExtMa2[i] = SimpleMA(i, Period2, close);
|
346
174
|
|
347
|
-
|
348
|
-
|
349
175
|
if (i >= (Period3 - 1))
|
350
|
-
|
351
176
|
ExtMa3[i] = SimpleMA(i, Period3, close);
|
352
|
-
|
353
177
|
}
|
354
178
|
|
355
|
-
|
356
|
-
|
357
179
|
return rates_total;
|
358
|
-
|
359
180
|
}
|
360
181
|
|
361
|
-
|
362
|
-
|
363
182
|
void OnChartEvent(const int id,
|
364
|
-
|
365
183
|
const long &lparam,
|
366
|
-
|
367
184
|
const double &dparam,
|
368
|
-
|
369
185
|
const string &sparam)
|
370
|
-
|
371
186
|
{
|
372
|
-
|
373
187
|
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
|
374
|
-
|
375
188
|
}
|
376
189
|
|
377
|
-
|
378
|
-
|
379
190
|
```
|
1
期間の取得処理修正
test
CHANGED
@@ -320,7 +320,9 @@
|
|
320
320
|
|
321
321
|
|
322
322
|
|
323
|
+
int minPeriod = MathMin(Period1, MathMin(Period2, Period3));
|
324
|
+
|
323
|
-
int first = MathMax(Period
|
325
|
+
int first = MathMax(minPeriod - 1, prev_calculated - 1);
|
324
326
|
|
325
327
|
|
326
328
|
|