ObjectSetDouble
ObjectSetDouble
此函数用于设置相应对象属性的值。该对象属性必须是双精度浮点型类型。该函数有两种变体。
设置属性值,不带修饰符。
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
[输入] 图表标识符。0表示当前图表。
- object_name
[输入] 对象名称。
- prop_id
[输入] 对象属性的ID。ENUM_OBJECT_PROPERTY_DOUBLE枚举中的值之一。
- prop_modifier
[输入] 指定属性的修饰符。它表示斐波那契工具和图形对象Andrew的叉状图的层级编号。层级编号从零开始。
- prop_value
[输入] 属性的值。
返回值
只有当更改图形对象属性的命令成功发送到图表时,该函数才会返回true。否则返回false。要了解更多关于错误的信息,请调用GetLastError()。
注意
当此函数用于当前图表时,会直接访问该图表并立即返回结果。要在不同图表上设置对象属性,则使用异步调用。异步调用意味着该函数不会等待添加到另一个图表队列中的命令的执行。相反,它会立即返回控制。
要检查其他图表(非当前图表)上命令执行的结果,可以使用检查指定对象属性的函数。但是,您应该记住,此类函数被添加到该图表的队列末尾,并等待执行结果,因此可能会耗时较长。在处理图表上的大量对象时,应考虑此特性。
创建斐波那契对象并在其中添加新层级的示例
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- auxiliary arrays
double high[],low[],price1,price2;
datetime time[],time1,time2;
//--- Copy the open prices - 100 latest bars are enough
int copied=CopyHigh(Symbol(),0,0,100,high);
if(copied<=0)
{
Print("Failed to copy the values of the High price series");
return;
}
//--- Copy the close price - 100 latest bars are enough
copied=CopyLow(Symbol(),0,0,100,low);
if(copied<=0)
{
Print("Failed to copy the values of the Low price series");
return;
}
//--- Copy the open time for the last 100 bars
copied=CopyTime(Symbol(),0,0,100,time);
if(copied<=0)
{
Print("Failed to copy the values of the price series of Time");
return;
}
//--- Organize access to the copied data as to timeseries - backwards
ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
ArraySetAsSeries(time,true);
//--- Coordinates of the first anchor point of the Fibo object
price1=high[70];
time1=time[70];
//--- Coordinates of the second anchor point of the Fibo object
price2=low[50];
time2=time[50];
//--- Time to create the Fibo object
bool created=ObjectCreate(0,"Fibo",OBJ_FIBO,0,time1,price1,time2,price2);
if(created) // If the object is created successfully
{
//--- set the color of Fibo levels
ObjectSetInteger(0,"Fibo",OBJPROP_LEVELCOLOR,Blue);
//--- by the way, how much Fibo levels do we have?
int levels=ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS);
Print("Fibo levels before = ",levels);
//---output to the Journal => number of level:value level_desription
for(int i=0;i<levels;i++)
{
Print(i,": ",ObjectGetDouble(0,"Fibo",OBJPROP_LEVELVALUE,i),
" ",ObjectGetString(0,"Fibo",OBJPROP_LEVELTEXT,i));
}
//--- Try to increase the number of levels per unit
bool modified=ObjectSetInteger(0,"Fibo",OBJPROP_LEVELS,levels+1);
if(!modified) // failed to change the number of levels
{
Print("Failed to change the number of levels of Fibo, error ",GetLastError());
}
//--- just inform
Print("Fibo levels after = ",ObjectGetInteger(0,"Fibo",OBJPROP_LEVELS));
//--- set a value for a newly created level
bool added=ObjectSetDouble(0,"Fibo",OBJPROP_LEVELVALUE,levels,133);
if(added) // managed to set a value for the level
{
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);
//--- once again output all levels - just to make sure
for(int i=0;i<levels;i++)
{
Print(i,":",ObjectGetDouble(0,"Fibo",OBJPROP_LEVELVALUE,i),
" ",ObjectGetString(0,"Fibo",OBJPROP_LEVELTEXT,i));
}
}
else // Fails if you try to increase the number of levels in the Fibo object
{
Print("Failed to set one more Fibo level. Error ",GetLastError());
}
}
}另请参阅
最后更新于