该函数设置相应指标属性的值。 指示符属性必须为字符串类型。 这个函数有两种变体。
(1)调用时指定属性标识符。
bool IndicatorSetString(
int prop_id, // 标识符
string prop_value // 要设置的值
);
(2)调用时指定属性标识符和修饰符。
bool IndicatorSetString(
int prop_id, // 标识符
int prop_modifier, // 修饰符 指标线条标号
string prop_value // 要设置的值
)
使用#property指令时,属性(修饰符)的编号从1开始,而函数从0开始编号。 如果级别号设置不正确,可能会导致指示灯显示不一致。
例如,为了设置第一个水平线的描述,使用零索引:
•IndicatorSetString(INDICATOR_LEVELTEXT, 0, “First Level”) – index 0用于设置第一级的文本描述
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
//— 设置显示3条水平线
#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);
}