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
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
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:
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
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.