How to Place Pending Orders from TradingView Alerts on MT5

Last updated · By the TradingView Link team
Short answer

Add p= to the order line. On a long, a minus sign places a buy limit below the ask and a plain number a buy stop above it, so long EURUSD q=0.1 p=-200 is a buy limit 200 points down. Shorts mirror this. A number with a decimal point, like p=1.0800, is an exact price.

How do you send a pending order from a TradingView alert?

A market order trades at once. A pending order waits for a price: MetaTrader's help calls it "the trader's instruction to a brokerage company to buy or sell a security in future under pre-defined conditions". With TradingView Link, any order line becomes one when you add p=, the entry. The EA places it on your MT4 or MT5 account when the alert arrives, and it waits on your broker's server until the price gets there.

p= takes three forms:

This alert places a buy limit 200 points below the current ask:

YourWebhookPassword
long EURUSD q=0.1 p=-200

The first line is your webhook password, and the webhook guide has the full message format.

Which order does each p= value place?

The EA picks the order type from the side of the trade and where the price lands. A minus sign waits for a better price, which makes a limit order. A plain number waits for the price to move further in the trade's direction, which makes a stop order:

Orders placed by p= on a 5-digit EURUSD quote
Order placedOrder linePrice
Buy limit long EURUSD q=0.1 p=-200 200 points below the ask
Buy stop long EURUSD q=0.1 p=200 200 points above the ask
Sell limit short EURUSD q=0.1 p=-200 200 points above the bid
Sell stop short EURUSD q=0.1 p=200 200 points below the bid
Buy limit long EURUSD q=0.1 p=-0.5% 0.5% below the ask
Buy limit or buy stop long EURUSD q=0.1 p=1.0800 At 1.0800: a limit if the ask is above it, a stop if below

MetaTrader's help defines a buy limit as "a trade request to buy at the Ask price that is equal to or less than that specified in the order", and a buy stop as an order to buy at an Ask price "equal to or greater than the one specified in the order". Sells mirror that against the bid. So use a limit to buy a pullback or sell a rally, and a stop to trade a breakout. If an exact price equals the current price, there's nothing to wait for, and the EA sends a market order instead.

How do you set an exact entry price?

Write it with a decimal point. The EA reads any p= value with a dot as a price and any whole number as points, so p=21500 on NAS100 isn't the price 21,500. It's an offset of 21,500 points from the market. Write p=21500.0 instead:

YourWebhookPassword
long NAS100 q=0.1 p=21500.0

On a long, an exact price becomes a buy limit if it's below the ask and a buy stop if it's above. On a short, it's a sell limit above the bid and a sell stop below it. Because the side decides the type, a price the market has already passed flips it: a buy at 1.0800 sent when the ask is 1.0790 becomes a buy stop, which waits for the price to climb back. Offsets such as p=-200 always give the type you chose.

If the price comes from a placeholder, check in TradingView's alert log that it arrived with a decimal point, and use your broker's symbol name, as our symbol mapping guide shows.

How do you make an unfilled order expire?

Add e= with the number of minutes the order may wait. This buy limit cancels itself if the price hasn't reached it within an hour:

YourWebhookPassword
long EURUSD q=0.1 p=-200 e=60

Without e=, the order stays until it fills or you cancel it, so a limit left over from an old signal can still fill days later.

Two limits apply. The MT4 EA rejects expiries of 1 to 10 minutes and the MT5 EA rejects e=1, so use 15 minutes or more. And some brokers don't take expiries on every symbol. MT5 then returns 10022, "Invalid order expiration date in the request", and MT4 error 147, "Expirations are denied by broker". On those symbols, leave out e= and cancel the order with a second alert.

How do stop loss and take profit work on a pending order?

Add them as usual. On a pending order, sl= and tp= are measured from the order's price, not the current price, so this buy limit gets a stop 300 points below its entry and a target 600 points above it:

YourWebhookPassword
long EURUSD q=0.1 p=-200 sl=300 tp=600

The EA sends both in the same request as the order, so the stop is in place from the moment the order fills. MetaTrader's help says stops "are always associated with an open position or a pending order". Brokers also set a minimum distance, the Stops level: a "channel of prices (in points) from the current price, inside which one can't place Stop Loss, Take Profit and pending orders". An order inside it is refused with "Invalid Stops". A symbol's Stops level is in its specification in Market Watch. Our stop loss and take profit guide covers exact stop prices, percentages and trailing stops.

What happens to open trades when the alert arrives?

Before the EA places a buy limit or buy stop, it closes your sells on that symbol with the same magic number, and a sell order closes the buys. That happens when the alert arrives, not when the order fills, so long EURUSD q=0.1 p=-200 closes an open short at once, and if the limit never fills, you're left flat.

To keep the short until the buy fills, give the pending order its own magic number with m=, as the magic number guide explains, and close the short with its own alert. The close guide explains reversals.

