You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
MQL4: https://docs.mql4.com/trading/ordercommission
MQL5: https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfocommission
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.
MQL4: https://docs.mql4.com/trading/ordercommission
MQL5: https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfocommission
MQL4: https://docs.mql4.com/trading/ordercommission
MQL5: https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfocommission
You missed the point. Getting the commission before opening an 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
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:
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