当前位置:首页 > MQL4开发人员手册

物体函数 [Object Functions]

时间:2008-09-28 14:56:49  来源:  作者:

物体函数 [Object Functions]

<-- begin content -->
由 帝国程序员 在 周二, 2005-10-25 18:50 提交

bool ObjectCreate( string name, int type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)
创建物件

    :: 输入参数
    name - 物件名称
    type - 物件类型.
    window - 物件所在窗口的索引值
    time1 - 时间点1
    price1 - 价格点1
    time2 - 时间点2
    price2 - 价格点2
    time3 - 时间点3
    price3 - 价格点3

示例:

// 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);

bool ObjectDelete( string name)
删除物件

    :: 输入参数
    name - 物件名称

示例:

ObjectDelete("text_object");

string ObjectDescription( string name)
返回物件描述

    :: 输入参数
    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 ObjectFind( string name)
寻找物件,返回物件的索引值

    :: 输入参数
    name - 物件名称

示例:

if(ObjectFind("line_object2")!=win_idx) return(0);

double ObjectGet( string name, int index)
获取物件的值

    :: 输入参数
    name - 物件名称
    index - 取值属性的索引

示例:

color oldColor=ObjectGet("hline12", OBJPROP_COLOR);

string ObjectGetFiboDescription( string name, int index)
取物件的斐波纳契数列地描述

    :: 输入参数
    name - 物件名称
    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);
}

int ObjectGetShiftByValue( string name, double value)
取物件的位移值

    :: 输入参数
    name - 物件名称
    value - 价格

示例:

int shift=ObjectGetShiftByValue("MyTrendLine#123", 1.34);

double ObjectGetValueByShift( string name, int shift)
取物件位移后的值

    :: 输入参数
    name - 物件名称
    shift - 位移数

示例:

double price=ObjectGetValueByShift("MyTrendLine#123", 11);

bool ObjectMove( string name, int point, datetime time1, double price1)
移动物件

    :: 输入参数
    name - 物件名称
    point - 调整的索引
    time1 - 新的时间
    price1 - 新的价格

示例:

ObjectMove("MyTrend", 1, D'2005.02.25 12:30', 1.2345);

string ObjectName( int index)
取物件名称

    :: 输入参数
    index - 物件的索引

示例:

int obj_total=ObjectsTotal();
string name;
for(int i=0;i {
name=ObjectName(i);
Print(i,"Object name is " + name);
}

int ObjectsDeleteAll( int window, int type=EMPTY)
删除所有物件

    :: 输入参数
    window - 物件所在的窗口索引
    type - 删除物件的类型

示例:

ObjectsDeleteAll(2, OBJ_HLINE); // removes all horizontal line objects from window 3 (index 2).

bool ObjectSet( string name, int index, double value)
设置物件的值

    :: 输入参数
    name - 物件的名称
    index - 物件属性的索引值
    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);

bool ObjectSetFiboDescription( string name, int index, string text)
设置物件斐波纳契数列的描述

    :: 输入参数
    name - 物件的名称
    index - 物件斐波纳契数列的索引值
    text - 新的描述

示例:

ObjectSetFiboDescription("MyFiboObject,2,"Second line");

bool ObjectSetText( string name, string text, int font_size, string font=NULL, color text_color=CLR_NONE)
设置物件的描述

    :: 输入参数
    name - 物件的名称
    text - 文本
    font_size - 字体大小
    font - 字体名称
    text_color - 字体颜色

示例:

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);
}

int ObjectType( string name)
取物件类型

    :: 输入参数
    name - 物件的名称

示例:

if(ObjectType("line_object2")!=OBJ_HLINE) return(0);

来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
This site was designed & Modified by beok.net. Last ModiMon, 08/11/2008 0:05 AMe --> Beijing Time.