How to get commission fee before open order? - page 2

 

As the OP (and others) have outlined, they wish to be able to obtain the commission BEFORE the order is placed, not after it has executed.

In other words, they are looking for something like OrderCalcCommision (akin to the MQL5 functions OrderCalcProfit or OrderCalcMargin), which MetaQuotes has sadly not implemented for commission.

 
 

You missed the point. Getting the commission before opening an order.

Xiangdong Guo #: Is there any MQL function (method or way) to calculate commission value before open order?
 

Of course(!!!) there is no available function in mql4 to calculate the commission before an order has been opened.
Commissions vary with different brokers and the value is not part of the instrument specification, thus there can be  
no MarketInfo or SymbolInfo constant to access the value. 
Still as others already partly pointed out, there are some options, depending on the architecuture of your EA: 
1) Retrieve the orders's history via OrdersHistoryTotal() and look for an order of the same instrument and 
take the commission from there and re-calculate it for your order before placement. 
2) Place the order and right after retrieve the commission from the new ticket-id and via OrderCommission() and 
adjust your SL/TP if that is what you want. 
3) Provide settings parameters for your EA that contain the individual broker's commissions for forex, CFD and index CFDs.
To determine inside your code what type of instrument you are dealing with you can use SymbolInfo with 

MODE_MARGINCALCMODE

28

Margin calculation mode. 0 - Forex; 1 - CFD; 2 - Futures; 3 - CFD for indices

 
Xiangdong Guo:

Hi there,

I'd like to know any MQL4/5 function to get commission fee before open order.

Thanks in advance.

Hello,

To estimate commission fees for a specific symbol in MQL4/5 before opening an order, here are two suggestions:

  1. Using Historical Data: Check the trade history for past trades on the desired symbol. Calculate the commission per lot by dividing the commission of a closed trade by its lot size. Then, multiply by your intended lot size to estimate the commission for a new order. This assumes the broker’s commission rate is consistent.
  2. Test Position Approach: Open a position with the smallest possible lot size (e.g., 0.01 lots), note its commission, and close it immediately. Multiply this commission by 100 to estimate the commission for a 1-lot position. For example, if 0.01 lots has a $0.05 commission, a 1-lot position would be $5. Be cautious, as this involves real trading—test in a demo account first.

Best Approach: The most reliable method is to check the commission for each symbol directly from the Market Watch in MetaTrader, under the symbol’s specifications (e.g., right-click on the symbol, select "Specification"). Note the commission rate (e.g., $5 per lot) and hardcode it into your code for accurate calculations.

Important Note: Some brokers charge half the commission when opening a position and the other half when closing it. Always verify your broker’s commission policy (via their documentation, symbol specifications, or support) to ensure accurate estimates.

Best regards
Hamid Marwi