Advertisements
$ £ ¥
¥ £ $

OrderSend Error 134 (Not Enough Money) in MT4 and Error 10019 in MT5

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 4 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 — the 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 obvious non-coding solution, which is to deposit more funds to your trading account).

Fixing Error 134 (ERR_NOT_ENOUGH_MONEY) in MT4

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 stop-out level to consider the margin requirements:

if (((AccountStopoutMode() == 1) && 
(AccountFreeMarginCheck(Symbol(), Direction, Volume) > AccountStopoutLevel()))
|| ((AccountStopoutMode() == 0) && 
((AccountEquity() / (AccountEquity() - AccountFreeMarginCheck(Symbol(), Direction, Volume)) * 100) > AccountStopoutLevel())))

This will check the way your broker applies stop-out (an absolute or relative level) and then will check if there is enough free margin after in the account after the next trade gets executed.

Fixing Error 10019 (TRADE_RETCODE_NO_MONEY) in MT5

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 looks quite complex compared to the MT4 version but it checks the same condition.

Registering with a Forex broker that offers a lower stop-out level is also a good option to avoid this kind of errors.

If you have any thoughts, comments, or questions regarding MetaTrader OrderSend Error 134 or Return Code 10019 in MT5 and the ways to fix it, feel free to join our Forex forum for a discussion.

If you want to get news of the most recent updates to our guides or anything else related to Forex trading, you can subscribe to our monthly newsletter.