-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGraphic.mqh
532 lines (475 loc) · 39 KB
/
Graphic.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
//+------------------------------------------------------------------+
//| Graphic.mqh |
//| Copyright 2021, Homma.tech |
//| https://www.homma.tech |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Homma.tech"
#property link "https://www.homma.tech"
#include "NewTypes.mqh"
#define PRIMARY_COLOR C'0x28,0x2A,0x36'
#define SECONDARY_COLOR C'0x44,0x47,0x5A'
#define FONT_COLOR C'0xF8,0xF8,0xF2'
#define DEFAULT_FONT "Arial"
#define DEFAULT_FONT_SIZE 12
class CHorizontalLine {
private:
string horizontalLineID;
int x, y;
public:
bool CHorizontalLine :: Create(int layer = 1,
string name = "HLine",
int subWindow = 0,
double price = 0,
color lineColor = PRIMARY_COLOR,
ENUM_LINE_STYLE lineStyle = STYLE_SOLID,
int lineWidth = 1,
string label = NULL,
int fontSize = 12) {
horizontalLineID = IntegerToString(layer) + "_" + name;
if(!price)
price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
ResetLastError();
if(!ObjectCreate(0,
horizontalLineID,
OBJ_HLINE,
subWindow,
0,
price)) {
Print(__FUNCTION__,
": falha ao criar um linha horizontal! Código de erro = ",
GetLastError());
return(false);
}
ObjectSetInteger(0, horizontalLineID, OBJPROP_COLOR, lineColor);
ObjectSetInteger(0, horizontalLineID, OBJPROP_STYLE, lineStyle);
ObjectSetInteger(0, horizontalLineID, OBJPROP_WIDTH, lineWidth);
ObjectSetInteger(0, horizontalLineID, OBJPROP_BACK, false);
ObjectSetInteger(0, horizontalLineID, OBJPROP_SELECTABLE, true);
ObjectSetInteger(0, horizontalLineID, OBJPROP_SELECTED, true);
ObjectSetInteger(0, horizontalLineID, OBJPROP_HIDDEN, false);
ObjectSetInteger(0, horizontalLineID, OBJPROP_ZORDER, 1);
ObjectSetString(0, horizontalLineID, OBJPROP_TEXT, label);
ObjectSetInteger(0, horizontalLineID, OBJPROP_FONTSIZE, fontSize);
ChartTimePriceToXY(0, 0, TimeCurrent(), price, x, y);
return(true);
}
void CHorizontalLine :: ChangePrice(datetime newTime,
double newPrice) {
ObjectMove(0, horizontalLineID, 0, newTime, newPrice);
}
double CHorizontalLine :: Price() {
return ObjectGetDouble(0, horizontalLineID, OBJPROP_PRICE);
}
int CHorizontalLine :: X() {
ChartTimePriceToXY(0, 0, TimeCurrent(), Price(), x, y);
return x;
}
int CHorizontalLine :: Y() {
ChartTimePriceToXY(0, 0, TimeCurrent(), Price(), x, y);
return y;
}
void CHorizontalLine :: Destroy() {
ObjectDelete(0, horizontalLineID);
}
};
class CRetangle {
private:
string retangleName;
long x,
y;
public:
string CRetangle :: Create(int layer,
string name,
long width,
long height,
long positionX,
long positionY,
color backgroundColor = PRIMARY_COLOR,
ENUM_BORDER_TYPE borderType = BORDER_FLAT,
color borderColor = PRIMARY_COLOR,
ENUM_LINE_STYLE borderStyle = STYLE_SOLID,
int borderWidth = 1,
ENUM_BASE_CORNER referenceCorner = CORNER_LEFT_UPPER) {
x = positionX;
y = positionY;
retangleName = IntegerToString(layer) + "_" + name;
ObjectCreate(0,
retangleName,
OBJ_RECTANGLE_LABEL,
0,
0,
0);
ObjectSetInteger(0, retangleName, OBJPROP_XDISTANCE, positionX);
ObjectSetInteger(0, retangleName, OBJPROP_YDISTANCE, positionY);
ObjectSetInteger(0, retangleName, OBJPROP_XSIZE, width);
ObjectSetInteger(0, retangleName, OBJPROP_YSIZE, height);
ObjectSetInteger(0, retangleName, OBJPROP_BGCOLOR, backgroundColor);
ObjectSetInteger(0, retangleName, OBJPROP_BORDER_TYPE, borderType);
ObjectSetInteger(0, retangleName, OBJPROP_CORNER, referenceCorner);
ObjectSetInteger(0, retangleName, OBJPROP_COLOR, borderColor);
ObjectSetInteger(0, retangleName, OBJPROP_STYLE, borderStyle);
ObjectSetInteger(0, retangleName, OBJPROP_WIDTH, borderWidth);
ObjectSetInteger(0, retangleName, OBJPROP_BACK, false);
ObjectSetInteger(0, retangleName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, retangleName, OBJPROP_SELECTED, false);
ObjectSetInteger(0, retangleName, OBJPROP_HIDDEN, false);
ObjectSetInteger(0, retangleName, OBJPROP_ZORDER, 100);
return retangleName;
}
long CRetangle :: X() {
return x;
}
long CRetangle :: Y() {
return y;
}
void CRetangle :: Destroy() {
ObjectDelete(0, retangleName);
}
};
class CLabel {
private:
string labelName;
public:
string CLabel :: Create(int layer,
string name,
string textInput,
long positionX,
long positionY,
string fontName = DEFAULT_FONT,
int fontSize = DEFAULT_FONT_SIZE,
color fontColor = FONT_COLOR,
ENUM_ANCHOR_POINT anchor = ANCHOR_LEFT_UPPER,
ENUM_BASE_CORNER referenceCorner = CORNER_LEFT_UPPER) {
labelName = IntegerToString(layer) + "_" + name;
ObjectCreate(0,
labelName,
OBJ_LABEL,
0,
0,
0);
//--- definir coordenadas da etiqueta
ObjectSetInteger(0, labelName, OBJPROP_XDISTANCE, positionX);
ObjectSetInteger(0, labelName, OBJPROP_YDISTANCE, positionY);
//--- determinar o canto do gráfico onde as coordenadas do ponto são definidas
ObjectSetInteger(0, labelName, OBJPROP_CORNER, referenceCorner);
//--- definir o texto
ObjectSetString(0, labelName, OBJPROP_TEXT, textInput);
//--- definir o texto fonte
ObjectSetString(0, labelName, OBJPROP_FONT, fontName);
//--- definir tamanho da fonte
ObjectSetInteger(0, labelName, OBJPROP_FONTSIZE, fontSize);
//--- definir o ângulo de inclinação do texto
ObjectSetDouble(0, labelName, OBJPROP_ANGLE, 0.0);
//--- tipo de definição de ancoragem
ObjectSetInteger(0, labelName, OBJPROP_ANCHOR, anchor);
//--- definir cor
ObjectSetInteger(0, labelName, OBJPROP_COLOR, fontColor);
//--- exibir em primeiro plano (false) ou fundo (true)
ObjectSetInteger(0, labelName, OBJPROP_BACK, false);
//--- Habilitar (true) ou desabilitar (false) o modo de movimento da etiqueta pelo mouse
ObjectSetInteger(0, labelName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, labelName, OBJPROP_SELECTED, false);
//--- ocultar (true) ou exibir (false) o nome do objeto gráfico na lista de objeto
ObjectSetInteger(0, labelName, OBJPROP_HIDDEN, false);
//--- definir a prioridade para receber o evento com um clique do mouse no gráfico
ObjectSetInteger(0, labelName, OBJPROP_ZORDER, 2);
return labelName;
}
long CLabel :: X() {
return ObjectGetInteger(0, labelName, OBJPROP_XDISTANCE);
}
long CLabel :: Y() {
return ObjectGetInteger(0, labelName, OBJPROP_YDISTANCE);
}
void CLabel :: ChangeText(string newText) {
ObjectSetString(0, labelName, OBJPROP_TEXT, newText);
}
void CLabel :: Move(datetime time,
double price) {
ObjectMove(0, labelName, 0, time, price);
}
void CLabel :: Move(long newX,
long newY) {
if(newX != X())
ObjectSetInteger(0, labelName, OBJPROP_XDISTANCE, newX);
if(newY != Y())
ObjectSetInteger(0, labelName, OBJPROP_YDISTANCE, newY);
}
void CLabel :: Destroy() {
ObjectDelete(0, labelName);
}
};
class CEdit {
private:
string editName;
bool active;
public:
CEdit :: CEdit() {
active = false;
}
string CEdit :: Create(int layer,
string name,
string textInput,
long positionX,
long positionY,
long width,
long height,
string fontName = DEFAULT_FONT,
int fontSize = DEFAULT_FONT_SIZE,
color fontColor = FONT_COLOR,
color bgColor = SECONDARY_COLOR,
ENUM_ALIGN_MODE align = ALIGN_CENTER,
ENUM_BASE_CORNER referenceCorner = CORNER_LEFT_UPPER) {
active = true;
editName = IntegerToString(layer) + "_" + name;
ObjectCreate(0,
editName,
OBJ_EDIT,
0,
0,
0);
//--- definir coordenadas da etiqueta
ObjectSetInteger(0, editName, OBJPROP_XDISTANCE, positionX);
ObjectSetInteger(0, editName, OBJPROP_YDISTANCE, positionY);
//--- definir tamanho do objeto
ObjectSetInteger(0, editName, OBJPROP_XSIZE, width);
ObjectSetInteger(0, editName, OBJPROP_YSIZE, height);
//--- definir o tipo de alinhamento do texto no objeto
ObjectSetInteger(0, editName, OBJPROP_ALIGN, align);
//--- determinar o canto do gráfico onde as coordenadas do ponto são definidas
ObjectSetInteger(0, editName, OBJPROP_CORNER, referenceCorner);
//--- definir o texto
ObjectSetString(0, editName, OBJPROP_TEXT, textInput);
//--- definir o texto fonte
ObjectSetString(0, editName, OBJPROP_FONT, fontName);
//--- definir tamanho da fonte
ObjectSetInteger(0, editName, OBJPROP_FONTSIZE, fontSize);
//--- definir o ângulo de inclinação do texto
ObjectSetDouble(0, editName, OBJPROP_ANGLE, 0.0);
//--- definir cor
ObjectSetInteger(0, editName, OBJPROP_COLOR, fontColor);
//--- definir a cor de fundo
ObjectSetInteger(0, editName, OBJPROP_BGCOLOR, bgColor);
//--- exibir em primeiro plano (false) ou fundo (true)
ObjectSetInteger(0, editName, OBJPROP_BACK, false);
//--- Habilitar (true) ou desabilitar (false) o modo de movimento da etiqueta pelo mouse
ObjectSetInteger(0, editName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, editName, OBJPROP_SELECTED, false);
//--- ocultar (true) ou exibir (false) o nome do objeto gráfico na lista de objeto
ObjectSetInteger(0, editName, OBJPROP_HIDDEN, false);
//--- definir a prioridade para receber o evento com um clique do mouse no gráfico
ObjectSetInteger(0, editName, OBJPROP_ZORDER, 10);
return editName;
}
bool CEdit :: IsActive() {
return active;
}
string CEdit :: GetValue() {
return ObjectGetString(0, editName, OBJPROP_TEXT);
}
void CEdit :: SetValue(string newText) {
ObjectSetString(0, editName, OBJPROP_TEXT, newText);
}
void CEdit :: Destroy() {
active = false;
ObjectDelete(0, editName);
}
};
class CButton {
public:
ulong xi, yi, xf, yf;
int buttonLayer;
string buttonName;
bool active;
string buttonText;
long buttonWidth;
long buttonHeight;
long buttonPositionX;
long buttonPositionY;
string buttonFontName;
int buttonFontSize;
color buttonFontColor;
color buttonBackgroundColor;
color buttonBorderColor;
color buttonHoverColor;
ENUM_BASE_CORNER buttonReferenceCorner;
CButton :: CButton() {}
CButton :: CButton(int layer,
string name,
string text,
long width,
long height,
long positionX,
long positionY,
string fontName = DEFAULT_FONT,
int fontSize = DEFAULT_FONT_SIZE,
color fontColor = FONT_COLOR,
color backgroundColor = SECONDARY_COLOR,
color borderColor = SECONDARY_COLOR,
color hoverColor = SECONDARY_COLOR,
ENUM_BASE_CORNER referenceCorner = CORNER_LEFT_UPPER) {
active = false;
buttonName = IntegerToString(layer) + "_" + name;
buttonLayer = layer;
buttonText = text;
buttonWidth = width;
buttonHeight = height;
buttonPositionX = positionX;
buttonPositionY = positionY;
buttonFontName = fontName;
buttonFontSize = fontSize;
buttonFontColor = fontColor;
buttonBackgroundColor = backgroundColor;
buttonBorderColor = borderColor;
buttonHoverColor = hoverColor;
buttonReferenceCorner = referenceCorner;
}
CButton :: CButton(const CButton &) {}
string CButton :: Draw(long positionX = NULL, long positionY = NULL) {
buttonPositionX = positionX == NULL ? buttonPositionX : positionX;
buttonPositionY = positionY == NULL ? buttonPositionY : positionY;
active = true;
ObjectCreate(0,
buttonName,
OBJ_BUTTON,
0,
0,
0);
//--- definir coordenadas do botão
ObjectSetInteger(0, buttonName, OBJPROP_XDISTANCE, buttonPositionX);
ObjectSetInteger(0, buttonName, OBJPROP_YDISTANCE, buttonPositionY);
xi = buttonPositionX;
yi = buttonPositionY;
//--- definir tamanho do botão
ObjectSetInteger(0, buttonName, OBJPROP_XSIZE, buttonWidth);
ObjectSetInteger(0, buttonName, OBJPROP_YSIZE, buttonHeight);
xf = xi + buttonWidth;
yf = yi + buttonHeight;
//--- determinar o canto do gráfico onde as coordenadas do ponto são definidas
ObjectSetInteger(0, buttonName, OBJPROP_CORNER, buttonReferenceCorner);
//--- definir o texto
ObjectSetString(0, buttonName, OBJPROP_TEXT, buttonText);
//--- definir o texto fonte
ObjectSetString(0, buttonName, OBJPROP_FONT, buttonFontName);
//--- definir tamanho da fonte
ObjectSetInteger(0, buttonName, OBJPROP_FONTSIZE, buttonFontSize);
//--- definir a cor do texto
ObjectSetInteger(0, buttonName, OBJPROP_COLOR, buttonFontColor);
//--- definir a cor de fundo
ObjectSetInteger(0, buttonName, OBJPROP_BGCOLOR, buttonBackgroundColor);
//--- definir a cor da borda
ObjectSetInteger(0, buttonName, OBJPROP_BORDER_COLOR, buttonBorderColor);
//--- exibir em primeiro plano (false) ou fundo (true)
ObjectSetInteger(0, buttonName, OBJPROP_BACK, false);
//--- set button state
ObjectSetInteger(0, buttonName, OBJPROP_STATE, false);
//--- habilitar (true) ou desabilitar (false) o modo do movimento do botão com o mouse
ObjectSetInteger(0, buttonName, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, buttonName, OBJPROP_SELECTED, false);
//--- ocultar (true) ou exibir (false) o nome do objeto gráfico na lista de objeto
ObjectSetInteger(0, buttonName, OBJPROP_HIDDEN, false);
//--- definir a prioridade para receber o evento com um clique do mouse no gráfico
ObjectSetInteger(0, buttonName, OBJPROP_ZORDER, 10);
return buttonName;
}
bool CButton :: OnClick() {
if((bool)ObjectGetInteger(0,
buttonName,
OBJPROP_STATE)) {
ObjectSetInteger(0,
buttonName,
OBJPROP_STATE,
false);
return true;
}
return false;
}
bool CButton :: State() {
return (bool)ObjectGetInteger(0,
buttonName,
OBJPROP_STATE);
}
bool CButton :: Hover(uint mouseX,
uint mouseY) {
if((mouseX > xi && mouseX < xf) &&
(mouseY > yi && mouseY < yf)) {
ChangeColor(buttonHoverColor, buttonHoverColor);
return true;
}
ChangeColor(buttonBackgroundColor, buttonBorderColor);
return false;
}
void CButton :: SetState(bool newState) {
ObjectSetInteger(0,
buttonName,
OBJPROP_STATE,
newState);
}
void CButton :: ChangeState() {
if(State() == true)
SetState(false);
if(State() == false)
SetState(true);
}
void CButton ::ChangeColor(color newBGColor,
color newBorderColor) {
ObjectSetInteger(0, buttonName, OBJPROP_BGCOLOR, newBGColor);
ObjectSetInteger(0, buttonName, OBJPROP_BORDER_COLOR, newBorderColor);
}
void CButton :: ChangeText(string text) {
ObjectSetString(0, buttonName, OBJPROP_TEXT, text);
}
string CButton :: GetText() {
return buttonText;
}
bool CButton :: IsActive() {
return active;
}
void CButton :: Destroy() {
active = false;
ObjectDelete(0, buttonName);
}
};
class CDropdown {
public:
CButton elements[];
CDropdown :: CDropdown();
CDropdown :: CDropdown(CButton& items[]);
CDropdown :: ~CDropdown();
void CDropdown :: Open();
void CDropdown :: Close();
void CDropdown :: Destroy();
};
//+------------------------------------------------------------------+
//| Constructors |
//+------------------------------------------------------------------+
CDropdown :: CDropdown() {}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CDropdown :: CDropdown(CButton& items[]) {
ArrayResize(elements, ArraySize(items));
for(int i = 0; i < ArraySize(items); i++) {
elements[i] = items[i];
}
}
//+------------------------------------------------------------------+
//| Dropdown open function |
//+------------------------------------------------------------------+
void CDropdown :: Open() {
for(int i = 0; i < ArraySize(elements); i++) {
elements[i].Draw(elements[i].buttonPositionX,
elements[i].buttonPositionY + i*elements[i].buttonHeight);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CDropdown :: Close() {
for(int i = 0; i < ArraySize(elements); i++) {
elements[i].buttonPositionY = elements[i].buttonPositionY - i*elements[i].buttonHeight;
elements[i].Destroy();
ChartRedraw();
}
}
//+------------------------------------------------------------------+