void OnStart()
{
ulong deal_ticket; // ticket
ulong order_ticket; // ticket de la orden según la cual ha sido realizada la transacción
datetime transaction_time; // hora de realizar la transacción
long deal_type ; // tipo de operación comercial
long position_ID; // identificador de la posición
string deal_description; // descripción de la operación
double volume; // volumen de operación
string symbol; // símbolo usado en la transacción
//--- vamos a fijar la fecha inicial y final para solicitar el historial de transacciones
datetime from_date=0; // desde el principio
datetime to_date=TimeCurrent();// hasta el momento actual
//--- vamos a solicitar el historial de transacciones del período especificado
HistorySelect(from_date,to_date);
//--- número total en la lista de transacciones
int deals=HistoryDealsTotal();
//--- ahora vamos a procesar cada transacción
for(int i=0;i<deals;i++)
{
deal_ticket= HistoryDealGetTicket(i);
volume= HistoryDealGetDouble(deal_ticket,DEAL_VOLUME);
transaction_time=(datetime)HistoryDealGetInteger(deal_ticket,DEAL_TIME);
order_ticket= HistoryDealGetInteger(deal_ticket,DEAL_ORDER);
deal_type= HistoryDealGetInteger(deal_ticket,DEAL_TYPE);
symbol= HistoryDealGetString(deal_ticket,DEAL_SYMBOL);
position_ID= HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID);
deal_description= GetDealDescription(deal_type,volume,symbol,order_ticket,position_ID);
//--- hagamos el formateado bonito para el número de transacción
string print_index=StringFormat("% 3d",i);
//--- mostramos la información sobre la transacción
Print(print_index+": deal #",deal_ticket," at ",transaction_time,deal_description);
}
}
//+------------------------------------------------------------------+
//| devuelve la descripción literal de la transacción |
//+------------------------------------------------------------------+
string GetDealDescription(long deal_type,double volume,string symbol,long ticket,long pos_ID)
{
string descr;
//---
switch(deal_type)
{
case DEAL_TYPE_BALANCE: return ("balance");
case DEAL_TYPE_CREDIT: return ("credit");
case DEAL_TYPE_CHARGE: return ("charge");
case DEAL_TYPE_CORRECTION: return ("correction");
case DEAL_TYPE_BUY: descr="buy"; break;
case DEAL_TYPE_SELL: descr="sell"; break;
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: descr="cancelled buy deal"; break;
case DEAL_TYPE_SELL_CANCELED: descr="cancelled sell deal"; break;
}
descr=StringFormat("%s %G %s (order #%d, position ID %d)",
descr, // descripción corriente
volume, // volumen de transacción
symbol, // instrumento de transacción
ticket, // ticket de la orden que ha provocado la transacción
pos_ID // ID de la posición en la que ha participado la transacción
);
return(descr);
//---
}
|