void OnStart()
{
color BuyColor =clrBlue;
color SellColor=clrRed;
//--- 请求交易历史记录
HistorySelect(0,TimeCurrent());
//--- 创建物件
string name;
uint total=HistoryDealsTotal();
ulong ticket=0;
double price;
double profit;
datetime time;
string symbol;
long type;
long entry;
//--- 所有交易
for(uint i=0;i<total;i++)
{
//--- 尽力获得交易报价
if((ticket=HistoryDealGetTicket(i))>0)
{
//--- 获得交易属性
price =HistoryDealGetDouble(ticket,DEAL_PRICE);
time =HistoryDealGetInteger(ticket,DEAL_TIME);
symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
type =HistoryDealGetInteger(ticket,DEAL_TYPE);
entry =HistoryDealGetInteger(ticket,DEAL_ENTRY);
profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
//--- 只对当前交易品种
if(price && time && symbol==Symbol())
{
//--- 创建价格物件
name="TradeHistory_Deal_"+string(ticket);
if(entry) ObjectCreate(0,name,OBJ_ARROW_RIGHT_PRICE,0,time,price,0,0);
else ObjectCreate(0,name,OBJ_ARROW_LEFT_PRICE,0,time,price,0,0);
//--- 设置物件属性
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
ObjectSetInteger(0,name,OBJPROP_BACK,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,type?BuyColor:SellColor);
if(profit!=0) ObjectSetString(0,name,OBJPROP_TEXT,"Profit: "+string(profit));
}
}
}
//--- 应用于图表
ChartRedraw();
}
|