what's wrong with my code?

 
MqlTradeRequest request;
MqlTradeResult result;
void OnTick()
  {
   request.symbol = Symbol();
   request.volume = 0.01;
   request.action = TRADE_ACTION_DEAL;
   request.type_filling = ORDER_FILLING_IOC;
   request.price = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
   request.type = ORDER_TYPE_BUY;
   for(int i = 1; i < 2 ; i++)
     {
      bool a = OrderSend(request,result);
     }

   if(PositionSelect(Symbol()) == true)
     {
      long ticket = PositionGetInteger(POSITION_TICKET);
      string position = PositionGetString(POSITION_SYMBOL);
      double volume = PositionGetDouble(POSITION_VOLUME);
      ENUM_POSITION_TYPE position_type = (POSITION_TYPE_BUY)PositionGetInteger(POSITION_TYPE);
      double sl = PositionGetDouble(POSITION_SL);
      double tp = PositionGetDouble(POSITION_TP);
      double open_price = PositionGetDouble(POSITION_PRICE_OPEN);
      Comment("ticket = ",ticket,"\n",
              "position_open = ",position,"\n",
              "position_type = ",position_type,"\n",
              "sl = ",sl,"\n",
              "tp = ",tp,"\n",
              "open_price = ",open_price);
     }
  }

hi guys, I have really no idea what's wrong with the position_type,

I got a error says that "position_type - some operator expected",

can anyone help?

 
ENUM_POSITION_TYPE position_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
 
ziyang2048 #:

我有一个问题,我不是很懂为什么为什么PositionGetInteger前面要放enum_position_type?

两边的数据类型不一致, 把大的类型赋给小的类型时需要做强制转换.

因为PositionGetInteger()函数的返回值类型是long,而左边的变量position_type的类型是ENUM_POSITION_TYPE

需要把long类型转换成 ENUM_POSITION_TYPE类型

 
Ziheng Zhuang #:

两边的数据类型不一致, 把大的类型赋给小的类型时需要做强制转换.

因为PositionGetInteger()函数的返回值类型是long,而左边的变量position_type的类型是ENUM_POSITION_TYPE

需要把long类型转换成 ENUM_POSITION_TYPE类型

哦哦

我了解了,谢谢你

原因: