物体函数 [Object Functions]
<-- begin content -->由 帝国程序员 在 周二, 2005-10-25 18:50 提交
bool ObjectDelete( string name)
删除物件
string ObjectDescription( string name)
返回物件描述
int ObjectFind( string name)
寻找物件,返回物件的索引值
double ObjectGet( string name, int index)
获取物件的值
string ObjectGetFiboDescription( string name, int index)
取物件的斐波纳契数列地描述
int ObjectGetShiftByValue( string name, double value)
取物件的位移值
double ObjectGetValueByShift( string name, int shift)
取物件位移后的值
bool ObjectMove( string name, int point, datetime time1, double price1)
移动物件
string ObjectName( int index)
取物件名称
int ObjectsDeleteAll( int window, int type=EMPTY)
删除所有物件
bool ObjectSet( string name, int index, double value)
设置物件的值
bool ObjectSetFiboDescription( string name, int index, string text)
设置物件斐波纳契数列的描述
bool ObjectSetText( string name, string text, int font_size, string font=NULL, color text_color=CLR_NONE)
设置物件的描述
void ObjectsRedraw( )
重绘所有物件
示例:
int ObjectsTotal( )
取物件总数
示例:
int ObjectType( string name)
取物件类型
bool ObjectCreate( string name, int type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)
创建物件
示例:
// new text object
if(!ObjectCreate("text_object", OBJ_TEXT, 0, D'2004.02.20 12:30', 1.0045))
{
Print("error: can't create text_object! code #",GetLastError());
return(0);
}
// new label object
if(!ObjectCreate("label_object", OBJ_LABEL, 0, 0, 0))
{
Print("error: can't create label_object! code #",GetLastError());
return(0);
}
ObjectSet("label_object", OBJPROP_XDISTANCE, 200);
ObjectSet("label_object", OBJPROP_YDISTANCE, 100);
if(!ObjectCreate("text_object", OBJ_TEXT, 0, D'2004.02.20 12:30', 1.0045))
{
Print("error: can't create text_object! code #",GetLastError());
return(0);
}
// new label object
if(!ObjectCreate("label_object", OBJ_LABEL, 0, 0, 0))
{
Print("error: can't create label_object! code #",GetLastError());
return(0);
}
ObjectSet("label_object", OBJPROP_XDISTANCE, 200);
ObjectSet("label_object", OBJPROP_YDISTANCE, 100);
bool ObjectDelete( string name)
删除物件
示例:
ObjectDelete("text_object");
string ObjectDescription( string name)
返回物件描述
示例:
// writing chart's object list to the file
int handle, total;
string obj_name,fname;
// file name
fname="objlist_"+Symbol();
handle=FileOpen(fname,FILE_CSV|FILE_WRITE);
if(handle!=false)
{
total=ObjectsTotal();
for(int i=-;i {
obj_name=ObjectName(i);
FileWrite(handle,"Object "+obj_name+" description= "+ObjectDescription(obj_name));
}
FileClose(handle);
}
int handle, total;
string obj_name,fname;
// file name
fname="objlist_"+Symbol();
handle=FileOpen(fname,FILE_CSV|FILE_WRITE);
if(handle!=false)
{
total=ObjectsTotal();
for(int i=-;i
obj_name=ObjectName(i);
FileWrite(handle,"Object "+obj_name+" description= "+ObjectDescription(obj_name));
}
FileClose(handle);
}
int ObjectFind( string name)
寻找物件,返回物件的索引值
示例:
if(ObjectFind("line_object2")!=win_idx) return(0);
double ObjectGet( string name, int index)
获取物件的值
示例:
color oldColor=ObjectGet("hline12", OBJPROP_COLOR);
string ObjectGetFiboDescription( string name, int index)
取物件的斐波纳契数列地描述
示例:
#include
...
string text;
for(int i=0;i<32;i++)
{
text=ObjectGetFiboDescription(MyObjectName,i);
//---- check. may be objects's level count less than 32
if(GetLastError()!=ERR_NO_ERROR) break;
Print(MyObjectName,"level: ",i," description: ",text);
}
...
string text;
for(int i=0;i<32;i++)
{
text=ObjectGetFiboDescription(MyObjectName,i);
//---- check. may be objects's level count less than 32
if(GetLastError()!=ERR_NO_ERROR) break;
Print(MyObjectName,"level: ",i," description: ",text);
}
int ObjectGetShiftByValue( string name, double value)
取物件的位移值
示例:
int shift=ObjectGetShiftByValue("MyTrendLine#123", 1.34);
double ObjectGetValueByShift( string name, int shift)
取物件位移后的值
示例:
double price=ObjectGetValueByShift("MyTrendLine#123", 11);
bool ObjectMove( string name, int point, datetime time1, double price1)
移动物件
示例:
ObjectMove("MyTrend", 1, D'2005.02.25 12:30', 1.2345);
string ObjectName( int index)
取物件名称
示例:
int obj_total=ObjectsTotal();
string name;
for(int i=0;i {
name=ObjectName(i);
Print(i,"Object name is " + name);
}
string name;
for(int i=0;i
name=ObjectName(i);
Print(i,"Object name is " + name);
}
int ObjectsDeleteAll( int window, int type=EMPTY)
删除所有物件
示例:
ObjectsDeleteAll(2, OBJ_HLINE); // removes all horizontal line objects from window 3 (index 2).
bool ObjectSet( string name, int index, double value)
设置物件的值
示例:
// moving first coord to last bar time
ObjectSet("MyTrend", OBJPROP_TIME1, Time[0]);
// setting second fibo level
ObjectSet("MyFibo", OBJPROP_FIRSTLEVEL+1, 1.234);
// setting object visibility. object will be shown only on 15 minute and 1 hour charts
ObjectSet("MyObject", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15 | OBJ_PERIOD_H1);
ObjectSet("MyTrend", OBJPROP_TIME1, Time[0]);
// setting second fibo level
ObjectSet("MyFibo", OBJPROP_FIRSTLEVEL+1, 1.234);
// setting object visibility. object will be shown only on 15 minute and 1 hour charts
ObjectSet("MyObject", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15 | OBJ_PERIOD_H1);
bool ObjectSetFiboDescription( string name, int index, string text)
设置物件斐波纳契数列的描述
示例:
ObjectSetFiboDescription("MyFiboObject,2,"Second line");
bool ObjectSetText( string name, string text, int font_size, string font=NULL, color text_color=CLR_NONE)
设置物件的描述
示例:
ObjectSetText("text_object", "Hello world!", 10, "Times New Roman", Green);
void ObjectsRedraw( )
重绘所有物件
示例:
ObjectsRedraw();
int ObjectsTotal( )
取物件总数
示例:
int obj_total=ObjectsTotal();
string name;
for(int i=0;i {
name=ObjectName(i);
Print(i,"Object name is for object #",i," is " + name);
}
string name;
for(int i=0;i
name=ObjectName(i);
Print(i,"Object name is for object #",i," is " + name);
}
int ObjectType( string name)
取物件类型
示例:
if(ObjectType("line_object2")!=OBJ_HLINE) return(0);
