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).
Returns the requested property of a deal in the history (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;
}
//+------------------------------------------------------------------+
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).
Returns the requested property of a deal in the history (double)
DEAL_COMMISSION
Deal commission
double
Even though I do it your way, I still get 0 commission value.
double CalculateDailyNetProfit() { double total = 0.0; datetime day_start = iTime(_Symbol, PERIOD_D1, 0); if(!HistorySelect(day_start, TimeCurrent())) { Print("Failed to select the history for: ", _Symbol); return 0.0; } for(int i = 0; i < HistoryDealsTotal(); i++) { ulong ticket = HistoryDealGetTicket(i); if(ticket > 0 && HistoryDealGetString(ticket, DEAL_SYMBOL) == _Symbol && HistoryDealGetInteger(ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT && (HistoryDealGetInteger(ticket, DEAL_TYPE) == DEAL_TYPE_BUY || HistoryDealGetInteger(ticket, DEAL_TYPE) == DEAL_TYPE_SELL)) { double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT); double commission = HistoryDealGetDouble(ticket, DEAL_COMMISSION); double swap = HistoryDealGetDouble(ticket, DEAL_SWAP); double net_profit = profit + commission + swap; if(commission != 0.0) Print("Commission: ", commission); total += net_profit; } } return total; }
However, in History, the total Commission is a huge number.
What did I do wrong?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use

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