Link

26 May 2017, 12:33
Jatin Patel
0
93

https://www.mql5.com/en/articles/138



if(m_position.SelectByTicket(myticket))
     {
      double profit=m_position.Profit();
      Comment("Profit = ",DoubleToString(profit,2));
     }


2.2.2 The CountOrders function

//+------------------------------------------------------------------+
//|  Count Total Orders for this expert/symbol                             |
//+------------------------------------------------------------------+
int CountOrders()
  {
   int mark=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(myorder.Select(OrderGetTicket(i)))
        {
         if(myorder.Magic()==EA_Magic && myorder.Symbol()==_Symbol) mark++;
        }
     }
   return(mark);
  }
//--- variables for returning values from position properties

   double   open_price;
   double   initial_volume;
   long     positionID;
   double   position_profit;

   ENUM_POSITION_TYPE      type;

//--- number of current positions

   uint     total=PositionsTotal();
//--- go through orders in a loop
   for(uint i=0;i<total;i++)
     {
      //--- return order ticket by its position in the list
      if(PositionSelect(symbol)==true)
        {
         //--- return order properties
         open_price    =PositionGetDouble(POSITION_PRICE_OPEN);
         positionID    =PositionGetInteger(POSITION_IDENTIFIER);
         initial_volume=PositionGetDouble(POSITION_VOLUME);
         position_profit=PositionGetDouble(POSITION_PROFIT);
         
         type          =(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
         Alert(EnumToString(type));  

         
         
        }

to close the position by placing a reverse order of the same size

CTrade m_Trade;
m_Trade.Buy(lot,symbol_name,price,sl,tp,comment);

Share it with friends: