How do I get the commission value in MQL5?

 
Before opening a position for any instrument.

The best I could find - and it was in MQL4 - was AFTER having a position open:

   for (int pos = total - 1; pos >= 0; pos--) {
      if (OrderSelect(pos, SELECT_BY_POS)) {
         posCommission = OrderCommission();
         break;
      }
   }
I'd like to have this info to include in my calculations regarding different instruments before opening a position.

Couldn't find any equivalent in the Market Info in MQL5. Any suggestions?

Thanks in advance.
 
fulljack: Before opening a position for any instrument.

Please search before you post. It is not possible to obtain the commission value before placing and Order, only afterwards.

On MQL5 you can query the deal's properties to obtain the commission cost (after the fact).

HistoryDealGetDouble

Returns the requested property of a deal in the history (double)

ENUM_DEAL_PROPERTY_DOUBLE

DEAL_COMMISSION

Deal commission

double

 

Thanks, Fernando.

I did search, just thought it could have been some evolution in the meantime.

Very sad, as this can be 30-50% of your profit, really impacting the choice of broker and who gets to have your money.

Will keep looking for ways to get around this, but for the time being I guess it'm bound to lean on mostly unreliable recommendations, and keep a jaggy Excel sheet around.

Appreciate your input.

 

Hello, is similar to mql4. This application I use in my EAs:



//+------------------------------------------------------------------+

//|Profit  Buy                                                       |

//+------------------------------------------------------------------+

double Profit_Buy(int magic_number)

  {

   double profit = 0;


   for(int i = PositionsTotal() - 1; i >= 0; i--)

      if(PositionSelectByTicket(PositionGetTicket(i)) && PositionGetInteger(POSITION_MAGIC) == magic_number && (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetString(POSITION_SYMBOL) == Symbol())

         profit = profit + PositionGetDouble(POSITION_PROFIT) - MathAbs(PositionGetDouble(POSITION_SWAP)) + MathAbs(PositionGetDouble(POSITION_COMMISSION));


   return profit;

  }

//+------------------------------------------------------------------+



//+------------------------------------------------------------------+

//|Profit  Sell                                                      |

//+------------------------------------------------------------------+

double Profit_Sell(int magic_number)

  {

   double profit = 0;


   for(int i = PositionsTotal() - 1; i >= 0; i--)

      if(PositionSelectByTicket(PositionGetTicket(i)) && PositionGetInteger(POSITION_MAGIC) == magic_number && (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && PositionGetString(POSITION_SYMBOL) == Symbol())

         profit = profit + PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP) + MathAbs(PositionGetDouble(POSITION_COMMISSION));


   return profit;

  }

//+------------------------------------------------------------------+

 
Jhon Michael Antony Florez Roa #:

Hello, is similar to mql4. This application I use in my EAs:

...

When you post code please use the CODE button (Alt-S)!

Use the CODE button