bool CheckMoneyForTrade(string symb,double lots,ENUM_ORDER_TYPE type) { //--- Getting the opening price MqlTick mqltick; SymbolInfoTick(symb,mqltick); double price=mqltick.ask; if(type==ORDER_TYPE_SELL) price=mqltick.bid; //--- values of the required and free margin double margin,free_margin=AccountInfoDouble(ACCOUNT_MARGIN_FREE); //--- call of the checking function if(!OrderCalcMargin(type,symb,lots,price,margin)) { //--- something went wrong, report and return false Print("Error in ",__FUNCTION__," code=",GetLastError()); return(false); } //--- if there are insufficient funds to perform the operation if(margin>free_margin) { //--- report the error and return false Print("Not enough money for ",EnumToString(type)," ",lots," ",symb," Error code=",GetLastError()); return(false); } //--- checking successful return(true); }
Check this link.

- www.mql5.com
I have been quite puzzled by putting free margin check for Validation Test.
I can appreciate the meaning of having this check in live/demo trading and back-testing, where a person can come in and intersect upon finding out there is insufficient fund for opening a trade.
i.e.: He either reduces the lot size or add money to the account then restart the EA or close some running trades.
Or, perhaps a recklessly optimistic user, who has running trades, may even choose let the EA continue to run and hope to end in profit by those trades and "recover" some margin.
What would the validation tester do? Will it look up for the error print and be satisfied with that the check being in place before a trade order is sent?
Will it then change the criteria and proceed with the next test?
Would you kindly share your thoughts please?
Thanks!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
No issues were encountered in backtesting or live trading.