//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 取引及び注文履歴をリクエストする
if(!HistorySelect(0, TimeCurrent()))
{
Print("HistorySelect() failed. Error ", GetLastError());
return;
}
//--- 口座履歴の取引リストによるループ
int total=HistoryDealsTotal();
for(int i=0; i<total; i++)
{
//--- 次の取引のチケットを取得する(取引はプロパティを取得するために自動的に選択される)
ulong ticket=HistoryDealGetTicket(i);
if(ticket==0)
continue;
//--- 選択した取引の実数プロパティのリストのヘッダーを表示するために、取引のタイプと方向を取得する
string type=DealTypeDescription((ENUM_DEAL_TYPE)HistoryDealGetInteger(ticket, DEAL_TYPE));
string entry=DealEntryDescription((ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket, DEAL_ENTRY));
PrintFormat("Double properties of an deal %s entry %s #%I64u:", type, entry, ticket);
//--- 選択した取引のすべての実数プロパティをヘッダーの下に表示する
HistoryDealPropertiesDoublePrint(ticket, 12);
}
/*
real:
Double properties of an deal Buy entry In #2785070622:
Volume: 0.50
Price: 1.10480
Commission: 0.00
Swap: 0.00
Profit: 0.00 USD
Fee: 0.00
StopLoss: 0.00000
TakeProfit: 0.00000
Double properties of an deal Sell entry Out #2785071538:
Volume: 0.50
Price: 1.10491
Commission: 0.00
Swap: 0.00
Profit: 5.50 USD
Fee: 0.00
StopLoss: 0.00000
TakeProfit: 0.00000
*/
}
//+------------------------------------------------------------------+
//| 選択した取引の実数プロパティを操作ログに表示する |
//+------------------------------------------------------------------+
void HistoryDealPropertiesDoublePrint(const ulong ticket, const uint header_width=0)
{
uint w=0;
string header="";
double value=0;
//--- 銘柄、利益通貨、銘柄の小数点以下の桁数を取得する
string symbol = HistoryDealGetString(ticket, DEAL_SYMBOL);
string currency= SymbolInfoString(symbol, SYMBOL_CURRENCY_PROFIT);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
//--- ヘッダーのテキストとヘッダーフィールドの幅を定義する
//--- ヘッダーの幅が関数に渡され、ゼロと等しい場合、幅はヘッダー行のサイズ+1になる
header="Volume:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- 取引量を取得し、指定されたヘッダー幅で操作ログに表示する
if(!HistoryDealGetDouble(ticket, DEAL_VOLUME, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 操作ログに取引価格を表示する
header="Price:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_PRICE, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 操作ログに取引手数料を表示する
header="Commission:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_COMMISSION, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 閉じる際に、操作ログに累積スワップを表示する
header="Swap:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_SWAP, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 操作ログに取引の財務結果を表示する
header="Profit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_PROFIT, value))
return;
PrintFormat("%-*s%-.2f %s", w, header, value, currency);
//--- 操作ログに取引の手数料を表示する
header="Fee:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_FEE, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 操作ログにストップロスレベルを表示する
header="StopLoss:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_SL, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 操作ログにテイクプロフィットレベルを表示する
header="TakeProfit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetDouble(ticket, DEAL_TP, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
}
//+------------------------------------------------------------------+
//| 取引タイプの説明を返す |
//+------------------------------------------------------------------+
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);
}
}
//+------------------------------------------------------------------+
//| ポジション変更法を返す |
//+------------------------------------------------------------------+
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);
}
}
|