//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 取引及び注文履歴をリクエストする
if(!HistorySelect(0, TimeCurrent()))
{
Print("HistorySelect() failed. Error ", GetLastError());
return;
}
//--- 口座のすべての履歴注文のリストのループ
int total=HistoryOrdersTotal();
for(int i=0; i<total; i++)
{
//--- ループインデックスでリストから注文チケットを取得する
ulong ticket=HistoryOrderGetTicket(i);
if(ticket==0)
continue;
//--- 注文タイプを取得し、選択した注文の実数プロパティのリストのヘッダーを表示する
string type=OrderTypeDescription((ENUM_ORDER_TYPE)HistoryOrderGetInteger(ticket, ORDER_TYPE));
PrintFormat("Double properties of an history order %s #%I64u:", type, ticket);
//--- ヘッダーの下に選択した注文のすべての実数プロパティを表示する
HistoryOrderPropertiesDoublePrint(ticket, 16);
}
/*
結果:
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
*/
}
//+------------------------------------------------------------------+
//| 選択した過去の注文の実数プロパティを |
//| 操作ログに表示する |
//+------------------------------------------------------------------+
void HistoryOrderPropertiesDoublePrint(const long ticket, const uint header_width=0)
{
uint w=0;
string header="";
double value=0;
//--- 注文の銘柄とその小数点以下の桁数を取得する
string symbol = HistoryOrderGetString(ticket, ORDER_SYMBOL);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
//--- ヘッダーのテキストとヘッダーフィールドの幅を定義する
//--- ヘッダーの幅が関数に渡され、ゼロと等しい場合、幅はヘッダー行のサイズ+1になる
header="Volume initial:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- 注文を出す際に初期ボリュームを取得し、指定されたヘッダー幅で操作ログに表示する
if(!HistoryOrderGetDouble(ticket, ORDER_VOLUME_INITIAL, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 操作ログに未履行の注文ボリュームを表示する
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);
//--- 操作ログに注文で指定された価格を表示する
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);
//--- 操作ログにストップロスレベルを表示する
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);
//--- 操作ログにテイクプロフィットレベルを表示する
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);
//--- 操作ログに注文の銘柄による現在の価格を表示する
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);
//--- 操作ログにストップリミット注文がアクティブになったときのリミット注文価格を表示する
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);
}
//+------------------------------------------------------------------+
//| 注文タイプの説明を返す |
//+------------------------------------------------------------------+
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");
}
}
|