Phương thức liên kết đối tượng
Các đối tượng đồ họa Text
, Label
, Bitmap
và Bitmap Label
(OBJ_TEXT
, OBJ_LABEL
, OBJ_BITMAP
và OBJ_BITMAP_LABEL
) có thể có một trong 9 cách liên kết tọa độ khác nhau được định nghĩa bởi thuộc tính OBJPROP_ANCHOR
.
Đối tượng | ID | X/Y | Width/Height | Date/Price | OBJPROP_CORNER | OBJPROP_ANCHOR | OBJPROP_ANGLE |
---|---|---|---|---|---|---|---|
Text | OBJ_TEXT | — | — | Yes | — | Yes | Yes |
Label | OBJ_LABEL | Yes | Yes (read only) | — | Yes | Yes | Yes |
Button | OBJ_BUTTON | Yes | Yes | — | Yes | — | — |
Bitmap | OBJ_BITMAP | — | Yes (read only) | Yes | — | Yes | — |
Bitmap Label | OBJ_BITMAP_LABEL | Yes | Yes (read only) | — | Yes | Yes | — |
Edit | OBJ_EDIT | Yes | Yes | — | Yes | — | — |
Rectangle Label | OBJ_RECTANGLE_LABEL | Yes | Yes | — | Yes | — | — |
Các ký hiệu sau được sử dụng trong bảng:
X/Y
– tọa độ của các điểm neo được xác định bằng pixel so với góc của biểu đồ;Width/Height
– các đối tượng có chiều rộng và chiều cao. Đối với "read only", giá trị chiều rộng và chiều cao chỉ được tính một lần khi đối tượng được hiển thị trên biểu đồ;Date/Price
– tọa độ điểm neo được xác định bằng giá trị ngày và giá;OBJPROP_CORNER
– xác định góc của biểu đồ mà tọa độ điểm neo được xác định tương đối. Có thể là một trong 4 giá trị của liệt kêENUM_BASE_CORNER
;OBJPROP_ANCHOR
– xác định điểm neo trong chính đối tượng và có thể là một trong 9 giá trị của liệt kêENUM_ANCHOR_POINT
. Tọa độ bằng pixel được xác định từ điểm này đến góc biểu đồ được chọn;OBJPROP_ANGLE
– xác định góc xoay của đối tượng ngược chiều kim đồng hồ.
Biến thể cần thiết có thể được chỉ định bằng hàm ObjectSetInteger
(chart_handle, object_name, OBJPROP_ANCHOR
, anchor_point_mode), trong đó anchor_point_mode là một trong các giá trị của ENUM_ANCHOR_POINT
.
ENUM_ANCHOR_POINT
ID | Mô tả |
---|---|
ANCHOR_LEFT_UPPER | Điểm neo ở góc trên bên trái |
ANCHOR_LEFT | Điểm neo ở bên trái tại trung tâm |
ANCHOR_LEFT_LOWER | Điểm neo ở góc dưới bên trái |
ANCHOR_LOWER | Điểm neo ở dưới tại trung tâm |
ANCHOR_RIGHT_LOWER | Điểm neo ở góc dưới bên phải |
ANCHOR_RIGHT | Điểm neo ở bên phải tại trung tâm |
ANCHOR_RIGHT_UPPER | Điểm neo ở góc trên bên phải |
ANCHOR_UPPER | Điểm neo ở trên tại trung tâm |
ANCHOR_CENTER | Điểm neo chính xác ở trung tâm của đối tượng |
Các đối tượng OBJ_BUTTON
, OBJ_RECTANGLE_LABEL
, OBJ_EDIT
và OBJ_CHART
có điểm neo cố định ở góc trên bên trái (ANCHOR_LEFT_UPPER
).
Ví dụ:
string text_name="my_OBJ_TEXT_object";
if(ObjectFind(0,text_name)<0)
{
Print("Object ",text_name," not found. Error code = ",GetLastError());
//--- Get the maximal price of the chart
double chart_max_price=ChartGetDouble(0,CHART_PRICE_MAX,0);
//--- Create object Label
ObjectCreate(0,text_name,OBJ_TEXT,0,TimeCurrent(),chart_max_price);
//--- Set color of the text
ObjectSetInteger(0,text_name,OBJPROP_COLOR,clrWhite);
//--- Set background color
ObjectSetInteger(0,text_name,OBJPROP_BGCOLOR,clrGreen);
//--- Set text for the Label object
ObjectSetString(0,text_name,OBJPROP_TEXT,TimeToString(TimeCurrent()));
//--- Set text font
ObjectSetString(0,text_name,OBJPROP_FONT,"Trebuchet MS");
//--- Set font size
ObjectSetInteger(0,text_name,OBJPROP_FONTSIZE,10);
//--- Bind to the upper right corner
ObjectSetInteger(0,text_name,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
//--- Rotate 90 degrees counter-clockwise
ObjectSetDouble(0,text_name,OBJPROP_ANGLE,90);
//--- Forbid the selection of the object by mouse
ObjectSetInteger(0,text_name,OBJPROP_SELECTABLE,false);
//--- redraw object
ChartRedraw(0);
}
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
Các đối tượng đồ họa Arrow (OBJ_ARROW
) chỉ có 2 cách liên kết tọa độ của chúng. Các định danh được liệt kê trong ENUM_ARROW_ANCHOR
.
ENUM_ARROW_ANCHOR
ID | Mô tả |
---|---|
ANCHOR_TOP | Điểm neo ở phía trên |
ANCHOR_BOTTOM | Điểm neo ở phía dưới |
Ví dụ:
void OnStart()
{
//--- Auxiliary arrays
double Ups[],Downs[];
datetime Time[];
//--- Set the arrays as timeseries
ArraySetAsSeries(Ups,true);
ArraySetAsSeries(Downs,true);
ArraySetAsSeries(Time,true);
//--- Create handle of the Indicator Fractals
int FractalsHandle=iFractals(NULL,0);
Print("FractalsHandle = ",FractalsHandle);
//--- Set Last error value to Zero
ResetLastError();
//--- Try to copy the values of the indicator
int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups);
if(copied<=0)
{
Print("Unable to copy the upper fractals. Error = ",GetLastError());
return;
}
ResetLastError();
//--- Try to copy the values of the indicator
copied=CopyBuffer(FractalsHandle,1,0,1000,Downs);
if(copied<=0)
{
Print("Unable to copy the bottom fractals. Error = ",GetLastError());
return;
}
ResetLastError();
//--- Copy timeseries containing the opening bars of the last 1000 ones
copied=CopyTime(NULL,0,0,1000,Time);
if(copied<=0)
{
Print("Unable to copy the Opening Time of the last 1000 bars");
return;
}
int upcounter=0,downcounter=0; // count there the number of arrows
bool created;// receive the result of attempts to create an object
for(int i=2;i<copied;i++)// Run through the values of the indicator iFractals
{
if(Ups[i]!=EMPTY_VALUE)// Found the upper fractal
{
if(upcounter<10)// Create no more than 10 "Up" arrows
{
//--- Try to create an "Up" object
created=ObjectCreate(0,string(Time[i]),OBJ_ARROW_THUMB_UP,0,Time[i],Ups[i]);
if(created)// If set up - let's make tuning for it
{
//--- Point anchor is below in order not to cover bar
ObjectSetInteger(0,string(Time[i]),OBJPROP_ANCHOR,ANCHOR_BOTTOM);
//--- Final touch - painted
ObjectSetInteger(0,string(Time[i]),OBJPROP_COLOR,clrBlue);
upcounter++;
}
}
}
if(Downs[i]!=EMPTY_VALUE)// Found a lower fractal
{
if(downcounter<10)// Create no more than 10 arrows "Down"
{
//--- Try to create an object "Down"
created=ObjectCreate(0,string(Time[i]),OBJ_ARROW_THUMB_DOWN,0,Time[i],Downs[i]);
if(created)// If set up - let's make tuning for it
{
//--- Point anchor is above in order not to cover bar
ObjectSetInteger(0,string(Time[i]),OBJPROP_ANCHOR,ANCHOR_TOP);
//--- Final touch - painted
ObjectSetInteger(0,string(Time[i]),OBJPROP_COLOR,clrRed);
downcounter++;
}
}
}
}
}
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
Sau khi thực thi script, biểu đồ sẽ trông giống như trong hình này.