-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInputCheck.mqh
58 lines (49 loc) · 5.09 KB
/
InputCheck.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
//+------------------------------------------------------------------+
//| InputCheck.mqh |
//| Copyright 2021, Homma.tech |
//| https://www.homma.tech |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Homma.tech"
#property link "https://www.homma.tech"
class CInputCheck {
public:
bool CInputCheck :: VolumesOk(double volume,
string messageLassThanMin = NULL,
string messageGreaterThanMax = NULL,
string messageNotMultiple = NULL);
};
//+------------------------------------------------------------------+
//| Volume check |
//+------------------------------------------------------------------+
bool CInputCheck :: VolumesOk(double volume,
string messageLessThanMin = NULL,
string messageGreaterThanMax = NULL,
string messageNotMultiple = NULL) {
double min_volume = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double max_volume = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
double volume_step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
messageLessThanMin == NULL ?
messageLessThanMin = "Volume is less than the minimum to this symbol! \n Minimum volume: %2.f \n \n Please, try again with different value." :
NULL;
messageGreaterThanMax == NULL ?
messageGreaterThanMax = "Volume is greater than the maximum to this symbol! \n Maximum volume: %3.f \n \n Please, try again with different value." :
NULL;
messageNotMultiple == NULL ?
messageNotMultiple = "Volume is not a multiple of the minimum step to this symbol!\n Minimum step: %2.f \n \n Please, try again with different value." :
NULL;
if(volume < min_volume) {
MessageBox(StringFormat(messageLessThanMin, min_volume));
return false;
}
if(volume > max_volume) {
MessageBox(StringFormat(messageGreaterThanMax, max_volume));
return false;
}
int ratio = (int)MathRound(volume / volume_step);
if(MathAbs(ratio * volume_step - volume) > 0.0000001) {
MessageBox(StringFormat(messageNotMultiple, volume_step));
return false;
}
return true;
}
//+------------------------------------------------------------------+