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
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
- 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 ortake-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.
Update 2011-12-15:
Some brokers (ECN ones) don’t allow expert advisors to set


February 10th, 2009 at 7:19 am
Epic Tip!! TY!!!
▼Reply
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 ?
▼Reply
Andrei Reply:
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.
▼Reply
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
▼Reply
Andrei Reply:
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.
▼Reply
February 17th, 2010 at 5:51 am
Another current issue deals with Market Execution vs Instant Execution. One is MM with instant execution and the other one is non-dealing with Market Execution. Market Execution that is done by STP and ECN cannot send TP and SL along with the order. You have to modify order and then set the TP and SL.
▼Reply
Andrei Reply:
February 17th, 2010 at 8:43 am
Why do you think so?
▼Reply
Mark Reply:
March 2nd, 2010 at 12:57 pm
How I can do this. Can you help step by step?
▼Reply
January 20th, 2011 at 1:14 pm
Thank you very much for the code.
It fix my problem
▼Reply
September 1st, 2011 at 8:55 pm
Dear !
I try to use EA in demo account and it work fine.But when i use it on real account,always have error ordersend 130.
Pleas ! help me to know why ?
Thanks !
▼Reply
admin Reply:
September 1st, 2011 at 9:21 pm
What setting do you use?
▼Reply
alvin Reply:
September 1st, 2011 at 9:23 pm
I am use defaul setting for both of 2 account. Something wrong here ?
▼Reply
alvin Reply:
September 1st, 2011 at 9:25 pm
I am using phoenix v56_03, please ! help me
▼Reply
admin Reply:
September 1st, 2011 at 9:38 pm
Did you download Phonex from here:
http://www.earnforex.com/metatrader_expert_advisors/Phoenix
or from somewhere else?
▼Reply
alvin Reply:
September 2nd, 2011 at 3:47 am
Nobody can help me with this problem :(
▼Reply
September 1st, 2011 at 9:47 pm
Yes ! i am download your shared phoenix and use in GBPUSD.
On demo account no problem but on real account it issue
▼Reply
admin Reply:
September 2nd, 2011 at 8:34 am
Is the symbol called “GBPUSD” in your broker’s MT4? Are you sure there are no extra symbols, like “#GBPUSD” or “xGBPUSD”?
▼Reply
alvin Reply:
September 2nd, 2011 at 4:03 pm
Dear !
Thank so much, i had fix that promlem, now that EA work fine :D
▼Reply
admin Reply:
September 2nd, 2011 at 6:24 pm
And how did you do it?
▼Reply
juan david Reply:
November 29th, 2011 at 11:56 pm
im having the same problem with phoenix ( downloaded form here) and im running default settings with the recommended pairs.
i have a 1000 demo account.
thanks in advance
▼Reply
admin Reply:
November 30th, 2011 at 9:55 am
Did you try the proposed solution? Does your broker allows setting SL and TP on positions in the open order?
▼Reply
December 15th, 2011 at 9:26 am
I have an EA with SL set to 650 (65 pips) and TP set to 800 (80 pips) but am still getting error 130 on execution. It works fine in Strategy Tester. The log file is as follows:
9:00:10 MACross GBPUSDm,H1: Alert: MA crossover -> SELL GBPUSDm
09:00:10 MACross GBPUSDm,H1: MA crossover: Error opening SELL order : 130
09:00:10 MACross GBPUSDm,H1: Bid: 1.558 SL: 1.5645 TP: 1.55
The code for this is:
Do you have any ideas on how to resolve this?
▼Reply
admin Reply:
December 15th, 2011 at 2:04 pm
If you are trading on ECN account, you can’t set SL or TP on position opening, you have to do it after the order is executed.
▼Reply
December 15th, 2011 at 3:16 pm
Not sure what an ECN account is, but I know for market order, it’s not possible to set SL/TP on opening, but I have other EAs that work fine doing that.
▼Reply
admin Reply:
December 15th, 2011 at 3:24 pm
If you are sure that other EA are setting SL & TP in OrderSend() and don’t get OrderSend error 130 on this same account, then my only suggestion to you would be to apply NormalizeDouble() to your stop-loss and take-profit levels. E.g.:
▼Reply
December 15th, 2011 at 3:32 pm
Thanks. I will try that.
▼Reply
December 16th, 2011 at 8:15 pm
The conditions were just met, but the EA did not execute. Same error 130. I’m going to try a different approach. That’s for your assistance.
▼Reply
admin Reply:
December 16th, 2011 at 9:00 pm
Please let us know if you find the solution.
▼Reply