跳至内容

IndicatorSetDouble

IndicatorSetDouble

此函数设置相应指示符属性的值。指示符属性必须是双精度类型。该函数有两种变体。

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

bool  IndicatorSetDouble(
   int     prop_id,           // identifier
   double  prop_value         // value to be set
   );

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

bool  IndicatorSetDouble(
   int     prop_id,           // identifier
   int     prop_modifier,     // modifier
   double  prop_value         // value to be set
   )

参数

prop_id

[in] 指示符属性的标识符。该值可以是ENUM_CUSTOMIND_PROPERTY_DOUBLE枚举中的值之一。

prop_modifier

[in] 指定属性的修饰符。只有级别属性需要修饰符。级别的编号从0开始。这意味着要为第二级设置属性,则需要指定1(比使用编译器指令时少1)。

prop_value

[in] 属性的值。

返回值

成功执行时返回true,否则返回false。

注意

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

例如,单独子窗口中指示符的第一级值可以通过两种方式设置:

  • property indicator_level1 50 - 使用值1来指定级别编号,
  • IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, 50) - 使用0来指定第一级。

示例:将水平线放置的级别的数值颠倒的指示符。

使用IndicatorSetDouble()函数的示例

#property indicator_separate_window
//--- set the maximum and minimum values for the indicator window
#property indicator_minimum  0
#property indicator_maximum  100
//--- display two horizontal levels in a separate indicator window
#property indicator_level1 25
#property indicator_level2 75
//--- set thickness of horizontal levels
#property indicator_levelwidth 1
//--- set style of horizontal levels
#property indicator_levelstyle STYLE_DOT
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- two levels
   IndicatorSetInteger(INDICATOR_LEVELS,2);
//--- set descriptions of horizontal levels
   IndicatorSetString(INDICATOR_LEVELTEXT,0,"First Level (index 0)");
   IndicatorSetString(INDICATOR_LEVELTEXT,1,"Second Level (index 1)");
//--- set the short name for indicator
   IndicatorSetString(INDICATOR_SHORTNAME,"IndicatorSetDouble() Demo");
//--- set clrBlue color for all levels
   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrBlue);
//---
   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[])
  {
   static int tick_counter=0;
   static double level1=25,level2=75;
   static int delta=1;
//--- calculate ticks
   tick_counter+=delta;
//--- check ranges
   if(tick_counter<0) delta=5;
   if(tick_counter>25) delta=-5;
//--- calculate new values
   level1+=delta;
   level2-=delta;
//--- set new values for levels
   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,level1);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,level2);
//--- return value of prev_calculated for next call
   return(rates_total);
  }

另请参阅

绘图样式

最后更新于