HistoryDealGetDouble

Retorna a propriedade solicitada de uma operação. A propriedade da operação deve ser do tipo double. Existem 2 variantes da função.

1. Imediatamente retorna o valor da propriedade.

double  HistoryDealGetDouble(
   ulong                      ticket_number,     // Ticket (bilhete)
   ENUM_DEAL_PROPERTY_DOUBLE  property_id        // Identificador de propriedade
   );

2. A função vai retornar "true" ou "false", dependendo se deu certo ou não. Se der certo, o valor da propriedade será passado por referência para uma variável de destino, que você define no último parâmetro.

bool  HistoryDealGetDouble(
   ulong                      ticket_number,     // Ticket (bilhete)
   ENUM_DEAL_PROPERTY_DOUBLE  property_id,       // Identificador de propriedade
   double&                    double_var         // Aqui nós aceitamos o valor da propriedade
   );

Parâmetros

ticket_number

[in]  Ticket de operação.

property_id

[in]  Identificador da propriedade da operação. O valor pode ser um dos valores da enumeração ENUM_DEAL_PROPERTY_DOUBLE.

double_var

[out]  Variável de tipo double, que aceita o valor da propriedade requerida.

Valor retornado

Valor do tipo double.

Observação

Não confunda ordens, operações e posições. Cada operação é o resultado da execução de uma ordem, cada posição é a soma de uma ou mais operações.

Exemplo:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- solicitamos o histórico de operações e ordens
   if(!HistorySelect(0TimeCurrent()))
     {
      Print("HistorySelect() failed. Error "GetLastError());
      return;
     }
 
//--- em um loop pela lista de operações no histórico da conta
   int total=HistoryDealsTotal();
   for(int i=0i<totali++)
     {
      //--- obtemos o ticket da próxima operação (a operação é automaticamente selecionada para obter suas propriedades)
      ulong ticket=HistoryDealGetTicket(i);
      if(ticket==0)
         continue;
      
      //--- obtemos o tipo e a direção da operação e geramos o cabeçalho da lista de propriedades reais da operação selecionada
      string type=DealTypeDescription((ENUM_DEAL_TYPE)HistoryDealGetInteger(ticketDEAL_TYPE));
      string entry=DealEntryDescription((ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticketDEAL_ENTRY));
      PrintFormat("Double properties of an deal %s entry %s #%I64u:"typeentryticket);
      
      //--- imprimimos todas as propriedades reais da operação selecionada sob o cabeçalho
      HistoryDealPropertiesDoublePrint(ticket12);
     }
   /*
   Resultado:
   Double properties of an deal Buy entry In #2785070622:
   Volume:     0.50
   Price:      1.10480
   Commission0.00
   Swap:       0.00
   Profit:     0.00 USD
   Fee:        0.00
   StopLoss:   0.00000
   TakeProfit0.00000
   Double properties of an deal Sell entry Out #2785071538:
   Volume:     0.50
   Price:      1.10491
   Commission0.00
   Swap:       0.00
   Profit:     5.50 USD
   Fee:        0.00
   StopLoss:   0.00000
   TakeProfit0.00000
   */
  }
