-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOperations.mqh
71 lines (57 loc) · 2.63 KB
/
Operations.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
//+------------------------------------------------------------------+
//| Operations.mqh |
//| Copyright 2022, Homma.tech |
//| https://www.homma.tech |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Homma.tech"
#property link "https://www.homma.tech"
#include <Trade/Trade.mqh>
#include "NewTypes.mqh"
class COperations {
protected:
CTrade tradeOperations;
public:
double COperations :: AccumulatedProfit(datetime initDate,
datetime finishDate,
string symbol_AP = NULL);
int COperations :: NumberOfTrades (datetime initDate,
datetime finishDate);
ulong COperations :: PastOperationTicket(int shift);
};
//+------------------------------------------------------------------+
//| Acumulated profit function |
//+------------------------------------------------------------------+
double COperations :: AccumulatedProfit(datetime initDate_AP,
datetime finishDate_AP,
string symbol_AP = NULL) {
double profitAcum = 0;
HistorySelect(initDate_AP, finishDate_AP);
for(int i = 1; i <= HistoryDealsTotal(); i++) {
ulong ticket = HistoryDealGetTicket(i);
profitAcum += HistoryDealGetDouble(ticket, DEAL_PROFIT);
}
if(PositionSelect(symbol_AP == NULL ? _Symbol : symbol_AP)) {
profitAcum += PositionGetDouble(POSITION_PROFIT);
}
return profitAcum;
}
//+------------------------------------------------------------------+
//| Number of trades in a period function |
//+------------------------------------------------------------------+
int COperations :: NumberOfTrades (datetime initDate,
datetime finishDate) {
HistorySelect(initDate, finishDate);
return HistoryDealsTotal();
}
//+------------------------------------------------------------------+
//| Past ticket function |
//+------------------------------------------------------------------+
ulong COperations :: PastOperationTicket(int shift) {
uint dealsTotal;
string today;
today = TimeToString(TimeLocal(), TIME_DATE);
HistorySelect(StringToTime(today), TimeCurrent());
dealsTotal = HistoryDealsTotal();
return HistoryDealGetTicket(dealsTotal - shift);
}
//+------------------------------------------------------------------+