Posts Tagged ‘error’

OrderSend Error 130 — What to Do?

Monday, October 6th, 2008

The expert advisors that work on one broker can stop working on another; the problem with them often lies in OrderSend Error 130. If you see Error 130 in the Log of your MetaTrader platform when your expert advisor should be opening a position, then that means that the stop-loss or take-profit levels are set to close to the current market price. In the MQL documentation this error is called ERR_INVALID_STOPS («Invalid stops»). Some Forex broker set the minimum distance between the current price and the stop-loss/take-profit levels to prevent scalping or abusing the quote delays. That’s not a real problem for the majority of the expert advisors that don’t use scalping. To prevent this error from occurring, you need to change the expert’s code.

First, you might want to know what’s the minimum stoplevel is set in your broker’s MetaTrader server. Adding this line of code will output the current minimum stoplevel for the currency pair of the chart, where you run the EA:
Print(MarketInfo(Symbol(),MODE_STOPLEVEL));

You shouldn’t be using stop-loss or take-profit level, which are closer than MarketInfo(Symbol(),MODE_STOPLEVEL) to the current market price. If your EA calculates stops and take-profits dynamically, this is what I suggest you to do:

  1. Declare a global variable for the minimum StopLevel; e.g.:
    int StopLevel;
  2. In the init() function of your expert advisor define the minimum StopLevel:
    StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
    Note, that adding a spread difference is also required.
  3. The next time your stop-loss or take-profit is calculated, just check them to be not less than StopLevel:
    if (StopLoss < StopLevel) StopLoss = StopLevel;
    if (TakeProfit < StopLevel) TakeProfit = StopLevel;
  4. Don’t forget to refresh the current market rates with RefreshRates() before adding the stop-loss/take-profits levels to the actual market rates.

That should help in the majority of the cases. At least, for me such handling of the OrderSend Error 130 has always worked.

Handling OrderSend Error 131 in MetaTrader 4

Thursday, July 10th, 2008

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.



InstaForex Broker