Unfilled orders also count toward the EA's MaxTradePerSymbol input, 10 by default, which caps open trades plus pending orders on a symbol. Old limits that never filled can use it up, and then new alerts on that symbol fail with Exceeds max trades. An expiry stops them piling up.

Can one alert place several limit orders?

Yes. Each line of the message is a separate order, so one alert can place a ladder of limits at different distances. This one splits 0.3 lots over three buy limits, 100, 200 and 300 points below the ask:

YourWebhookPassword
long EURUSD q=0.1 p=-100
long EURUSD q=0.1 p=-200
long EURUSD q=0.1 p=-300

Each order fills on its own when the price reaches it, and each line can take its own e=, sl= and tp=. Every rung counts toward MaxTradePerSymbol, so a ladder of 10 fills the default allowance. Our lot size guide covers sizing by balance or risk.

Do Pine Script strategy limit orders reach MT5 as limit orders?

Not on their own. Pine Script's docs define a limit order as "an instruction to buy or sell an instrument at a specific price or better", placed with the limit parameter of strategy.entry(). But a strategy's order alerts fire on fills: "When an order placed by the strategy is executed by the broker emulator, an alert is triggered." By then the simulated limit has filled, and the EA opens a market order at that moment's price. p={{strategy.order.price}} doesn't help, since that placeholder "returns the price at which the order was executed".

For a real pending order on MT5, alert when the strategy places the order. alert() calls can fire "when orders are sent to the broker emulator in strategies", so call it once, when the signal starts, with the same price in p= and an e= that matches how long the strategy keeps the order. Expect it at the bar's close: "By default, strategy scripts execute alert() function calls only on the close of realtime bars".

Then create the alert on alert() calls alone. "A script alert created from a strategy can trigger on alert() function calls, on order fill events, or both", and with both, the fill can send a second order at market. Our indicator alerts guide shows a script that writes the order line itself.

How do you move or cancel a pending order?

Send cancel with the symbol. It deletes that symbol's limit and stop orders with the same magic number, and t=long or t=short limits it to one side:

YourWebhookPassword
cancel EURUSD

flat closes open positions but leaves pending orders alone, so an exit that should also drop unfilled entries needs a flat line and a cancel line in the same message. The close guide has more on cancel.

To move an order to a new price, cancel it and send a new one. A modify line changes the stop and target of pending orders too. Add e= to it if the order should still expire; the new expiry counts from the modify.

Why was a pending order rejected?

The EA prints the reason in MetaTrader's Experts tab. The first four come from your broker's server, the last two from the EA:

Pending order errors and what to do
ErrorCauseFix
Invalid stops (10016, or 130 on MT4) The order, its stop or its target is inside the symbol's Stops level Place the order further from the price
Invalid price (10015, or 129 on MT4) The server refused the order price Check p=, and write exact prices with a decimal point
Invalid expiration (10022, or 147 on MT4) The broker doesn't take an expiry on this symbol Leave out e= and cancel with a second alert
Pending order limit (10033, or 148 on MT4) The account has reached the broker's cap on orders Cancel old pending orders
Invalid expiration time The EA refused e=: 1 minute on MT5, 1 to 10 minutes on MT4 Use e=15 or more
Exceeds max trades Trades plus pending orders on the symbol reached MaxTradePerSymbol, 10 by default Cancel unfilled orders, or raise the input

Our troubleshooting guide lists the other EA messages and codes.

Test a limit order alert on a demo account
Connect TradingView to MT4 or MT5 and send a buy limit with an expiry to a demo account. 5 free alerts a month, no credit card.

Frequently asked questions

What is the difference between a buy limit and a buy stop?

A buy limit waits below the current price, to buy a pullback more cheaply. A buy stop waits above it, to buy once the price breaks higher. In an alert, p=-200 places the first and p=200 the second.

Does a pending order close my opposite trade straight away?

Yes. When the alert arrives, the EA closes trades in the other direction on that symbol with the same magic number, then places the order. Give the order its own magic number to keep them open.

How long does a pending order stay open?

Until it fills or you cancel it. Add e= with minutes, such as e=60, to make it cancel itself. Use at least 15 minutes, since the MT4 EA rejects expiries of 10 minutes or less.

Do pending orders fill when MetaTrader is closed?

Yes. A pending order sits on your broker's server, so it can fill or expire while MetaTrader is closed. MetaTrader and the EA have to be running to place, change or cancel it.

Can a Pine Script strategy send limit orders to MT5?

Yes, but not through its fill alerts, which only fire once TradingView has filled the order. Send an alert() call with p= when the strategy places the order, and set the alert to trigger on alert() calls only.

Does this work the same way on MT4?

Yes. The MT4 EA reads the same p=, e= and cancel lines and picks limit or stop orders by the same rules.

Sources

All checked November 2026. Which order the EA places for each p= value, and how it handles e=, stops, cancels and open trades, comes from our own MT4 and MT5 EA code.

Related guides