跳至内容

ChartWindowFind

ChartWindowFind

此函数返回绘制指示器的子窗口的编号。该函数有两种变体。

  1. 该函数会在指定的图表中搜索具有指定“短名称”的子窗口(短名称显示在子窗口的左上部分),如果成功则返回子窗口编号。
int  ChartWindowFind(
   long     chart_id,                  // chart identifier
   string   indicator_shortname        // short indicator name, see INDICATOR_SHORTNAME
   );
  1. 该函数必须从自定义指示器调用。它返回指示器工作的子窗口编号。
int  ChartWindowFind();

参数

chart_id

[in] 图表ID。0表示当前图表。

indicator_shortname

[in] 指示器的短名称。

返回值

如果成功,则返回子窗口编号。如果失败,则函数返回-1。

注意

如果第二种变体(无参数)从脚本或专家顾问调用,函数将返回-1。

不要将指示器的短名称与文件名称混淆,后者是在使用iCustom()函数创建指示器时指定的。如果指示器未明确设置短名称,则包含指示器源代码的文件名称将在编译过程中指定。

正确形成指示器的短名称非常重要,该名称通过IndicatorSetString()函数记录在INDICATOR_SHORTNAME属性中。建议短名称包含指示器的输入参数值,因为通过ChartIndicatorDelete()函数从图表中删除的指示器是其短名称来识别的。

示例:

#property script_show_inputs
//--- input parameters
input string   shortname="MACD(12,26,9)";
//+------------------------------------------------------------------+
//| Returns number of the chart window with this indicator           |
//+------------------------------------------------------------------+
int GetIndicatorSubWindowNumber(long chartID=0,string short_name="")
  {
   int window=-1;
//---
   if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      //--- the function is called from the indicator, name is not required
      window=ChartWindowFind();
     }
   else
     {
      //--- the function is called from an Expert Advisor or script
      window=ChartWindowFind(0,short_name);
      if(window==-1) Print(__FUNCTION__+"(): Error = ",GetLastError());
     }
//---
   return(window);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int window=GetIndicatorSubWindowNumber(0,shortname);
   if(window!=-1)
      Print("Indicator "+shortname+" is in the window #"+(string)window);
   else
      Print("Indicator "+shortname+" is not found. window = "+(string)window);
  }

另请参阅

ObjectCreate(), ObjectFind()

最后更新于