Position Commission

 

Hello Friends 

I've been trying to get the commission of opened positions but it's not working.

I used P.Commission(), but it's returning 0.

 
Osazee Asikhemhen: I've been trying to get the commission of opened positions but it's not working. I used P.Commission(), but it's returning 0.

Don't just state that it is "not working". That has no meaning or relevance without any context. We cannot read your mind.

We cannot help you without details or sample code. Show also log output of your debug prints.

 
//I Decleared this at the begining of my code
#include <Trade\PositionInfo.mqh>
CPositionInfo  P;  





//This is the function to return floating profit and loss
double GetFloatPNL(string name, string bias)
{
   double floatpnl = 0;
   
    for (int i = PositionsTotal() - 1; i >= 0; i--)
      {
         ulong   posTicket  = PositionGetTicket(i);
         long    pos_type   = PositionGetInteger(POSITION_TYPE);
         string  pos_symbol = PositionGetString(POSITION_SYMBOL);
         double  posProfit  = PositionGetDouble(POSITION_PROFIT);
         double  posLot     = PositionGetDouble(POSITION_VOLUME);
         double  posSwap    = PositionGetDouble(POSITION_SWAP);
         double  posCommsn  = P.Commission();
         
         if (pos_symbol == name)
            {
               if(bias == "buy" && pos_type == ORDER_TYPE_BUY)
                  {
                     double cur_pnl = posProfit + posCommsn + posSwap;
                     floatpnl = floatpnl + cur_pnl;
                  }
               if(bias == "sell" && pos_type == ORDER_TYPE_SELL)
                  {
                     double cur_pnl = posProfit + posCommsn + posSwap;
                     floatpnl = floatpnl + cur_pnl;
                  }
            }      
      }
      
   return floatpnl;
}
 
Fernando Carreiro #:

Don't just state that it is "not working". That has no meaning or relevance without any context. We cannot read your mind.

We cannot help you without details or sample code. Show also log output of your debug prints.



Thanks for you response, Sir

 
That's my code above
Reason: