#define SYMBOL_NAME "GBPHKD" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- verificamos se o símbolo está presente nas listas; se não estiver, informamos o fato e encerramos o trabalho bool custom = false; if(!SymbolExist(SYMBOL_NAME, custom)) { PrintFormat("'%s' symbol not found in the lists", SYMBOL_NAME); return; } //--- adicionamos o símbolo à janela Observação do mercado ResetLastError(); if(!SymbolSelect(SYMBOL_NAME, true)) { Print("SymbolSelect() failed. Error ", GetLastError()); return; } //--- se o símbolo for adicionado com sucesso à lista, obtemos seu índice na janela Observação do Mercado e informamos no log sua adição 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); //--- agora removemos o símbolo da janela Observação do Mercado ResetLastError(); if(!SymbolSelect(SYMBOL_NAME, false)) { Print("SymbolSelect() failed. Error ", GetLastError()); return; } //--- se o símbolo for removido com sucesso da lista, seu índice na janela Observação do Mercado será -1, relatamos no log sua exclusão index = SymbolIndex(SYMBOL_NAME); PrintFormat("The '%s' symbol has been removed from the MarketWatch list. Symbol index in the list: %d", SYMBOL_NAME, index); /* resultado: 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 */ } //+------------------------------------------------------------------+ //| Retorna o índice do símbolo na lista da Observação do Mercado | //+------------------------------------------------------------------+ 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); } |