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
Hi, thanks for this thread and post.
I have been doing a lot of back testing on my MT4 before now, it’s been going great (as supposed). But lately, it just stopped working totally and I mean all the expert advisors stopped placing trades (doesn’t matter what I do).
I checked the journal section and found loads of OrderSend Error 134 and sometimes OrderSend Error 131. Got any idea on how to work around it?
PS: I didn’t code any of the EAs, I believe however that all of the coders couldn’t have made the same mistake. My first suspect is my MT4 App but, let’s hear y’all smart minds thought on this..
▼Reply
Andriy Moraru Reply:
March 25th, 2020 at 8:06 am
OrderSend Error 134 is an error that pops up when you don’t have enough money (margin) in your account to open a trade. Either you already have too many trades open or the EA is trying to open a trade that is too big for your account. This could also be caused by the broker’s increase in margin requirements.
OrderSend Error 131 is an error that pops up when an EA is trying to open a trade with an incorrect volume. For example, if the minimum trade size is 0.1 and the EA is trying to send an order with 0.08 volume, it will be rejected with the Error 131. This could happen if your broker increased minimum trade volume or volume step either for your account type or for that particular instrument you are trying to trade.
▼Reply
Hello, As said in the article I added the lines of code in my program however they tell me that I did not define the Symbol, Volume, and Direction functions.
How should I define them?
Thanks you from France
▼Reply
Andriy Moraru Reply:
September 4th, 2020 at 9:04 am
Symbol() shouldn’t cause any problems – just make sure you are not skipping the brackets.
Volume and Direction need to be replaced with your variables or direct values (e.g., 0.1 and OP_BUY if you want to test margin for going long 0.1 lot of the pair in MT4).
▼Reply
Thanks you :)
▼Reply