-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderQueue.mqh
More file actions
262 lines (220 loc) · 8.14 KB
/
OrderQueue.mqh
File metadata and controls
262 lines (220 loc) · 8.14 KB
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
//+------------------------------------------------------------------+
//| CCOrderQueue.mqh |
//| Copyright 2014, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#include <Object.mqh>
#include <Arrays\List.mqh>
#include "OrderInfo.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class COrderQueue : public CObject
{
private:
// ñ÷åò÷èêè ðàçìåðà îðäåðîâ
double m_sell_size;
double m_buy_size;
double m_sell_stop_size;
double m_buy_stop_size;
// ñ÷åò÷èêè êîëè÷åñòâà îðäåðîâ
int m_total_sell;
int m_total_buy;
int m_total_sell_stop;
int m_total_buy_stop;
// ñ÷åò÷èêè òîðãîâûõ ñåðèé
int m_counters[3];
int m_counters_old[3];
COrderInfo* m_last_buy;
COrderInfo* m_last_sell;
CList* m_pOrderList;
void ZeroCounters();
public:
COrderQueue();
~COrderQueue();
void Update();
CList* GetList();
double GetSellSize();
double GetSellStopSize();
double GetBuySize();
double GetBuyStopSize();
COrderInfo* GetLastBuy();
COrderInfo* GetLastSell();
int GetTotalSell();
int GetTotalBuy();
int GetTotalSellStop();
int GetTotalBuyStop();
bool IsSeriesEnded();
bool HasPendingOrders();
};
//+------------------------------------------------------------------+
//| Ïðèçíàê íàëè÷èÿ â î÷åðåäè îòëîæåííûõ îðäåðîâ |
//+------------------------------------------------------------------+
bool COrderQueue::HasPendingOrders(void)
{
return m_pOrderList.Total() > 0 && m_pOrderList.Total() != m_total_buy + m_total_sell;
}
//+------------------------------------------------------------------+
//| Ññûëêà íà ïîñëåäíèé àêòèâíûé îðäåð íà ïîêóïêó |
//+------------------------------------------------------------------+
COrderInfo* COrderQueue::GetLastBuy()
{
return m_last_buy;
}
//+------------------------------------------------------------------+
//| Ññûëêà íà ïîñëåäíèé àêòèâíûé îðäåð íà ïðîäàæó |
//+------------------------------------------------------------------+
COrderInfo* COrderQueue::GetLastSell()
{
return m_last_sell;
}
//+------------------------------------------------------------------+
//| Ïðèçíàê òîãî, ÷òî ñåðèÿ ñäåëîê çàêîí÷èëàñü |
//+------------------------------------------------------------------+
bool COrderQueue::IsSeriesEnded(void)
{
if (ArrayCompare(m_counters, m_counters_old) != 0) {
if ((m_counters[1] != 0 && m_counters[1] < m_counters_old[1])
|| (m_counters[2] != 0 && m_counters[2] < m_counters_old[2])) {
return true;
}
}
return false;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò êîëè÷åñòâî âñåõ îòêðûòûõ ïîçèöèé íà ïîêóïêó |
//+------------------------------------------------------------------+
int COrderQueue::GetTotalBuy(void)
{
return m_total_buy;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò êîëè÷åñòâî âñåõ îòêðûòûõ ïîçèöèé íà ïðîäàæó |
//+------------------------------------------------------------------+
int COrderQueue::GetTotalSell(void)
{
return m_total_sell;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò êîëè÷åñòâî âñåõ îòëîæåííûõ ïîçèöèé íà ïðîäàæó |
//+------------------------------------------------------------------+
int COrderQueue::GetTotalSellStop(void)
{
return m_total_sell_stop;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò êîëè÷åñòâî âñåõ îòëîæåííûõ ïîçèöèé íà ïîêóïêó |
//+------------------------------------------------------------------+
int COrderQueue::GetTotalBuyStop(void)
{
return m_total_buy_stop;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò ðàçìåð âñåõ îòêðûòûõ ïîçèöèé íà ïîêóïêó |
//+------------------------------------------------------------------+
double COrderQueue::GetBuySize(void)
{
return m_buy_size;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò ðàçìåð âñåõ îòêðûòûõ ïîçèöèé íà ïðîäàæó |
//+------------------------------------------------------------------+
double COrderQueue::GetSellSize(void)
{
return m_sell_size;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò ðàçìåð âñåõ îòëîæåííûõ ïîçèöèé íà ïîêóïêó |
//+------------------------------------------------------------------+
double COrderQueue::GetBuyStopSize(void)
{
return m_buy_stop_size;
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò ðàçìåð âñåõ îòëîæåííûõ ïîçèöèé íà ïðîäàæó |
//+------------------------------------------------------------------+
double COrderQueue::GetSellStopSize(void)
{
return m_sell_stop_size;
}
//+------------------------------------------------------------------+
//| Îáíîâëÿåò ñ÷åò÷èêè î÷åðåäè |
//+------------------------------------------------------------------+
void COrderQueue::Update()
{
int total, pos, magic;
COrderInfo* order;
ZeroCounters();
m_pOrderList.Clear();
m_last_buy = NULL;
m_last_sell = NULL;
ArrayCopy(m_counters_old, m_counters);
total = OrdersTotal();
for (pos = 0; pos < total; pos++) {
order = new COrderInfo();
if (order.SelectByIndex(pos)) {
m_pOrderList.Add(order);
if (order.GetType() == OP_BUY) {
m_total_buy += 1;
m_buy_size += order.GetVolume();
m_last_buy = order;
} else if (order.GetType() == OP_SELL) {
m_total_sell += 1;
m_sell_size += order.GetVolume();
m_last_sell = order;
} else if (order.GetType() == OP_SELLSTOP) {
m_total_sell_stop += 1;
m_sell_stop_size += order.GetVolume();
} else if (order.GetType() == OP_BUYSTOP) {
m_total_buy_stop += 1;
m_buy_stop_size += order.GetVolume();
}
if (!order.IsPending()) {
magic = order.GetMagic();
m_counters[magic] += 1;
}
}
}
}
//+------------------------------------------------------------------+
//| Âîçâðàùàåò óêàçàòåëü íà ñïèñîê îðäåðîâ |
//+------------------------------------------------------------------+
CList* COrderQueue::GetList(void)
{
return m_pOrderList;
}
//+------------------------------------------------------------------+
//| Îáíóëÿåò ñ÷åò÷èêè î÷åðåäè |
//+------------------------------------------------------------------+
void COrderQueue::ZeroCounters(void)
{
m_total_buy = 0;
m_total_sell = 0;
m_total_sell_stop = 0;
m_total_buy_stop = 0;
m_sell_size = 0;
m_buy_size = 0;
m_sell_stop_size = 0;
m_buy_stop_size = 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
COrderQueue::COrderQueue()
{
m_pOrderList = new CList();
ArrayInitialize(m_counters, 0);
Update();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
COrderQueue::~COrderQueue()
{
delete m_pOrderList;
}
//+------------------------------------------------------------------+