Handling OrderSend Error 131 in MetaTrader 4

OrderSend Error 131 is a very frequent problem that is usually encountered when testing MT4 expert advisors. What causes this error? It is called ERR_INVALID_TRADE_VOLUME in the MetaTrader 4 documentation. It means that your expert advisor (EA) is trying to send an order with invalid trade volume. At the absolute majority of the MT4 brokers, setting some EA to open an order with 0.123 lots volume will generate this error. But sometimes, it is generated when an EA created for mini or micro accounts is used on a standard account. If you stumble upon an OrderSend Error 131 during your strategy testing, you can quickly find the wrong settings of your EA. To do so, find the standard OnInit() (or init() in older versions of MT4) function inside your EA's code and insert these lines of code there:

Print("MODE_LOTSIZE = ", MarketInfo(Symbol(), MODE_LOTSIZE));
Print("MODE_MINLOT = ", MarketInfo(Symbol(), MODE_MINLOT));
Print("MODE_LOTSTEP = ", MarketInfo(Symbol(), MODE_LOTSTEP));
Print("MODE_MAXLOT = ", MarketInfo(Symbol(), MODE_MAXLOT));

The output will be valid for the current chart's trading symbol and for the trading account type you are currently logged in. The first line will tell you how many units there are in one lot of the current trading symbol (100,000 would mean a standard-sized lot). Remember that in your expert advisor's log, this line will be first from the bottom. The second line will tell you the minimum amount of lots you can trade (this is the most usual error; you probably just need to fix the amount of lots your EA trades from 0.1 to 1). The third one will give the step size for the trade volume in lots. The fourth line will tell you the maximum number of lots that your EA can trade.

For example, a Standard trading account at Exness Forex broker generates the following information when the above-mentioned lines of code are executed on a EUR/USD chart:

Example Output of Min Lot, Max Lot, Lot Size, and Lot Step in MetaTrader 4

This means that 1 lot comprises 100,000 units (a standard size), the minimum trade volume is 0.01 lot (so, you can trade starting from $0.10 per pip in a dollar-based currency pair), the minimum trade volume step is also 0.01 lot (you can trade 0.33, 0.4 or 1.25 lot volumes, but you cannot send orders with 0.333 lot size), and the maximum volume you can use to open a position is 200 lots.

You can incorporate the MarketInfo() function at a more complex level into your EA, so that it could automatically check the allowed values and auto-correct the EA's trade parameters. But if you don't want to code much, you can just use the code above to find out the right values and correct the settings manually.

You can discuss your personal struggles with the OrderSend Error 131 problem on our forum if you are having trouble solving this issue on your own.

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.

© 2005–2021


Design — Mart Studio

Forex trading bears intrinsic risks of loss. You must understand that Forex trading, while potentially profitable, can make you lose your money. Never trade with the money that you cannot afford to lose! Trading with leverage can wipe your account even faster.

CFDs are leveraged products and as such loses may be more than the initial invested capital. Trading in CFDs carry a high level of risk thus may not be appropriate for all investors.