函数设置相应对象属性的值。对象属性必须是双类型的。这个函数有两个变体。
设置属性值,不带修饰符。
bool ObjectSetDouble(
long chart_id, // 图表标识符chart identifier
string object_name, // 对象名称object name
int prop_id, // 属性property
double prop_value // 值value
);
设置一个属性值,指标修改器。
bool ObjectSetDouble(
long chart_id, // 图表标识符chart identifier
string object_name, // 对象名称object name
int prop_id, // 属性property
int prop_modifier, // 修饰符modifier
double prop_value // 值value
);
参数
chart_id
[in]表标识符。0表示当前图表。
object_name
以物体的名义。
prop_id
对象属性的ID。该值可以是ENUM_OBJECT_PROPERTY_DOUBLE枚举值之一。
prop_modifier
[in]指定属性的修饰符。它表示斐波那契工具和图形对象Andrew的干草叉中级别的数量。能级的计算从0开始。
prop_value
财产的价值。
返回值
只有当更改图形对象属性的命令成功发送到图表时,函数才返回true。否则返回false。要了解有关错误调用GetLastError()的更多信息,请参阅。
请注意
当在当前图表上使用此函数时,将直接访问此图表,并立即返回结果。为了在不同的图表上设置对象属性,使用异步调用。异步调用意味着函数不等待已添加到另一个图表队列的命令的执行。相反,它立即返回控制权。
要检查当前图表之外的命令执行结果,可以使用检查指定对象属性的函数。但是,您应该记住,这些函数被添加到图表队列的末尾,并等待执行结果,因此会很耗时。在处理图表上的大量对象时,应该考虑到这个特性。
创建斐波纳契对象并在其中添加新级别的示例:
//|脚本程序启动函数|
//---------------------------------+
void OnStart()
{
//---辅助数组
double 高组[],低组[],价坐标1,价坐标2;
datetime 时组[],时坐标1,时坐标2;
//---考贝开盘价- 100个最新的bars就够了
int copied=CopyHigh(Symbol(),0,0,100,高组);
if(copied<=0){
Print("未能将价格复制到最高价序列上");
return;
}
//---考贝收盘价- 100个最新的bars就够了
copied=CopyLow(Symbol(),0,0,100,低组);
if(copied<=0){
Print("未能将价格复制到最低价序列上");
return;
}
//--- 复制最后100棒的开盘时间
copied=CopyTime(Symbol(),0,0,100,时组);
if(copied<=0){
Print("未能将价格复制到开盘时间序列上");
return;
}
//--- 组织对复制数据的访问,就像对时间序列一样(方向向后)
ArraySetAsSeries(高组,true);
ArraySetAsSeries(低组,true);
ArraySetAsSeries(时组,true);
//--- Fibo对象的第一个锚点的坐标
价坐标1=高组[70];
时坐标1=时组[70];
//--- Fibo对象第二个锚点的坐标
价坐标2=低组[50];
时坐标2=时组[50];
//---该创建菲波对象了
bool created=ObjectCreate(0,"Fibo",OBJ_FIBO,0,时坐标1,价坐标1,时坐标2,价坐标2);
if(created){ //如果对象成功创建
//--- 设置Fibo水平的颜色
ObjectSetInteger(0,"Fibo",OBJPROP_LEVELCOLOR,Blue);
//--- 需要多少Fibo水平?
int levels=ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS);
Print("Fibo水平线 before = ",levels);
//---输出到日志=>水平值:水平值
for(int i=0;i<levels;i++){
Print(i,": ",ObjectGetDouble(0,"Fibo",OBJPROP_LEVELVALUE,i),
" ",ObjectGetString(0,"Fibo",OBJPROP_LEVELTEXT,i));
}
//--- 试着增加每一水平的数号
bool modified=ObjectSetInteger(0,"Fibo",OBJPROP_LEVELS,levels+1);
if(!modified){ //未能改水平数号
Print("更改菲波水平线失败,原因 ",GetLastError());
}
//--- 只是通知
Print("Fibo水平线 after = ",ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS));
//--- 设置一个值为新创建的水一线
bool added=ObjectSetDouble(0,"Fibo",OBJPROP_LEVELVALUE,levels,133);
if(added){ // 设置好一个值为水平线
Print("Successfully set one more Fibo level");
//--- Also do not forget to set the level description
ObjectSetString(0,"Fibo",OBJPROP_LEVELTEXT,levels,"my level");
ChartRedraw(0);
//--- Get the actual value of the number of levels in the Fibo object
levels=ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS);
Print("Fibo levels after adding = ",levels);
//--- 为了确保 再次输出所有水平线——
for(int i=0;i<levels;i++){
Print(i,":",ObjectGetDouble(0,"Fibo",OBJPROP_LEVELVALUE,i),
" ",ObjectGetString(0,"Fibo",OBJPROP_LEVELTEXT,i));
}
}
else{ // 如果您试图增加Fibo对象中的水平数
Print("未能设定一个调用Fibo水平。错误 ",GetLastError());
}
}
}
网友评论