-
Notifications
You must be signed in to change notification settings - Fork 17
/
Symbol.mqh
203 lines (168 loc) · 6.54 KB
/
Symbol.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
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
class SYMBOL
{
public:
const string Name;
SYMBOL(const string Symb=NULL,const string Path=NULL) : Name((Symb==NULL) ? _Symbol : Symb)
{
if(!SYMBOL::SymbolIsExist(this.Name))
::CustomSymbolCreate(this.Name,Path);
}
static bool SymbolIsExist(const string Symb=NULL)
{
::ResetLastError();
::SymbolInfoInteger((Symb==NULL) ? _Symbol : Symb,SYMBOL_CUSTOM);
return(::GetLastError() != ERR_MARKET_UNKNOWN_SYMBOL);
}
bool SetProperty(const ENUM_SYMBOL_INFO_DOUBLE Property,double Value) const
{
return(::CustomSymbolSetDouble(this.Name, Property, Value));
}
bool SetProperty(const ENUM_SYMBOL_INFO_INTEGER Property,long Value) const
{
return(::CustomSymbolSetInteger(this.Name, Property, Value));
}
bool SetProperty(const ENUM_SYMBOL_INFO_STRING Property,string Value) const
{
return(::CustomSymbolSetString(this.Name, Property, Value));
}
long GetProperty(const ENUM_SYMBOL_INFO_INTEGER Property) const
{
return(::SymbolInfoInteger(this.Name, Property));
}
double GetProperty(const ENUM_SYMBOL_INFO_DOUBLE Property) const
{
return(::SymbolInfoDouble(this.Name, Property));
}
string GetProperty(const ENUM_SYMBOL_INFO_STRING Property) const
{
return(::SymbolInfoString(this.Name, Property));
}
bool Delete(void) const
{
return(this.IsCustom() && this.Off() && ::CustomSymbolDelete(this.Name));
}
#define CLONE(A) this.SetProperty(A, Source.GetProperty(A))
bool CloneProperties(const string Symb=NULL) const
{
const SYMBOL Source(Symb);
return(SYMBOL::SymbolIsExist(Symb) && this.IsCustom() &&
CLONE(SYMBOL_BASIS) &&
CLONE(SYMBOL_CURRENCY_BASE) &&
CLONE(SYMBOL_CURRENCY_MARGIN) &&
CLONE(SYMBOL_CURRENCY_PROFIT) &&
CLONE(SYMBOL_DESCRIPTION) &&
CLONE(SYMBOL_FORMULA) &&
CLONE(SYMBOL_ISIN) &&
CLONE(SYMBOL_PAGE) &&
CLONE(SYMBOL_PATH) &&
CLONE(SYMBOL_MARGIN_HEDGED) &&
CLONE(SYMBOL_MARGIN_INITIAL) &&
CLONE(SYMBOL_MARGIN_MAINTENANCE) &&
CLONE(SYMBOL_OPTION_STRIKE) &&
CLONE(SYMBOL_POINT) &&
CLONE(SYMBOL_SESSION_PRICE_LIMIT_MAX) &&
CLONE(SYMBOL_SESSION_PRICE_LIMIT_MIN) &&
CLONE(SYMBOL_SESSION_PRICE_SETTLEMENT) &&
CLONE(SYMBOL_SWAP_LONG) &&
CLONE(SYMBOL_SWAP_SHORT) &&
CLONE(SYMBOL_TRADE_ACCRUED_INTEREST) &&
CLONE(SYMBOL_TRADE_CONTRACT_SIZE) &&
CLONE(SYMBOL_TRADE_FACE_VALUE) &&
CLONE(SYMBOL_TRADE_LIQUIDITY_RATE) &&
CLONE(SYMBOL_TRADE_TICK_SIZE) &&
CLONE(SYMBOL_TRADE_TICK_VALUE) &&
CLONE(SYMBOL_VOLUME_LIMIT) &&
CLONE(SYMBOL_VOLUME_MAX) &&
CLONE(SYMBOL_VOLUME_MIN) &&
CLONE(SYMBOL_VOLUME_STEP) &&
CLONE(SYMBOL_BACKGROUND_COLOR) &&
CLONE(SYMBOL_CHART_MODE) &&
CLONE(SYMBOL_DIGITS) &&
CLONE(SYMBOL_EXPIRATION_MODE) &&
CLONE(SYMBOL_EXPIRATION_TIME) &&
CLONE(SYMBOL_FILLING_MODE) &&
CLONE(SYMBOL_MARGIN_HEDGED_USE_LEG) &&
CLONE(SYMBOL_OPTION_MODE) &&
CLONE(SYMBOL_OPTION_RIGHT) &&
CLONE(SYMBOL_ORDER_GTC_MODE) &&
CLONE(SYMBOL_ORDER_MODE) &&
CLONE(SYMBOL_SPREAD) &&
CLONE(SYMBOL_SPREAD_FLOAT) &&
CLONE(SYMBOL_START_TIME) &&
CLONE(SYMBOL_SWAP_MODE) &&
CLONE(SYMBOL_SWAP_ROLLOVER3DAYS) &&
CLONE(SYMBOL_TICKS_BOOKDEPTH) &&
CLONE(SYMBOL_TRADE_CALC_MODE) &&
CLONE(SYMBOL_TRADE_EXEMODE) &&
CLONE(SYMBOL_TRADE_FREEZE_LEVEL) &&
CLONE(SYMBOL_TRADE_MODE) &&
CLONE(SYMBOL_TRADE_STOPS_LEVEL));
}
#undef CLONE
int CloneHistory(string Symb=NULL) const
{
return(::MathMax(this.CloneRates(Symb), this.CloneTicks(Symb)));
}
int CloneRates(const MqlRates &Rates[]) const
{
return(this.IsCustom() ? ::CustomRatesReplace(this.Name, 0, LONG_MAX, Rates) : -1);
}
int CloneRates(string Symb=NULL) const
{
int Res=this.IsCustom() && SYMBOL::SymbolIsExist(Symb) ? 0 : -1;
if(Res!=-1)
{
Symb=(Symb==NULL) ? _Symbol : Symb;
MqlRates Rates[];
::CopyRates(Symb,PERIOD_M1,0,(int)::SeriesInfoInteger(Symb,PERIOD_M1,SERIES_BARS_COUNT),Rates);
Res=this.CloneRates(Rates);
}
return(Res);
}
int CloneTicks(const MqlTick &Ticks[]) const
{
return(this.IsCustom() ? ::CustomTicksReplace(this.Name, 0, LONG_MAX, Ticks) : -1);
}
int CloneTicks(string Symb=NULL) const
{
Symb=(Symb==NULL) ? _Symbol : Symb;
int Res=this.IsCustom() && ::SymbolInfoInteger(Symb,SYMBOL_CUSTOM) ? 0 : -1;
if(Res!=-1)
{
MqlTick Ticks[];
::CopyTicksRange(Symb,Ticks,COPY_TICKS_ALL,0,LONG_MAX);
Res=this.CloneTicks(Ticks);
}
return(Res);
}
bool Clone(const string Symb=NULL) const
{
return(this.CloneProperties(Symb) && (this.CloneHistory(Symb) != -1));
}
virtual bool operator=(const string Symb) const
{
return(this.Clone(Symb));
}
bool On(void) const
{
return(::SymbolSelect(this.Name, true));
}
bool Off(void) const
{
return(::SymbolSelect(this.Name, false));
}
bool IsCustom(void) const
{
return bool (this.GetProperty(SYMBOL_CUSTOM));
}
bool IsExist(void) const
{
return(SYMBOL::SymbolIsExist(this.Name));
}
};
//+------------------------------------------------------------------+