SymbolExist

检查指定名称的交易品种是否存在。

bool  SymbolExist(
   const string  name,    // 交易品种名称
   bool&   is_custom      // 自定义交易品种属性
   );

参数

名称

[in]  交易品种名称。

is_custom

[out]  成功执行时设置自定义交易品种属性。如果为true,检测的交易品种就是自定义交易品种。

返回值

如果为false,则意味着在标准和自定义交易品种中没有找到该交易品种。

示例:

#define SYMBOL_NAME "GBPUSDn"
//+------------------------------------------------------------------+
//| EA交易初始化函数                                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 声明自定义交易品种标识,并检查是否存在其名称在SYMBOL_NAME中指定的交易品种
   bool custom = false;
   bool result = SymbolExist(SYMBOL_NAMEcustom);
   
//--- 声明默认的“找不到交易品种”消息文本
   string text = StringFormat("The symbol '%s' was not found among either the standard or custom symbols."SYMBOL_NAME);
   
//--- 如果找到交易品种,则根据找到交易品种的列表创建消息文本
   if(result)
     {
      //--- 如果这是一个标准交易品种
      if(!custom)
         text = StringFormat("The '%s' symbol is available on the server."SYMBOL_NAME);
      //--- 如果这是一个自定义交易品种
      else
         text = StringFormat("The symbol '%s' was found in the list of custom symbols."SYMBOL_NAME);
     }
     
//--- 将有关检查结果的消息发送到日志
   Print(text);
   /*
   result for standard 'GBPUSD' symbol:
   The 'GBPUSDsymbol is available on the server.
   
   result for custom 'GBPUSDx' symbol:
   The symbol 'GBPUSDxwas found in the list of custom symbols.
   
   result for missing 'GBPUSDn' symbol:
   The symbol 'GBPUSDnwas not found among either the standard or custom symbols.
   */
  }

另见

SymbolsTotalSymbolSelectCustom symbols