TesterStatistics
Hàm trả về giá trị của tham số thống kê được chỉ định, được tính toán dựa trên kết quả kiểm tra.
cpp
double TesterStatistics(
ENUM_STATISTICS statistic_id // ID
);
1
2
3
2
3
Tham số
statistic_id
[truyền vào] ID của tham số thống kê từ liệt kê ENUM_STATISTICS
.
Giá trị trả về
Giá trị của tham số thống kê từ kết quả kiểm tra.
Ghi chú
Hàm có thể được gọi bên trong OnTester()
hoặc OnDeinit()
trong trình kiểm tra. Trong các trường hợp khác, kết quả không xác định.
Ví dụ:
cpp
// EA dựa trên tệp chuẩn "MACD Sample.mq5"
// hiển thị kết quả của TesterStatistics() trong trình xử lý sự kiện Tester
#define MACD_MAGIC 1234502
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
input double InpLots =0.1; // Lots
input int InpTakeProfit =50; // Take Profit (tính bằng pip)
input int InpTrailingStop =30; // Trailing Stop Level (tính bằng pip)
input int InpMACDOpenLevel =3; // MACD open level (tính bằng pip)
input int InpMACDCloseLevel=2; // MACD close level (tính bằng pip)
input int InpMATrendPeriod =26; // MA trend period
//+------------------------------------------------------------------+
//| Hàm khởi tạo Expert |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- tạo tất cả các đối tượng cần thiết
if(!ExtExpert.Init())
return(INIT_FAILED);
//--- khởi tạo thành công
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Hàm xử lý tick mới của Expert |
//+------------------------------------------------------------------+
void OnTick(void)
{
static datetime limit_time=0; // thời gian gọi cuối cùng tính đến 'timeout'
//--- nếu thời gian vượt quá giá trị limit_time được chỉ định
if(TimeCurrent()>=limit_time)
{
//--- kiểm tra dữ liệu
if(Bars(Symbol(),Period())>2*InpMATrendPeriod)
{
//--- nếu thành công, tăng limit_time thêm 'timeout' giây
if(ExtExpert.Processing())
limit_time=TimeCurrent()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+
//| Hàm xử lý kiểm tra Expert |
//+------------------------------------------------------------------+
double OnTester(void)
{
double ret=TesterStatistics(STAT_PROFIT_FACTOR);
double profit=TesterStatistics(STAT_PROFIT);
int trades_total=(int)TesterStatistics(STAT_TRADES);
int profit_total=(int)TesterStatistics(STAT_PROFIT_TRADES);
int loss_total=(int)TesterStatistics(STAT_LOSS_TRADES);
PrintFormat("%s: Profit = %.2f, trades total: %lu, profit trades total: %lu, loss trades total: %lu, profit factor: %.2f",__FUNCTION__,profit,trades_total,profit_total,loss_total,ret);
return(ret);
/*
Kết quả:
OnTester: Profit = 209.84, trades total: 13, profit trades total: 11, loss trades total: 2, profit factor: 3.02
final balance 10209.84 USD
OnTester result 3.020606644198363
*/
}
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
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