OrderSend Error 130 — What to Do?
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:
- Declare a global variable for the minimum StopLevel; e.g.:
int StopLevel; - 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. - 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; - 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.
Tags: error, expert advisors, MetaTrader, MT4


February 10th, 2009 at 7:19 am
Epic Tip!! TY!!!
March 31st, 2009 at 9:26 pm
“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.”
Whats is the reason for broker to do that if you can stop loos by hand ?
March 31st, 2009 at 10:09 pm
Because it’s almost impossible to constantly abuse the low stop-loss manually. Real abusers create EAs that do that.
April 4th, 2009 at 5:10 am
Hi,
Thanks for the info – but I have a question I hope you can help with. My EA places pending orders, with TP and SL placed between 25 and 50 pips from open. Every now and then I get error 130, I presume because the SL is close to current price. Surely the error should only occur when SL is too close to the opening price, NOT the current price on a pending trade. adjusting the SL too much will change the nature of the trade – any ideas for this one. BTW I am using Alpari UK.
Thanks
Richard
April 4th, 2009 at 9:31 am
Richard,
I am not sure but I believe that it’s not because SL or TP are close to the current price, but because your opening price in the pending order is too close to the current.