//+------------------------------------------------------------------+
//| Registra no log as propriedades reais da operação selecionada    |
//+------------------------------------------------------------------+
void HistoryDealPropertiesDoublePrint(const ulong ticketconst uint header_width=0)
  {
   uint   w=0;
   string header="";
   double value=0;
   
//--- obtemos o símbolo da operação, a moeda do lucro e o número de casas decimais do símbolo
   string symbol  = HistoryDealGetString(ticketDEAL_SYMBOL);
   string currencySymbolInfoString(symbolSYMBOL_CURRENCY_PROFIT);
   int    digits  = (int)SymbolInfoInteger(symbolSYMBOL_DIGITS);
   
//--- definimos o texto do cabeçalho e a largura do campo de cabeçalho
//--- se a largura do cabeçalho for passada para a função igual a zero, a largura será o tamanho da linha do cabeçalho + 1
   header="Volume:";
   w=(header_width==0 ? header.Length()+1 : header_width);
//--- recebemos e imprimimos no log o volume da operação com um cabeçalho de largura definida
   if(!HistoryDealGetDouble(ticketDEAL_VOLUMEvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- imprimimos no log o preço da operação
   header="Price:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_PRICEvalue))
      return;
   PrintFormat("%-*s%-.*f"wheaderdigitsvalue);
   
//--- imprimimos no log a comissão da operação
   header="Commission:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_COMMISSIONvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- imprimimos no logo swap acumulado no fechamento
   header="Swap:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_SWAPvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- imprimimos no log o resultado financeiro da operação
   header="Profit:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_PROFITvalue))
      return;
   PrintFormat("%-*s%-.2f %s"wheadervaluecurrency);
   
//--- imprimimos no log o pagamento da operação realizada
   header="Fee:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_FEEvalue))
      return;
   PrintFormat("%-*s%-.2f"wheadervalue);
   
//--- imprimimos no log o valor do nível StopLoss
   header="StopLoss:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_SLvalue))
      return;
   PrintFormat("%-*s%-.*f"wheaderdigitsvalue);
 
//--- imprimimos no log o valor do nível TakeProfit
   header="TakeProfit:";
   w=(header_width==0 ? header.Length()+1 : header_width);
   if(!HistoryDealGetDouble(ticketDEAL_TPvalue))
      return;
   PrintFormat("%-*s%-.*f"wheaderdigitsvalue);
  }
//+------------------------------------------------------------------+
//| Retorna uma descrição do tipo de operação                        |
//+------------------------------------------------------------------+
string DealTypeDescription(const ENUM_DEAL_TYPE type)
  {
   switch(type)
     {
      case DEAL_TYPE_BUY                     :  return("Buy");
      case DEAL_TYPE_SELL                    :  return("Sell");
      case DEAL_TYPE_BALANCE                 :  return("Balance");
      case DEAL_TYPE_CREDIT                  :  return("Credit");
      case DEAL_TYPE_CHARGE                  :  return("Additional charge");
      case DEAL_TYPE_CORRECTION              :  return("Correction");
      case DEAL_TYPE_BONUS                   :  return("Bonus");
      case DEAL_TYPE_COMMISSION              :  return("Additional commission");
      case DEAL_TYPE_COMMISSION_DAILY        :  return("Daily commission");
      case DEAL_TYPE_COMMISSION_MONTHLY      :  return("Monthly commission");
      case DEAL_TYPE_COMMISSION_AGENT_DAILY  :  return("Daily agent commission");
      case DEAL_TYPE_COMMISSION_AGENT_MONTHLY:  return("Monthly agent commission");
      case DEAL_TYPE_INTEREST                :  return("Interest rate");
      case DEAL_TYPE_BUY_CANCELED            :  return("Canceled buy deal");
      case DEAL_TYPE_SELL_CANCELED           :  return("Canceled sell deal");
      case DEAL_DIVIDEND                     :  return("Dividend operations");
      case DEAL_DIVIDEND_FRANKED             :  return("Franked (non-taxable) dividend operations");
      case DEAL_TAX                          :  return("Tax charges");
      default                                :  return("Unknown deal type: "+(string)type);
     }
  }
//+------------------------------------------------------------------+
//| Retorna uma descrição de como a posição foi alterada             |
//+------------------------------------------------------------------+
string DealEntryDescription(const ENUM_DEAL_ENTRY entry)
  {
   switch(entry)
     {
      case DEAL_ENTRY_IN      :  return("In");
      case DEAL_ENTRY_OUT     :  return("Out");
      case DEAL_ENTRY_INOUT   :  return("Reverce");
      case DEAL_ENTRY_OUT_BY  :  return("Out by");
      case DEAL_ENTRY_STATE   :  return("Status record");
      default                 :  return("Unknown deal entry: "+(string)entry);
     }
  }

Também Veja

HistorySelect(), HistoryDealsTotal(), HistoryDealSelect(), Propriedades de uma Operação