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;
}
//+------------------------------------------------------------------+
- 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: