Forex Blog

First-hand Forex trading experience and information about foreign exchange market that will be useful to traders


Handling OrderSend Error 131 in MetaTrader 4

July 10, 2008 (Last updated on December 5, 2009) by

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

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

The first line will give you the information regarding how many units one lot holds when you trade in this account (100000 would mean a standard-sized lot). Remember, that in your expert advisor’s log this line will be first starting from down to up, not vice versa. The second line will tell you the minimum amount of lots you can trade (this is the most usual error; you’ll probably just need to fix the amount of lots your EA trades from 0.1 to 1). The third one will give the minimum step for the trade volume in lots. The fourth line will tell you the maximum amount of lots that your EA can trade.

For example, demo account at FXOpen generates this info when I insert those lines into the code:

2008.07.10 15:13:37 MACD Sample EURUSD, H1: 10000
2008.07.10 15:13:37 MACD Sample EURUSD, H1: 0.01
2008.07.10 15:13:37 MACD Sample EURUSD, H1: 0.01
2008.07.10 15:13:37 MACD Sample EURUSD, H1: 100000

That means that 1 lot is 100,000 units (a standard size), minimum trade volume is 0.01 lot (so, one can trade starting from $10 on 1 position in a dollar-based currency pair), minimum trade volume step is also 0.01 lot (one can trade 0.33, 0.4 or 1.25 lot volumes, but can’t send orders with 0.333 lot size) and the maximum volume one can use to open a position is 10,000 lots.

You can incorporate the MarketInfo() function at a more complex level into your EA, so it could automatically check the allowed values and correct its settings. 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.

11 Responses to “Handling OrderSend Error 131 in MetaTrader 4”

  1. chief2000

    This is some Enhancement:
    // ===============================================
    Print(“MODE_LOTSIZE = “, MarketInfo(Symbol(),MODE_LOTSIZE), “, Symbol = “, Symbol());
    Print(“MODE_MINLOT = “, MarketInfo(Symbol(),MODE_MINLOT), “, Symbol = “, Symbol());
    Print(“MODE_LOTSTEP = “, MarketInfo(Symbol(),MODE_LOTSTEP), “, Symbol = “, Symbol());
    Print(“MODE_MAXLOT = “, MarketInfo(Symbol(),MODE_MAXLOT), “, Symbol = “, Symbol());
    // ===============================================


    Ogün POLAt Reply:

    Thanks for your help.But ı have used this code and i learned max lot size is 30.
    How can i increase max lot size.

    Yours sincerely.


    admin Reply:

    Only your broker can increase your allowed max lot size. You may try contacting their support service about that but I am not sure that they will increase it. Do you really have to open such big positions?


  2. Chad

    “You can incorporate the MarketInfo() function at a more complex level into your EA, so it could automatically check the allowed values and correct its settings”

    Please what is the code. I need it but I am not a coder. Grateful. Chad


  3. Andrei

    Chad, If you aren’t coder it’d be better for you to use the solution proposed in this post. Integration of MarketInfo() into code for automatic adjustments is different in each case and I won’t be able to help you here. More than that, you don’t really need it if you aren’t a professional coder.


  4. RobotFX

    God bless you!
    I was going crazy trying to figure this out. I finally understand why my EA works on mini but not so well on normal accounts.


  5. Steve

    The other issue I didn’t see mentioned here is that some live accounts use different symbols than the demo account.. A simple mistake but You have to use the correct symbol, ie instead of AUDUSD you might need to use AUDUSD.FX .. this will throw that error also.


    Andriy Moraru Reply:

    Yeah, this is also an issue sometimes. Especially, if you have symbol name’s hardcoded into an EA or set via string input parameter. Not only currency pairs names can be different between live and demo accounts – different live account types at the same broker can have different names, e.g. EURUSD.m for mini accounts and EURUSD.f for fixed spread accounts.


  6. Boitshepo

    my EA do not have standard init().

    im using fbs broker.
    micro account.

    I don’t know how to fix this orderSend error 131


    Andriy Moraru Reply:

    It can be called OnInit() in newer EAs. If there is neither init() nor OnInit() function, you can just add one.


    Buchi Reply:

    I have noticed such a similar error with a micro-account.
    Please check if the broker has micro currency pairs, if yes, add such in the chart and see if it resolves the issue.


Leave a Reply

required (will not be published)