Advertisement
OrderSend Error 130 in MT4/MQL4: Invalid Stops Fix

OrderSend Error 130 in MT4/MQL4 means that the stop loss, take profit, or pending order price is invalid. In most cases, this error occurs when the stop level is too close to the current market price.
This error is commonly shown as Invalid Stops. It often happens when an EA sends an order with a stop loss or take profit that does not satisfy the broker’s minimum stop distance.
Quick answer:
OrderSend Error 130 is ERR_INVALID_STOPS. Check
OrderSend Error 130 is ERR_INVALID_STOPS. Check
MODE_STOPLEVEL, confirm the distance between the current price and SL/TP, and make sure pending order prices follow the broker’s rules.What Does OrderSend Error 130 Mean?
In MQL4, Error 130 is known as:
- Error code: 130
- Error name: ERR_INVALID_STOPS
- Meaning: Invalid stops
This means that the stop loss, take profit, or pending order price passed to OrderSend() is not accepted by the broker.
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLoss, TakeProfit, "buy order", Magic, 0, clrBlue); If StopLoss or TakeProfit is too close to the current price, MT4 may return Error 130 and the order will not be placed.
Common Causes of OrderSend Error 130
| Cause | Example | How to Fix |
|---|---|---|
| Stop loss is too close to the current price | A Buy order sets SL only a few points below the current price | Check MODE_STOPLEVEL and increase the distance |
| Take profit is too close to the current price | A Sell order sets TP too close to the Ask price | Set TP farther away from the current market price |
| Pending order price is invalid | A Buy Limit is placed above the current Ask price | Use the correct price direction for each pending order type |
| Price is not normalized | The EA uses a price with too many decimal places | Use NormalizeDouble(price, Digits) |
| The broker does not allow SL/TP in the initial market order | Some ECN accounts reject orders with SL/TP set at order entry | Send the order first with SL/TP as zero, then use OrderModify() |
How to Check StopLevel in MQL4
The first thing to check is the broker’s minimum stop distance.
You can get this value with MarketInfo() and MODE_STOPLEVEL.
int stopLevel = (int)MarketInfo(Symbol(), MODE_STOPLEVEL);
double minStopDistance = stopLevel * Point;
Print("StopLevel: ", stopLevel);
Print("Minimum stop distance: ", minStopDistance); MODE_STOPLEVEL returns the minimum distance in points.
For example, if StopLevel is 20, the stop loss and take profit must usually be at least 20 points away from the current price.
Important:
On many 5-digit brokers,
On many 5-digit brokers,
Point is not the same as one pip.
Always check how your EA handles points and pips before calculating SL or TP.Correct Stop Loss and Take Profit Direction
Error 130 can also happen when the stop loss or take profit is placed on the wrong side of the market.
| Order Type | Stop Loss | Take Profit |
|---|---|---|
| Buy | Below the current price | Above the current price |
| Sell | Above the current price | Below the current price |
For a Buy order, the stop loss should be below the market and the take profit should be above the market.
RefreshRates();
double sl = Bid - 100 * Point;
double tp = Bid + 100 * Point;
sl = NormalizeDouble(sl, Digits);
tp = NormalizeDouble(tp, Digits);For a Sell order, the stop loss should be above the market and the take profit should be below the market.
RefreshRates();
double sl = Ask + 100 * Point;
double tp = Ask - 100 * Point;
sl = NormalizeDouble(sl, Digits);
tp = NormalizeDouble(tp, Digits);MQL4 Code Example: Check Stop Distance Before OrderSend
The following function checks whether SL and TP are far enough from the current market price.
//+------------------------------------------------------------------+
//| Check whether stop loss and take profit are valid |
//+------------------------------------------------------------------+
bool IsStopDistanceValid(int orderType, double sl, double tp)
{
RefreshRates();
double stopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point;
if(orderType == OP_BUY)
{
if(sl > 0 && (Bid - sl) < stopLevel)
return false;
if(tp > 0 && (tp - Bid) < stopLevel)
return false;
}
if(orderType == OP_SELL)
{
if(sl > 0 && (sl - Ask) < stopLevel)
return false;
if(tp > 0 && (Ask - tp) < stopLevel)
return false;
}
return true;
} You can use this function before calling OrderSend().
RefreshRates();
double sl = Bid - 100 * Point;
double tp = Bid + 100 * Point;
sl = NormalizeDouble(sl, Digits);
tp = NormalizeDouble(tp, Digits);
if(!IsStopDistanceValid(OP_BUY, sl, tp))
{
Print("Invalid stops. Check StopLevel, SL, and TP.");
return;
}
int ticket = OrderSend(
Symbol(),
OP_BUY,
Lots,
Ask,
Slippage,
sl,
tp,
"buy order",
Magic,
0,
clrBlue
);
if(ticket < 0)
{
int err = GetLastError();
Print("OrderSend failed. Error: ", err);
}Pending Orders Can Also Cause Error 130
OrderSend Error 130 is not limited to stop loss and take profit. It can also happen when the pending order price is invalid.
| Pending Order Type | Correct Price Direction |
|---|---|
| Buy Limit | Below the current Ask price |
| Buy Stop | Above the current Ask price |
| Sell Limit | Above the current Bid price |
| Sell Stop | Below the current Bid price |
For example, a Buy Limit should be placed below the current Ask price. If it is placed above the current Ask price, the pending order condition is invalid and Error 130 may occur.
RefreshRates();
double price = Ask - 100 * Point; // Buy Limit price below Ask
price = NormalizeDouble(price, Digits);
int ticket = OrderSend(
Symbol(),
OP_BUYLIMIT,
Lots,
price,
Slippage,
0,
0,
"buy limit",
Magic,
0,
clrBlue
); Note:
Pending orders must also satisfy the broker’s minimum stop distance. The order price itself may be rejected if it is too close to the current price.
Pending orders must also satisfy the broker’s minimum stop distance. The order price itself may be rejected if it is too close to the current price.
ECN Broker Case: Send Order First, Then Modify Stops
Some brokers or account types may reject a market order when SL and TP are included in the initial OrderSend().
In this case, a common solution is to send the order with SL and TP set to zero, then set them later with OrderModify().
RefreshRates();
int ticket = OrderSend(
Symbol(),
OP_BUY,
Lots,
Ask,
Slippage,
0,
0,
"buy order",
Magic,
0,
clrBlue
);
if(ticket < 0)
{
Print("OrderSend failed. Error: ", GetLastError());
return;
}
if(OrderSelect(ticket, SELECT_BY_TICKET))
{
RefreshRates();
double sl = Bid - 100 * Point;
double tp = Bid + 100 * Point;
sl = NormalizeDouble(sl, Digits);
tp = NormalizeDouble(tp, Digits);
bool modified = OrderModify(
ticket,
OrderOpenPrice(),
sl,
tp,
0,
clrBlue
);
if(!modified)
Print("OrderModify failed. Error: ", GetLastError());
}This method can help when the initial order is accepted only without stop loss and take profit.
How to Debug OrderSend Error 130
When Error 130 occurs, print the current price, StopLevel, SL, and TP. This makes it much easier to identify which value is invalid.
RefreshRates();
int stopLevel = (int)MarketInfo(Symbol(), MODE_STOPLEVEL);
double minStopDistance = stopLevel * Point;
Print("Bid: ", Bid);
Print("Ask: ", Ask);
Print("StopLevel: ", stopLevel);
Print("Minimum stop distance: ", minStopDistance);
Print("StopLoss: ", StopLoss);
Print("TakeProfit: ", TakeProfit);Then check the Experts tab or the Journal tab in MT4. If SL or TP is closer than the minimum stop distance, that is likely the reason for Error 130.
StopLevel Is Zero but Error 130 Still Occurs
In some cases, MODE_STOPLEVEL may return zero.
This does not always mean that any stop distance is accepted.
Some brokers use dynamic stop levels depending on market conditions, spread, or server-side rules.
If MODE_STOPLEVEL is zero but Error 130 still occurs, check the following:
- Spread is temporarily wide
- The broker uses dynamic stop restrictions
- The order price or stop price is not normalized
- The EA is sending SL/TP too quickly after price changes
- The broker requires SL/TP to be set after the order is opened
Related MQL4 Errors
OrderSend Error 130 is often confused with other OrderSend errors. The table below shows the main differences.
| Error Code | Error Name | Main Cause |
|---|---|---|
| 129 | ERR_INVALID_PRICE | The order price is invalid |
| 130 | ERR_INVALID_STOPS | Stop loss, take profit, or pending order price is invalid |
| 131 | ERR_INVALID_TRADE_VOLUME | The lot size is invalid |
| 134 | ERR_NOT_ENOUGH_MONEY | The account does not have enough margin |
FAQ About OrderSend Error 130
What does OrderSend Error 130 mean in MT4?
OrderSend Error 130 means ERR_INVALID_STOPS. It occurs when the stop loss, take profit, or pending order price is invalid according to the broker’s trading rules.
Why does Error 130 occur when my entry signal is correct?
Error 130 is usually caused by the order parameters, not the entry signal. Even if the buy or sell condition is correct, the order can fail if SL, TP, or the pending order price is too close to the current price.
How can I check the minimum stop distance in MQL4?
You can check the minimum stop distance by using MarketInfo(Symbol(), MODE_STOPLEVEL). The returned value is in points, so multiply it by Point when comparing it with price distances.
Can pending orders cause OrderSend Error 130?
Yes. Pending orders can cause Error 130 if the order price is on the wrong side of the market or too close to the current Bid or Ask price.
Why does MODE_STOPLEVEL return zero but Error 130 still occurs?
Some brokers use dynamic stop restrictions. Even if MODE_STOPLEVEL returns zero, the server may still reject stops depending on spread, market conditions, or account rules.
How do I fix OrderSend Error 130?
Check MODE_STOPLEVEL, make sure SL and TP are far enough from the current price, normalize all price values with NormalizeDouble(price, Digits), and confirm that pending order prices follow the correct direction.
Summary
OrderSend Error 130 in MT4/MQL4 means that the stop settings are invalid. In most cases, the problem is caused by SL, TP, or a pending order price that is too close to the current market price.
- Error 130 is ERR_INVALID_STOPS.
- Check
MODE_STOPLEVELbefore setting SL or TP. - Make sure Buy and Sell stops are placed on the correct side of the market.
- Pending orders must also follow the correct price direction.
- Use
NormalizeDouble(price, Digits)for order prices, SL, and TP. - If the broker rejects SL/TP in the initial order, send the order first and then use
OrderModify().
If your EA returns Error 130, start by printing Bid, Ask, StopLevel, SL, and TP. Understanding which price is invalid is the fastest way to fix the EA and avoid the same error in future tests.
Related: OrderSend Error 129 in MT4/MQL4
Related: OrderSend Error 130 in MT4/MQL4
Related: OrderSend Error 131 in MT4/MQL4
