How to get the commision and swaps of a position in MetaTrader

in MQL5 how can I get the commissions and swaps of an open position (by ticket)? is this not possible?

t depends on your broker (and system patches from MQL5).

There is a bit of history regarding this on commission.

A long time back, commission was absent in the positions and deals for both the demo account, and live account.

Commission was only calculated into your live statement as a separate entry. It is the gross amount including exchange fee if any.

I have checked my old indicator, and it can now grab commission from each deal on the demo account, which is great. (Just use double comm = HistoryDealGetDouble(ticket, DEAL_COMMISSION) )

But on live account, commission is still absent.

So in the meantime, you have to configure this number into your trading system.

I have checked with my broker and the help desk says that MQL5 is going to patch their system to enable commission during real time trading on live account.

I asked for it because if they do not enable this feature, the traders may lose more than the deposit… It is bad for the traders as well as for the broker.

Equity calculation will be wrong if commission is not computed into the deals. On some cases, commission is actually dynamic depending on the sign up package with the broker.

So in actual fact, commission is a dynamic number, not something that can be logically computed according to lot size, but depend on the broker’s own rules in server.

So you might have to wait for this feature to be added in, some time this year. (This is a 100% confirmation from my side.)

You have to ask the help desk of your broker regarding this.

P.S. I can’t comment on Swaps, because I have no experience retrieving this on MQL5. Only on MQL4 using OrderSwap(). Need others to comment on this.

thanks for the info, really a great explanation.

About Swaps I was asking because it is, by nature, hard to test - was yesterday at least… luckily today I still had some positions open, and could now see that the POSITION_SWAP works because it is now a non-zero value in the terminal.

If you can see on your terminal, you should be able to extract it. They differentiate position, order and deal on MQL5.