Sometimes, especially during backtesting or in case of a badly designed expert advisor, the OrderSend Error 134 (or ERR_NOT_ENOUGH_MONEY) appears in the Journal log of your MetaTrader platform. In MT5 this error is called TRADE_RETCODE_NO_MONEY and has a code 10019. The reason for this error is the same for both versions of the platform — lack of free margin to execute the OrderSend function for the given position volume. The methods to solve this error are quite different (we won’t discuss the
In MetaTrader 4, you have to code your EA to perform the following check before executing OrderSend():
if (AccountFreeMarginCheck(Symbol(), Direction, Volume) > 0) |
It will check how much free margin will be available after opening a position with the volume = Volume in a given direction = Direction. But comparing it with 0 isn’t a very good solution. One should pay attention to the broker’s
if (((AccountStopoutMode() == 1) && (AccountFreeMarginCheck(Symbol(), Direction, Volume) > AccountStopoutLevel())) || ((AccountStopoutMode() == 0) && ((AccountEquity() / (AccountEquity() - AccountFreeMarginCheck(Symbol(), Direction, Volume)) * 100) > AccountStopoutLevel()))) |
This way we check the way your broker applies
For MetaTrader 5 this condition would look like this (replace SYMBOL_MARGIN_LONG with SYMBOL_MARGIN_SHORT if you want to check margin before opening a short position):
if (((AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE) == ACCOUNT_STOPOUT_MODE_MONEY) && (AccountInfoDouble(ACCOUNT_FREEMARGIN) - SymbolInfoDouble(Symbol(), SYMBOL_MARGIN_INITIAL) * Lots * SymbolInfoDouble(Symbol(), SYMBOL_MARGIN_LONG) > AccountInfoDouble(ACCOUNT_MARGIN_SO_SO))) || ((AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE) == ACCOUNT_STOPOUT_MODE_PERCENT) && ((AccountInfoDouble(ACCOUNT_EQUITY)/(AccountInfoDouble(ACCOUNT_EQUITY) - (AccountInfoDouble(ACCOUNT_FREEMARGIN) - SymbolInfoDouble(Symbol(), SYMBOL_MARGIN_INITIAL) * Lots * SymbolInfoDouble(Symbol(), SYMBOL_MARGIN_LONG))) * 100 > AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)))) |
It is quite complex compared to the MT4 version but it checks the same condition.
Registering with a Forex broker that offers a lower
Update 2016-11-01: Thanks to Alexander Wait’s comment, I have corrected the formulas for account margin check.
If you have any thoughts, comments, or questions regarding MetaTrader OrderSend Error 134 or Return Code 10019 in MT5 and the ways to treat it, feel free to reply to this post using the form below.
thanks for this. i’ll note it and add it to my mt5 updates. with the error codes i mean.
▼Reply
Nice tip. Ever since US broker decreased their leverage level, my EAs run into error 134 occasionally… Never tried programming for MT5, hope it won’t be too different… Thanks anyway
▼Reply
Great advice on how to fix error 134. I just wanted to point out that the
following formula for MT4 is actually not quite right.
Let X = AccountFreeMarginCheck(Symbol(), Direction, Volume); then
(X / AccountEquity()) * 100) > AccountStopoutLevel() is incorrect.
The correct formula is actually the following:
(AccountEquity() / (AccountMargin()) * 100 > AccountStopoutLevel()
Since AccountMargin() = AccountEquity() – X, the following formula is
expressed in terms of free margin in the trading account:
(AccountEquity() / (AccountEquity() – X)) * 100 > AccountStopoutLevel()
▼Reply
Andriy Moraru Reply:
November 1st, 2016 at 5:45 pm
Thanks a lot, Alexander! You are completely right! I have now updated the post to list the correct formula.
▼Reply
Hi Guys im a newbie wanted to know what would be the setting for 30$ deposit to trade
Kindly advise
Thanks
▼Reply
Andriy Moraru Reply:
December 29th, 2017 at 6:10 am
Your position size is limited depending on your broker’s required margin level.
▼Reply