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
Update 2012-05-28: More on
If you have any questions or suggestions regarding OrderSend Error 130 problem with expert advisors, please feel free to reply using the form below.
Epic Tip!! TY!!!
▼Reply
khan Reply:
August 16th, 2013 at 5:04 pm
I keep getting this error non stop. my ordersend() function is as follows:
currentOrder = OrderSend(currencies[i], OP_SELL, 0.1, Bid, 3, Bid+(MarketInfo(currencies[i], MODE_STOPLEVEL) + MarketInfo(currencies[i], MODE_SPREAD))*0.0001, Bid-(MarketInfo(currencies[i], MODE_STOPLEVEL) + MarketInfo(currencies[i], MODE_SPREAD))*0.0001,”Sell”, BlueViolet);
The stuff in the stop loss and take profit areas were things that the internet told me to do but yet it still does not work. Please help!
▼Reply
admin Reply:
August 16th, 2013 at 6:04 pm
Perhaps, you are trying that on ECN account, where placing orders with SL and TP is prohibited? In that case, you have to send first an order without SL/TP and then modify it to add SL/TP.
▼Reply
khan Reply:
August 18th, 2013 at 11:27 pm
Can you tell me what I have to put in stoploss if I want to set it to 5 pips , and takeprofit to ten pips for both buy and sell trades? Thank you for replying to original post.
▼Reply
admin Reply:
August 19th, 2013 at 7:34 am
Buy trades:
Ask – 5 * Point
Ask + 10 * Point
Sell trades:
Bid + 5 * Point
Ask – 10 * Point
▼Reply
“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
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
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
Thank you very much for the code.
It fix my problem
▼Reply
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:
https://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
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
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
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
Thanks. I will try that.
▼Reply
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
Hi,
I have EA Which Give me 130 ERROR while Execute Order.
Like You said ECN Broker not Allow to put SL/TP while Order Execute.
So I need help to Chane EA program, like this First Send Order Only , After Modify it with SL and TP. Also How TO Hide SL/TP Like FAPTURBO EA.
Please i need Your help.
Thanks.
▼Reply
admin Reply:
May 15th, 2012 at 1:32 pm
You can contact Fapturbo support with this request.
▼Reply
EA name: cm_martini
worked in another broker but can’t work in exness broker , can you help me to modify that EA. please send modified EA to my email : almunpdam@yahoo.co.id
▼Reply
admin Reply:
July 19th, 2012 at 7:09 am
If you put a download link here, I can look at it.
▼Reply
hi
i have EA thats works great in the EUR/USD pair but when im trying to place it on the S&P or Nasdaq its give me error 130. when im running backtest its working great.
when trying to trade demo its always give me errors and not sending my orders. any idea? i didnt understood where to place this line :”Print(MarketInfo(Symbol(), MODE_STOPLEVEL));” for checking.
thanks for your help
▼Reply
admin Reply:
November 6th, 2012 at 8:28 pm
You need to place it anywhere in the init() function of the EA’s source code (.mq4 file). If you do not have the .mq4 file and have only .ex4, then it is not possible to add anything to your EA or alter it to fix the appearing error.
▼Reply
menny Reply:
November 6th, 2012 at 9:18 pm
i have the .mq4 file. i placed it here:
int init() {
//—-
Print(MarketInfo(Symbol(), MODE_STOPLEVEL));
pnt=MarketInfo(Symbol(),MODE_POINT);
dig=MarketInfo(Symbol(),MODE_DIGITS);
but where it should write me whats the stop levels minimum?
after i do that what should i do?
and why the back test is working well but live demo isnt?
any ideas?
thanks alot!!!menny
▼Reply
admin Reply:
November 6th, 2012 at 9:59 pm
It should print the value to your Experts tab.
▼Reply
sorry my friend i dont know where it does that i cant find it. anyway any explansion why its working in the back test and not in live demo?
is there any chance its because it sends sell stop + tp + sl at the same time? maybe it should place the tp and sl just after the sell stop is filled?
thanks
▼Reply
admin Reply:
November 7th, 2012 at 9:43 am
Here’s the Experts tab:

Yes, it may be so that the TP/SL should be set separately after the order is already open. But earlier you have said that you tried it on EUR/USD live demo and it worked.
▼Reply
well in this tab its doesnt show me the stop level just writing me the error.
in the EURUSD the EA works great only in nasdaq and s&p it shows me the error while trading live demo. but when im back testing it works fine.
what to do??
▼Reply
admin Reply:
November 7th, 2012 at 4:26 pm
Have you compiled the EA after you have added that line of code to init() function?
Are you sure it doesn’t print anything when you attach the EA to a chart?
▼Reply
what is compiled?
▼Reply
admin Reply:
November 7th, 2012 at 7:04 pm
When you apply some change to the EA’s code, you need to press a Compile button (F7).
See this tutorial for more info:
https://www.earnforex.com/blog/2007/07/metatrader-expert-advisros-users/
▼Reply
My EA works on the strategy tester but it doesnt work on the live account (test). I get a orderSend() 130
▼Reply
admin Reply:
April 8th, 2013 at 11:59 am
Do you trade on ECN account and send orders with SL/TP on them?
▼Reply
nambok Reply:
April 9th, 2013 at 1:42 am
yup, im trying to do scalping and my broker allows it, why would it allow on the strategy test and not the live account
▼Reply
admin Reply:
April 9th, 2013 at 7:14 am
It has nothing to do with allowing or disallowing scalping. If your broker uses ECN execution, your EA has to set SL/TP after opening a position.
Strategy Tester uses non-ECN execution.
▼Reply
nambok Reply:
April 10th, 2013 at 6:36 am
I see this makes sense, do you happened to know if Finfx is a ECN broker?
thanks a lot for your help :)
▼Reply
admin Reply:
April 10th, 2013 at 8:05 am
As far as I know, FinFX offers both ECN and non-ECN accounts.
▼Reply
Hello admin,
My EA made Error 130 on FinFx ECN acc.
and I don’t know how to fix this.
Can I send you my EA mql4, to fix?
this is my e-mail: sectorson@gmail.com
Thank you in advance.
▼Reply
admin Reply:
April 12th, 2013 at 8:50 am
You can upload your EA to some file sharing website and post the download link here. Though I cannot promise you that I will fix it.
▼Reply
Sector Reply:
April 12th, 2013 at 9:01 am
I upload EA, this is a link:
http://www.4shared.com/rar/2u3hzv8H/EA_ROBOT.html
▼Reply
admin Reply:
April 12th, 2013 at 10:11 am
Yeah, the EA applies SL and TP directly on position opening. It can be fixed by removing SL/TP from position opening procedures and transfer it to OrderModify() calls after positions are opened.
Unfortunately, this EA is a decompiled code and it is hell of a job to make sense out of anything there. You better contact its author asking to make it ECN-friendly.
▼Reply
Hi
I have run the EA and it keep showing Ordersend Error 130 and Ordermodify error 130. Is there a problem on the following that you can advice?
Problem A :-
▼Reply
Andriy Moraru Reply:
July 11th, 2014 at 2:46 am
I cannot see that from what you have posted. Did you read this blog post? It explains that stop-loss price should be no closer to the opening price than broker defined STOPLEVEL. Check if your EA follows this rule.
▼Reply
problem B
▼Reply
May be too little slippage is the cause of 130 error ?
How is slippage calcolated ?
e.g. slippage is 3. What is 3 ?
e.g. price 1.1111 + 3 = 1.1114 is allowed ?
or 1.11111 + 3 = 1.11114 is allowed ?
▼Reply
Andriy Moraru Reply:
January 29th, 2015 at 8:48 pm
Whether 3 pips are normal or fractional depends on the particular EA implementation, but OrderSend Error 130 has nothing to do with slippage but rather with the rate of SL, TP or a pending order’s open price.
▼Reply
Admin,
Parabéns pela explicação do erro 130. E parabéns por ajudar e esclarecer os neófitos de EA.
Gostei muito da simplicidade da explicação.
▼Reply
i allways got ordersend error 130
it is very profitable scalper mq4
can you please fix this order send error
i can mail you
▼Reply
Andriy Moraru Reply:
August 16th, 2016 at 1:05 pm
Sure. Let me see it – webmaster@earnforex.com.
▼Reply
Hi, Does the calculation… (StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);)… still hold true for a 5 digit broker? Or does the value of StopLevel need to be divided by 10?
▼Reply
Andriy Moraru Reply:
October 8th, 2016 at 6:01 am
It still holds true even for 5-digit brokers.
▼Reply
Hi
My problem is the ticket every day is -1. ticket=OrderSend(…..)
What can I do??
▼Reply
Andriy Moraru Reply:
October 25th, 2016 at 6:38 pm
Try checking the error using GetLastError().
▼Reply
Hi I have the proble of 130 for all trades sending my code can anyone help me please
▼Reply
Andriy Moraru Reply:
January 9th, 2017 at 11:17 am
First of all, 200 pips might not be enough – you should really compare it with SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL).
Then, there is a major flaw in this function – it trades on a symbol Symb given via the function’s argument. However, it uses calls to Digits and Point for normalization. Digits and Point use the current trading instrument’s parameters, so if you call buy(“EURUSD”, 13123123) when this EA is attached to USD/JPY, you will get completely wrong values.
▼Reply
alberto Reply:
June 20th, 2018 at 8:58 pm
Hi, i write from italy and just begun to write my first EA. i can not understood why some orders give me #130 error, during the execution i prints the order values and do not find any difference between the rights orders. follow my code and order debug, thanks for help and sorry for my english….
▼Reply
Andriy Moraru Reply:
June 21st, 2018 at 5:17 am
You have incorrectly calculated stop-loss. You are sending a sell order at 1.1993, but your SL is 1.19785. SL should be higher than entry for sell orders.
▼Reply
alberto Reply:
June 21st, 2018 at 8:02 am
no, it was a buy order, but you pointed out to me that the wrong value is TakeProfit that less then buy price!
i going to try to fix it!
regards!
▼Reply
I have been creating small programs already in MT4. But I have encountered an Error 130 issue with my pending order OrderModify. My level values are far higher than the minimum level required like the StopLevel and also with the formula you have above with the Spread. I have no problem modifying market orders. Its only in modifying pending orders.
▼Reply
Andriy Moraru Reply:
January 27th, 2021 at 12:59 pm
I have no idea what your custom function do and what results you are getting here. However, one possible problem I see is that it is trying to modify orders for some other symbol using the current symbol’s info for that.
▼Reply