MarketBookAdd

Abre o livro de ofertas (Depth of Market, DOM) para o ativo selecionado, e ativa notificações de alterações na DOM.

bool  MarketBookAdd(
   string  symbol      // ativo
   );

Parâmetros

symbol

[in] O nome do ativo cujo livro de ofertas é usado no Expert Advisor ou script.

Valor do Retorno

O valor true se aberto com sucesso, caso contrário false.

Observação

Normalmente, esta função deve ser chamada a partir da função OnInit() ou no construtor da classe. Para manipular a chegada de alertas, o programa Expert Advisor deve conter a função void OnBookEvent(string& symbol).

Exemplo:

#define   SYMBOL_NAME   "GBPUSD"
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- abrimos o livro de ofertas do símbolo SYMBOL_NAME
   if(!MarketBookAdd(SYMBOL_NAME))
     {
      PrintFormat("MarketBookAdd(%s) failed. Error "SYMBOL_NAMEGetLastError());
      return;
     }
 
//--- mostramos no log a mensagem sobre a abertura bem-sucedida do livro de ofertas
   PrintFormat("The MarketBook for the '%s' symbol was successfully opened and a subscription to change it was received"SYMBOL_NAME);
   
//--- esperamos 2 segundos
   Sleep(2000);
   
//--- no final, cancelaremos a assinatura do livro de ofertas
   ResetLastError();
   if(MarketBookRelease(SYMBOL_NAME))
      PrintFormat("MarketBook for the '%s' symbol was successfully closed"SYMBOL_NAME);
   else
      PrintFormat("Error %d occurred when closing MarketBook using the '%s' symbol"GetLastError(), SYMBOL_NAME);
      
   /*
   resultado:
   The MarketBook for the 'GBPUSDsymbol was successfully opened and a subscription to change it was received
   MarketBook for the 'GBPUSDsymbol was successfully closed
   */
  }

Também Veja

Estrutura da Profundidade de Mercado, Estruturas e Classes