void OnStart()
{
ulong deal_ticket; // 交易订单号
ulong order_ticket; // 执行交易的订单的订单号
datetime transaction_time; // 交易执行时间
long deal_type ; // 交易操作类型
long position_ID; // 仓位ID
string deal_description; // 操作描述
double volume; // 操作交易量
string symbol; // 交易的交易品种
//--- 设置交易历史记录请求的起止时间
datetime from_date=0; // 从最开始
datetime to_date=TimeCurrent();// 到当前时间
//--- 特定周期中请求交易历史记录
HistorySelect(from_date,to_date);
//--- 交易列表中的全部数量
int deals=HistoryDealsTotal();
//--- 现在处理每一个交易
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);
//--- 为交易号执行格式化
string print_index=StringFormat("% 3d",i);
//--- 显示交易信息
Print(print_index+": deal #",deal_ticket," at ",transaction_time,deal_description);
}
}
//+------------------------------------------------------------------+
//| 返回操作的字符串描述 |
//+------------------------------------------------------------------+
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, // 当前描述。
volume, // 交易的交易量。
symbol, // 交易的交易品种。
ticket, // 引起交易的订单的订单号。
pos_ID // 仓位交易执行的ID号。
);
return(descr);
//---
}
|