MT5遍历持仓订单的方法,MQL5如何遍历当前持仓订单列表,MT5获取当前订单的方法,直接上代码
- string strResult = "";
- ulong ticket = 0;
- for(int k=0; k<PositionsTotal(); k++) {
- if(PositionGetTicket(k)!=0) {
-
- string strSymbol = PositionGetSymbol(POSITION_SYMBOL);
- int nOrderID = PositionGetInteger(POSITION_IDENTIFIER);
- string strOpenTime = TimeToString(PositionGetInteger(POSITION_TIME),TIME_DATE|TIME_SECONDS);
- string strType = PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY?"buy":"sell";
- double dbLots = PositionGetDouble(POSITION_VOLUME);
- double dbOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
- double dbSL = PositionGetDouble(POSITION_SL);
- double dbTP = PositionGetDouble(POSITION_TP);
- double dbPrice = PositionGetDouble(POSITION_PRICE_CURRENT);
- double dbProfit = PositionGetDouble(POSITION_PROFIT);
- string strComment = PositionGetString(POSITION_COMMENT);
-
- strResult = StringFormat("交易品种:%s 订单号:%d 开仓时间:%s \r\n类型:%s 交易量 :%.2f 开仓价位:%f \r\n止损:%f 止盈:%f 当前价位:%f\r\n盈利:%f 注释:%s ",
- strSymbol,nOrderID,strOpenTime,
- strType,dbLots,dbOpenPrice,
- dbSL,dbTP,dbPrice,
- dbProfit,strComment);
- Alert(strResult);
- }
- }
复制代码
|