//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 在账户中所有订单的列表中做循环
int total=OrdersTotal();
for(int i=0; i<total; i++)
{
//--- 根据循环索引取得列表中的订单编号
ulong ticket=OrderGetTicket(i);
if(ticket==0)
continue;
//--- 取得订单类型并显示用于选中订单字符串型属性列表的标题
string type=OrderTypeDescription((ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE));
PrintFormat("String properties of an active pending order %s #%I64u:", type, ticket);
//--- 在标题下方打印选中订单的所有字符串型属性
OrderPropertiesStringPrint(13);
}
/*
结果:
String properties of an active pending order Sell Limit #2813781342:
Comment: Test OrderGetString
Symbol: EURUSD
External ID:
*/
}
//+------------------------------------------------------------------+
//| 在日志中显示选定订单的字符串型属性 |
//+------------------------------------------------------------------+
void OrderPropertiesStringPrint(const uint header_width=0)
{
//--- 在日志中显示注释
OrderPropertyPrint("Comment:", header_width, ORDER_COMMENT);
//--- 在日志中显示所下订单的交易品种
OrderPropertyPrint("Symbol:", header_width, ORDER_SYMBOL);
//--- 在日志中显示在外部系统中的订单 ID
OrderPropertyPrint("External ID:", header_width, ORDER_EXTERNAL_ID);
}
//+------------------------------------------------------------------+
//| 在日志中显示订单字符串属性值 |
//+------------------------------------------------------------------+
void OrderPropertyPrint(const string header, uint header_width, ENUM_ORDER_PROPERTY_STRING property)
{
string value="";
if(!OrderGetString(property, value))
PrintFormat("Cannot get property %s, error=%d", EnumToString(property), GetLastError());
else
{
//--- 如果传递给函数的标题宽度为0, 则宽度为标题行大小+1
uint w=(header_width==0 ? header.Length()+1 : header_width);
PrintFormat("%-*s%-s", w, header, 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: "+(string)type);
}
}
|