Using the class CCAccountInfo. Not sure it works in indicators.
https://www.mql5.com/en/docs/standardlibrary/tradeclasses/caccountinfo/caccountinfomargincheck
- www.mql5.com
Using the class CCAccountInfo. Not sure it works in indicators.
https://www.mql5.com/en/docs/standardlibrary/tradeclasses/caccountinfo/caccountinfomargincheck
Thanks this is great.
This is so far closest thing to AccountFreeMarginCheck in MQL4.
I just also found that they in fact have FreeMarginCheck too in MQL5 language. No wonder why the search did not come back with this. Because they called different name now.
Anyway, it is great finding.
Thanks so much blouf.
Regards.
double FreeMarginCheck( const string symbol, // symbol ENUM_ORDER_TYPE trade_operation, // operation double volume, // volume double price // price ) const
Found the ways to check margin without using other library.
Please try this code and let me know what you think.
I think it is working fine. :)
double freeMargin = AccountInfoDouble(ACCOUNT_FREEMARGIN); double margin = 0.0; bool ret = OrderCalcMargin(ORDER_TYPE_BUY, mSymbol, volume, mAsk, margin); if(freeMargin - margin <= 0.0 || ret != true) { printf("AIM: Not enougth Money to send buy order with %f lot or Margin Calculation Error", volume); Sleep(1000); return (false); }
Found the ways to check margin without using other library.
Please try this code and let me know what you think.
I think it is working fine. :)
Thanks. Great approach.
Slightly adjusted it to new mql5 constant names:
double free_margin = AccountInfoDouble(ACCOUNT_MARGIN_FREE); double margin = 0.0; bool margin_check_result = OrderCalcMargin(ORDER_TYPE_BUY, _Symbol, lots, ask, margin); if(free_margin - margin <= 0.0 || margin_check_result != true) { printf("Not enough money to send order with %f lot or Margin Calculation Error", lots); Sleep(1000); return (false); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi. Traders and Coders.
I used this article to convert my MQL4 code to MQL5 code. https://www.mql5.com/en/articles/81
Just found that AccountFreeMarginCheck in MQL4 is not available in MQL5.
Does anyone have some ways of checking free margin before sending order in MQL5 ?
The code look like this in MQL4:
I need to do pretty much same for MQL5 too.
It will be really appreciated if you can share how to replace above MQL4 code in MQL5 language ? As far as I know, CTrade does not have such a functionality either. However including this function makes a lot of sense.
Thanks so much in advance for your sharing.
Kind regards.
F.E.