void OnStart()
{
ulong deal_ticket; // 約定チケット
ulong order_ticket; // 約定が実行された注文のチケット
datetime transaction_time; // 約定実行時刻
long deal_type ; // 取引操作の種類
long position_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 // 約定が含まれたポジションの識別子
);
return(descr);
//---
}
|