跳至内容

IndicatorSetString

IndicatorSetString

此函数用于设置相应指示器的属性值。指示器属性必须是字符串类型。该函数有两种实现方式。

通过指定属性标识符调用。

bool  IndicatorSetString(
   int     prop_id,           // identifier
   string  prop_value         // value to be set
   );

通过指定属性标识符和修饰符调用。

bool  IndicatorSetString(
   int     prop_id,           // identifier
   int     prop_modifier,     // modifier
   string  prop_value         // value to be set
   )

参数

prop_id

[in] 指示器属性的标识符。该值可以是ENUM_CUSTOMIND_PROPERTY_STRING枚举中的某个值。

prop_modifier

[in] 指定属性的修饰符。只有级别属性需要修饰符。

prop_value

[in] 属性的值。

返回值

如果执行成功,则返回true;否则返回false。

注意

使用#property指令时,属性(修饰符)的编号从1开始,而该函数使用从0开始的编号。如果级别编号设置错误,指示器显示可能与预期的不同。

例如,要设置第一条水平线的描述,请使用索引0:

  • IndicatorSetString(INDICATOR_LEVELTEXT, 0, “First Level”) - 使用索引0来设置第一级的文本描述。

示例:用于设置指示器水平线文本标签的指示器。

使用IndicatorSetString()函数的示例

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
//--- display three horizontal levels in a separate indicator window
#property indicator_level1 30
#property indicator_level2 50
#property indicator_level3 70
//--- set color of horizontal levels
#property indicator_levelcolor clrRed
//--- set style of horizontal levels
#property indicator_levelstyle STYLE_SOLID
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- set descriptions of horizontal levels
   IndicatorSetString(INDICATOR_LEVELTEXT,0,"First Level (index 0)");
   IndicatorSetString(INDICATOR_LEVELTEXT,1,"Second Level (index 1)");
   IndicatorSetString(INDICATOR_LEVELTEXT,2,"Third Level (index 2)");
//--- set the short name for indicator
   IndicatorSetString(INDICATOR_SHORTNAME,"IndicatorSetString() Demo");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }

另请参阅

自定义指示器属性程序属性 (#property)

最后更新于