MT5在持仓获取上,要比MT4复杂些,分两部分,获取持仓和挂单采用了不同的方法。 一、获取持仓中的buy和sell单
- int b=0;//获取buy单个数
-
- int s=0;//获取sell单个数
-
- double lot_total_buy=0;//获取持仓中buy单的总手数
-
- double lot_total_sell=0;//获取持仓中sell单的总手数
-
- for(int i=0; i<PositionsTotal(); i++)
-
- {
-
- ulong ticket=PositionGetTicket(i);
-
- string ordsymbol = PositionGetString(POSITION_SYMBOL);
-
- string ordcom = PositionGetString(POSITION_COMMENT);
-
- long ordmagic = PositionGetInteger(POSITION_MAGIC);
-
- double ordslp = PositionGetDouble(POSITION_SL);
-
- double ordtpp = PositionGetDouble(POSITION_TP);
-
- double ordoop = PositionGetDouble(POSITION_PRICE_OPEN);
-
- long ordtype = PositionGetInteger(POSITION_TYPE);
-
- double ordlot = PositionGetDouble(POSITION_VOLUME);
-
- double ordcp = PositionGetDouble(POSITION_PRICE_CURRENT);
-
- if(ordsymbol==Symbol() && PositionGetInteger(POSITION_MAGIC)==magic)
-
- {
-
- if(ordtype==POSITION_TYPE_BUY)
-
- {
-
- b++;
-
- lot_total_buy+=ordlot;
-
- }
-
- if(ordtype==POSITION_TYPE_SELL)
-
- {
-
- s++;
-
- lot_total_sell+=ordlot;
-
- }
-
- }
-
- }
复制代码
二、获取挂单的信息 - //--- 订单属性返回值的变量
-
- ulong ticket=0;
-
- double open_price;
-
- double initial_volume;
-
- datetime time_setup;
-
- string symbol;
-
- string type;
-
- long order_magic;
-
-
- int bg=0;//获取挂单buystop的个数
-
- int sg=0;//获取挂单sellstop的个数
-
- for(int i=0; i<OrdersTotal(); i++)
-
- {
-
- //--- 通过列表中的仓位返回订单报价
-
- ticket=OrderGetTicket(i);
-
- //--- 返回订单属性
-
- open_price =OrderGetDouble(ORDER_PRICE_OPEN);
-
- time_setup =(datetime)OrderGetInteger(ORDER_TIME_SETUP);
-
- symbol =OrderGetString(ORDER_SYMBOL);
-
- order_magic =OrderGetInteger(ORDER_MAGIC);
-
- // positionID =OrderGetInteger(ORDER_POSITION_ID);
-
- initial_volume=OrderGetDouble(ORDER_VOLUME_INITIAL);
-
- type =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE)));
-
- string ordcom=OrderGetString(ORDER_COMMENT);
-
- if(symbol==Symbol() && order_magic==magic)
-
- {
-
- if(type=="ORDER_TYPE_BUY_STOP")
-
- {
-
- bg++;
-
- }
-
- if(type=="ORDER_TYPE_SELL_STOP")
-
- {
-
- sg++;
-
- }
-
- }
-
-
- }
复制代码
|