ObjectMove
ObjectMove
此函数会改变指定图表中对象指定锚点的坐标。该函数有两种变体:
bool ObjectMove(
string object_name, // object name
int point_index, // anchor point number
datetime time, // Time
double price // Price
);该函数会改变指定对象锚点的坐标。
bool ObjectMove(
string object_name, // object name
int point_index, // anchor point number
datetime time, // Time
double price // Price
);参数
- object_name
[in] 对象的名称。
- point_index
[in] 锚点的索引。锚点的数量取决于对象类型。
- time
[in] 所选锚点的时间坐标。
- price
[in] 所选锚点的价格坐标。
返回值
如果成功,返回 true;如果失败,返回 false。要了解更多关于错误的信息,请调用GetLastError()。
注意
该函数会移动图表中对象的坐标。根据对象类型不同,对象可以有一个到三个坐标。对象坐标从 0 开始编号。
当未指定图表 ID 时,该函数假定使用的是其直接访问的当前图表。在这种情况下,返回值表示函数的执行结果。
如果指定了当前图表之外的图表 ID,返回值仅表明命令是否已添加到该图表的队列中。在这种情况下,使用异步调用,这意味着函数不会等待已添加到其他图表队列的命令的执行。而是立即返回控制。
要检查其他图表而非当前图表的命令执行结果,可以使用检查指定对象属性的函数。但是,请注意,此类函数被添加到该图表的队列末尾并等待执行结果,因此可能会耗时较长。在处理图表上大量对象时,应考虑到这一特性。
示例:
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
int start()
{
string obj_name="trend_line";
long current_chart_id=ChartID();
//---
datetime t1=Time[0];
double p1=Close[0];
//---
datetime t2=Time[1];
double p2=Close[1];
//--- creating trend line object
if(!ObjectCreate(obj_name,OBJ_TREND,0,t1,p1,t2,p2))
{
Print("Error: can't create trend line! code #",GetLastError());
return(0);
}
//--- set color to Red
ObjectSetInteger(current_chart_id,obj_name,OBJPROP_COLOR,clrRed);
//--- moving of the trend line
for(int i=1; i<200; i++)
{
t2=Time[i];
p2=Close[i];
//--- move the 2nd anchor point of the trend line
ObjectMove(obj_name,1,t2,p2);
//--- forced chart redraw
ChartRedraw(current_chart_id);
Sleep(100);
}
//--- sleep to see the object
Sleep(3000);
//--- delete object
ObjectDelete(obj_name);
return(0);
}最后更新于