统计某个时间段的总成交单数和总成交量【源码】
//+------------------------------------------------------------------+ //| 统计交易量.mq4 | //| 统计某个时间段内的已成交订单的总交易单数 | //| QQ:1053029 | //+------------------------------------------------------------------+ #property copyright "Copyright,老头,QQ:10353029" #property show_inputs extern datetime startTime=D'2014.10.26',endTime=D'2014.10.31'; int start() { int iLots = iCountOrdersLots( startTime, endTime ); string str = "账户: " + AccountNumber() + "nn" + "时间段:" + TimeToStr(startTime,TIME_DATE) + "~" + TimeToStr(endTime,TIME_DATE) + "nn" + "总成交单数:" + iCountOrdersTotal( startTime, endTime ) + "单nn" + "已平仓总交易量:" + iCountOrdersLots( startTime, endTime ) + "手"; MessageBox(str,"注意",MB_OK); return(0); } //+------------------------------------------------------------------+ //| 函数名称:iCountOrdersTotal() | //| 函数功能:统计某个时间段内的已成交订单的总交易单数 | //| 函数参数:datetime timeStart = 统计交易量的开始时间 | //| datetime timeEnd = 统计交易量的结束时间 | //| 函数说明: | //| 返 回 值:时段内的总成交单数 | //+------------------------------------------------------------------+ double iCountOrdersTotal( datetime timeStart, datetime timeEnd ) { int iOrdTrade = 0; int orders = OrdersHistoryTotal(); for(int i=0;i<orders-1;i++) { if( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()<=OP_SELL) ) { iOrdTrade++; } } return(iOrdTrade); } //+------------------------------------------------------------------+ //| 函数名称:iCountOrdersLots() | //| 函数功能:统计某个时间段内的已成交订单的总交易手数 | //| 函数参数:datetime timeStart = 统计交易量的开始时间 | //| datetime timeEnd = 统计交易量的结束时间 | //| 函数说明: | //| 返 回 值:时段内的总成交手数 | //+------------------------------------------------------------------+ double iCountOrdersLots( datetime timeStart, datetime timeEnd ) { int iTicket[500]; int iOrdTrade = 0; double LotsSum = 0; int orders = OrdersHistoryTotal(); for(int i=0;i<orders-1;i++) { if( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()<=OP_SELL) ) { iTicket[iOrdTrade] = OrderTicket(); iOrdTrade++; } } for( i=0; i<iOrdTrade-1; i++ ) { if( OrderSelect(iTicket,SELECT_BY_TICKET,MODE_HISTORY) ) { datetime dStart = StrToTime( TimeToStr(timeStart, TIME_DATE) ); datetime dEnd = StrToTime( TimeToStr(timeEnd, TIME_DATE) ); datetime dOrder = StrToTime( TimeToStr(OrderOpenTime(),TIME_DATE) ); if( dOrder>=dStart && dOrder<=dEnd ) { LotsSum += OrderLots(); } }else{ //if( MessageBox("订单选择错误:"+iTicket,"注意",MB_YESNO) ==IDNO )break; } } return(LotsSum); } |
打赏
最新创建圈子
- 新闻EA运行效果图圈 2019-05-05
圈主:admin 帖子:1