//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
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("Double properties of an active pending order %s #%I64u:", type, ticket);
//--- 在标题下方打印选中订单的全部实数型属性
OrderPropertiesDoublePrint(16);
}
/*
结果:
Double properties of an active pending order Sell Limit #2812000714:
Volume initial: 1.00
Volume current: 1.00
Price open: 145.282
StopLoss: 0.000
TakeProfit: 0.000
Price current: 145.044
StopLimit: 0.000
Double properties of an active pending order Buy Limit #2812001112:
Volume initial: 1.00
Volume current: 1.00
Price open: 144.836
StopLoss: 0.000
TakeProfit: 0.000
Price current: 145.051
StopLimit: 0.000
Double properties of an active pending order Buy Stop #2812001488:
Volume initial: 0.50
Volume current: 0.50
Price open: 1.10642
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10530
StopLimit: 0.00000
Double properties of an active pending order Sell Stop #2812001712:
Volume initial: 0.50
Volume current: 0.50
Price open: 1.10374
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10525
StopLimit: 0.00000
*/
}
//+------------------------------------------------------------------+
//| 返回订单类型的描述 |
//+------------------------------------------------------------------+
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");
}
}
//+------------------------------------------------------------------+
//| 在日志中显示选定订单的实数型属性 |
//+------------------------------------------------------------------+
void OrderPropertiesDoublePrint(const uint header_width=0)
{
//--- 取得订单的交易品种和交易品种的小数位数
string symbol = OrderGetString(ORDER_SYMBOL);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
//--- 在日志中以指定宽度的标题显示下单时的初始交易量
OrderPropertyPrint("Volume initial:",header_width,2,ORDER_VOLUME_INITIAL);
//--- 在日志中显示未执行的订单交易量
OrderPropertyPrint("Volume current:",header_width,2,ORDER_VOLUME_CURRENT);
//--- 在日志中显示订单中指定的价格
OrderPropertyPrint("Price open:",header_width,digits,ORDER_PRICE_OPEN);
//--- 在日志中显示止损水平
OrderPropertyPrint("StopLoss:",header_width,digits,ORDER_SL);
//--- 在日志中显示止盈水平
OrderPropertyPrint("TakeProfit:",header_width,digits,ORDER_TP);
//--- 在日志中显示订单交易品种的当前价格
OrderPropertyPrint("Price current:",header_width,digits,ORDER_PRICE_CURRENT);
//--- 在日志中显示限价止损订单的订单限价
OrderPropertyPrint("StopLimit:",header_width,digits,ORDER_PRICE_STOPLIMIT);
}
//+------------------------------------------------------------------+
//| 在日志中显示订单实数型属性值 |
//+------------------------------------------------------------------+
void OrderPropertyPrint(const string header, uint header_width, int digits, ENUM_ORDER_PROPERTY_DOUBLE property)
{
double value=0;
if(!OrderGetDouble(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%-.*f", w, header, digits, value);
}
}
|