-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStatistics of candles.mq5
104 lines (101 loc) · 7.73 KB
/
Statistics of candles.mq5
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
//--- input parameters
input int InputCountBars = 1200; // Count of bars
input bool InpVerification = false; // Verification
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
enum ENUM_SERIES_TYPE
{
Bull=1, // ↑
Bear=-1, // ↓
};
//+------------------------------------------------------------------+
//| arr_series[][0]: series type |
//| arr_series[][1]: count of series |
//+------------------------------------------------------------------+
double arr_series[][2];
MqlRates rates[];
int copied=CopyRates(Symbol(),0,0,InputCountBars,rates);
if(copied==InputCountBars)
{
for(int i=0;i<copied;i++)
{
//--- here we define type of series
static int prev_series_type = 0;
int current_series_type = 0;
static int count_series = 0;
if(rates[i].open<rates[i].close)
current_series_type=Bull;
else if(rates[i].open>rates[i].close)
current_series_type=Bear;
else
continue;
//--- count of series
if(current_series_type==prev_series_type || prev_series_type==0)
count_series++;
else // generate the name of the series (only if the bar type has changed)
{
int name_series=current_series_type*count_series;
count_series=1;
//--- search for this series in an array and enter data
bool IsFound=false;
int size=ArrayRange(arr_series,0);
for(int j=0;j<size;j++)
{
//+------------------------------------------------------------------+
//| arr_series[][0]: series type |
//| arr_series[][1]: count of series |
//+------------------------------------------------------------------+
if(arr_series[j][0]==name_series)
{
IsFound=true;
arr_series[j][1]=arr_series[j][1]+1;
}
}
if(!IsFound)
{
ArrayResize(arr_series,size+1);
arr_series[size][0]=name_series;
arr_series[size][1]=1;
}
}
prev_series_type=current_series_type;
}
}
else
{
Print("Failed to get history data for the symbol ",Symbol(),". Bars copied ",copied," of ",InputCountBars);
return;
}
//---
ArraySort(arr_series);
//--- verification
if(InpVerification)
{
string out="";
string format="open = %G, high = %G, low = %G, close = %G, volume = %d";
for(int i=0;i<copied;i++)
{
out=IntegerToString(i)+":"+TimeToString(rates[i].time);
out=out+" "+StringFormat(format,
rates[i].open,
rates[i].high,
rates[i].low,
rates[i].close,
rates[i].tick_volume);
if(rates[i].open<rates[i].close)
out=out+" "+"Bull";
else if(rates[i].open>rates[i].close)
out=out+" "+"Bear";
Print(out);
}
Print("//| arr_series[][0]: series type |");
Print("//| arr_series[][1]: count of series |");
ArrayPrint(arr_series,0);
}
//---
}
//+------------------------------------------------------------------+