OrderSend Error 130 in MT4/MQL4: Invalid Stops Fix

MT4 and MQL4 technical notes eyecatch image with a degu mascot, code panel, and trading chart background
Advertisement

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 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

CauseExampleHow to Fix
Stop loss is too close to the current priceA Buy order sets SL only a few points below the current priceCheck MODE_STOPLEVEL and increase the distance
Take profit is too close to the current priceA Sell order sets TP too close to the Ask priceSet TP farther away from the current market price
Pending order price is invalidA Buy Limit is placed above the current Ask priceUse the correct price direction for each pending order type
Price is not normalizedThe EA uses a price with too many decimal placesUse NormalizeDouble(price, Digits)
The broker does not allow SL/TP in the initial market orderSome ECN accounts reject orders with SL/TP set at order entrySend 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, 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 TypeStop LossTake Profit
BuyBelow the current priceAbove the current price
SellAbove the current priceBelow 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 TypeCorrect Price Direction
Buy LimitBelow the current Ask price
Buy StopAbove the current Ask price
Sell LimitAbove the current Bid price
Sell StopBelow 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.

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 CodeError NameMain Cause
129ERR_INVALID_PRICEThe order price is invalid
130ERR_INVALID_STOPSStop loss, take profit, or pending order price is invalid
131ERR_INVALID_TRADE_VOLUMEThe lot size is invalid
134ERR_NOT_ENOUGH_MONEYThe 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_STOPLEVEL before 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

Related: OrderSend Error 134 in MT4/MQL4

Back to MT4/MQL4 Technical Notes

タイトルとURLをコピーしました