int _AppliedTo
Biến _AppliedTo
cho phép tìm hiểu loại dữ liệu được sử dụng để tính toán chỉ báo:
Loại dữ liệu | Ý nghĩa | Mô tả dữ liệu được sử dụng để tính toán chỉ báo |
---|---|---|
— | 0 | Chỉ báo sử dụng dạng gọi thứ hai của OnCalculate() - dữ liệu để tính toán không được chỉ định bởi một bộ đệm hoặc mảng dữ liệu cụ thể |
Close | 1 | Giá đóng cửa |
Open | 2 | Giá mở cửa |
High | 3 | Giá cao nhất |
Low | 4 | Giá thấp nhất |
Median Price (HL/2) | 5 | Giá trung bình = (High+Low)/2 |
Typical Price (HLC/3) | 6 | Giá điển hình = (High+Low+Close)/3 |
Weighted Price (HLCC/4) | 7 | Giá có trọng số = (Open+High+Low+Close)/4 |
Previous Indicator's Data | 8 | Dữ liệu của chỉ báo được khởi chạy trên biểu đồ trước chỉ báo này |
First Indicator's Data | 9 | Dữ liệu của chỉ báo được khởi chạy đầu tiên trên biểu đồ |
Indicator handle | 10+ | Dữ liệu của chỉ báo được truyền vào hàm iCustom() bằng cách sử dụng tay cầm chỉ báo. Giá trị _AppliedTo chứa tay cầm chỉ báo |
Ví dụ:
cpp
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
// Getting the type of data used for indicator calculation
Print("_AppliedTo=",_AppliedTo);
Print(getIndicatorDataDescription(_AppliedTo));
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Description of data used for indicator calculation |
//+------------------------------------------------------------------+
string getIndicatorDataDescription(int data_id)
{
string descr="";
switch(data_id)
{
case(0):descr="It's first type of OnCalculate() - no data buffer";
break;
case(1):descr="Indicator calculates on Close price";
break;
case(2):descr="Indicator calculates on Open price";
break;
case(3):descr="Indicator calculates on High price";
break;
case(4):descr="Indicator calculates on Low price";
break;
case(5):descr="Indicator calculates on Median Price (HL/2)";
break;
case(6):descr="Indicator calculates on Typical Price (HLC/3)";
break;
case(7):descr="Indicator calculates on Weighted Price (HLCC/4)";
break;
case(8):descr="Indicator calculates Previous Indicator's data";
break;
case(9):descr="Indicator calculates on First Indicator's data";
break;
default: descr="Indicator calculates on data of indicator with handle="+string(data_id);
break;
}
//---
return descr;
}
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
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
Xem thêm