//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- solicitamos o histórico de operações e ordens
if(!HistorySelect(0, TimeCurrent()))
{
Print("HistorySelect() failed. Error ", GetLastError());
return;
}
//--- em um loop pela lista de todos os pedidos históricos da conta
int total=HistoryOrdersTotal();
for(int i=0; i<total; i++)
{
//--- obtemos a ordem dos tickets na lista por índice de loop
ulong ticket=HistoryOrderGetTicket(i);
if(ticket==0)
continue;
//--- obtemos o tipo de ordem e gerar o cabeçalho da lista de propriedades reais da ordem selecionada
string type=OrderTypeDescription((ENUM_ORDER_TYPE)HistoryOrderGetInteger(ticket, ORDER_TYPE));
PrintFormat("Double properties of an history order %s #%I64u:", type, ticket);
//--- imprimimoa todas as propriedades reais da ordem selecionada sob o cabeçalho
HistoryOrderPropertiesDoublePrint(ticket, 16);
}
/*
Resultado:
Double properties of an history order Sell #2810847541:
Volume initial: 0.50
Volume current: 0.00
Price open: 1.10491
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10491
StopLimit: 0.00000
Double properties of an history order Buy Limit #2811003507:
Volume initial: 1.00
Volume current: 1.00
Price open: 1.10547
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10591
StopLimit: 0.00000
*/
}
//+------------------------------------------------------------------+
//| Imprimimos no log as propriedades reais |
//| da ordem histórica escolhida |
//+------------------------------------------------------------------+
void HistoryOrderPropertiesDoublePrint(const long ticket, const uint header_width=0)
{
uint w=0;
string header="";
double value=0;
//--- obtemos o símbolo de ordem e o número de casas decimais do símbolo
string symbol = HistoryOrderGetString(ticket, ORDER_SYMBOL);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_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 initial:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- obtemos e imprimimos no log o volume inicial ao colocar uma ordem com o cabeçalho da largura definida
if(!HistoryOrderGetDouble(ticket, ORDER_VOLUME_INITIAL, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- imprimimos no log o valor do volume de pedidos não atendidos
header="Volume current:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_VOLUME_CURRENT, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- imprimimos no log o valor do preço especificado na ordem
header="Price open:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_PRICE_OPEN, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- imprimimos no log o valor do nível StopLoss
header="StopLoss:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_SL, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- imprimimos no log o valor do nível TakeProfit
header="TakeProfit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_TP, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- imprimimos no log o valor do preço atual por símbolo da ordem
header="Price current:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_PRICE_CURRENT, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- imprimimos no log o valor do preço de definição da ordem Limit quando a ordem StopLimit é acionada
header="StopLimit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_PRICE_STOPLIMIT, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
}
//+------------------------------------------------------------------+
//| Retorna a descrição do tipo de ordem |
//+------------------------------------------------------------------+
string OrderTypeDescription(const ENUM_ORDER_TYPE type)
{
switch(type)
{
case ORDER_TYPE_BUY : return("Buy");
case ORDER_TYPE_SELL : return("Sell");
case ORDER_TYPE_BUY_LIMIT : return("Buy Limit");
case ORDER_TYPE_SELL_LIMIT : return("Sell Limit");
case ORDER_TYPE_BUY_STOP : return("Buy Stop");
case ORDER_TYPE_SELL_STOP : return("Sell Stop");
case ORDER_TYPE_BUY_STOP_LIMIT : return("Buy Stop Limit");
case ORDER_TYPE_SELL_STOP_LIMIT : return("Sell Stop Limit");
default : return("Unknown order type");
}
}
|