#define SYMBOL_NAME "GBPHKD"
//+------------------------------------------------------------------+
//| EA交易初始化函数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 检查列表中交易品种是否存在,如果没有找到,进行报告并完成工作
bool custom = false;
if(!SymbolExist(SYMBOL_NAME, custom))
{
PrintFormat("'%s' symbol not found in the lists", SYMBOL_NAME);
return;
}
//--- 将交易品种添加到市场报价窗口
ResetLastError();
if(!SymbolSelect(SYMBOL_NAME, true))
{
Print("SymbolSelect() failed. Error ", GetLastError());
return;
}
//--- 如果交易品种被成功地添加到列表中,请在市场报价窗口中获取它的索引号,并将结果发送到日志
int index = SymbolIndex(SYMBOL_NAME);
PrintFormat("The '%s' symbol has been added to the MarketWatch list. Symbol index in the list: %d", SYMBOL_NAME, index);
//--- 现在从市场报价窗口移除交易品种
ResetLastError();
if(!SymbolSelect(SYMBOL_NAME, false))
{
Print("SymbolSelect() failed. Error ", GetLastError());
return;
}
//--- 如果交易品种被成功地从列表中移除,则市场报价窗口的索引号-1,并将删除结果发送到日志
index = SymbolIndex(SYMBOL_NAME);
PrintFormat("The '%s' symbol has been removed from the MarketWatch list. Symbol index in the list: %d", SYMBOL_NAME, index);
/*
result:
The 'GBPHKD' symbol has been added to the MarketWatch list. Symbol index in the list: 12
The 'GBPHKD' symbol has been removed from the MarketWatch list. Symbol index in the list: -1
*/
}
//+------------------------------------------------------------------+
//| 返回交易品种在市场报价交易品种列表中的索引号 |
//+------------------------------------------------------------------+
int SymbolIndex(const string symbol)
{
int total = SymbolsTotal(true);
for(int i=0; i<total; i++)
{
string name = SymbolName(i, true);
if(name == symbol)
return i;
}
return(WRONG_VALUE);
}
|