IndicatorSetString
IndicatorSetString
函数建立类似指标属性值,指标属性必须是字符串型。有2个变量函数可以使用。
调用属性的指示标识符
bool IndicatorSetString(
int prop_id, // 标识符
string prop_value // 将被设置的值
);调用指示标识符和属性修饰语
bool IndicatorSetString(
int prop_id, // 标识符
int prop_modifier, // 修饰符
string prop_value // 将被设置的值
)参量
- prop_id
[in] 值可以是 ENUM_CUSTOMIND_PROPERTY_STRING 值中一个。
- prop_modifier
[in] 指定属性标识符,只有水平属性需要修饰语。
- prop_value
[in] 属性值。
返回值
注意
使用#property指令时属性(修饰符)的编号从1(一)开始,而函数使用从0(零)开始编号。如果水平编号设置错误,那么指标展示可能会不同于预想。
例如,若要设置第一水平线的描述,请使用0标引:
- IndicatorSetString(INDICATOR_LEVELTEXT, 0, “First Level”) - 标引 0用于设定第一水平的文本描述。
例如: 设置指标水平线的文本标签的指标。

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
//--- 在单独指标窗口展示三条水平线
#property indicator_level1 30
#property indicator_level2 50
#property indicator_level3 70
//--- 设置水平线的颜色
#property indicator_levelcolor clrRed
//--- 设置水平线的样式
#property indicator_levelstyle STYLE_SOLID
//+------------------------------------------------------------------+
//| 自定义指标初始化函数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 设置水平线的描述
IndicatorSetString(INDICATOR_LEVELTEXT,0,"First Level (index 0)");
IndicatorSetString(INDICATOR_LEVELTEXT,1,"Second Level (index 1)");
IndicatorSetString(INDICATOR_LEVELTEXT,2,"Third Level (index 2)");
//--- 设置指标缩略名
IndicatorSetString(INDICATOR_SHORTNAME,"IndicatorSetString() Demo");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 自定义指标迭代函数 |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
//--- 返回prev_calculated值以便下次调用
return(rates_total);
}