How to Send Stop Loss and Take Profit from TradingView Alerts to MT5
Add sl= and tp= to the alert's order line, such as
long EURUSD q=0.1 sl=300 tp=600. Plain numbers are points, the broker's smallest price step,
so that's a 30-pip stop and a 60-pip target on 5-digit EURUSD. Add % for a percentage, or
use slp= and tpp= for exact prices.
How do you add a stop loss and take profit to an alert?
A TradingView Link alert message has two lines: your webhook password, then the order. The stop and target go on the order line, after the size:
YourWebhookPassword
long EURUSD q=0.1 sl=300 tp=600 Each one can be a distance in points, a percentage or a price, and a trailing stop has its own parameter:
| Parameter | Example | What it sets |
|---|---|---|
| sl | sl=300 | Stop 300 points away |
| sl with % | sl=1% | Stop 1% of the price away |
| slp | slp=1.0780 | Stop at that price |
| tp | tp=600 | Target 600 points away |
| tp with % | tp=2% | Target 2% of the price away |
| tpp | tpp=1.0860 | Target at that price |
| ts | ts=200 | Trailing stop 200 points behind |
You can mix them, such as a price stop with a target in points. If a line has both sl= and
slp=, the EA uses the price. Leave both out and the trade opens with no stop. The EA sends the
stop and target with the order, so they sit on your broker's server.
The webhook guide lists every other parameter.
How many points are in a pip?
A point is the smallest price step of a symbol. Your broker sets how many decimals each symbol has, which
MetaTrader calls Digits. On 5-digit forex quotes, 10 points make one pip, so sl=300 is 30 pips
on EURUSD, not 300.
| Quote | 1 point | sl=300 is |
|---|---|---|
| EURUSD at 1.08123 | 0.00001 | 30 pips |
| USDJPY at 151.234 | 0.001 | 30 pips |
| Gold, 2 decimals | 0.01 | 3.00 in price |
| Index, 1 decimal | 0.1 | 30.0 in price |
| Bitcoin, 2 decimals | 0.01 | 3.00 in price |
Gold and Bitcoin are where this catches people out. On a quote with 2 decimals, sl=300 is a
move of 3.00, which makes it a $3 stop on Bitcoin. Use a percentage there, such as sl=1%, or a
price.
To check a symbol, right-click it in Market Watch and choose Specification. MetaQuotes' MT5 help describes Digits as the "number of decimal places in the price of the symbol". Signals written in pips need converting: multiply by 10 on 5-digit and 3-digit forex quotes.
Which price are the stop and target measured from?
From the price the trade closes at. On a market order, the EA measures a long's stop and target from the bid, and a short's from the ask. That matches MetaTrader, where, in MetaQuotes' words, "a security is bought at the Ask price and sold at the Bid price".
So the spread adds to the stop and comes off the target. With a 10-point spread, a long sent with
sl=300 tp=600 loses 310 points from its entry price if the stop is hit, and makes 590 at the
target. Percentages start from the same price: sl=1% on a long is 1% below the bid. On a limit
or stop entry with p=, both are measured from the order's price instead.
Prices in slp= and tpp= go in exactly as sent. If your TradingView chart uses
another data feed, its prices can differ slightly from your broker's, so a price stop can land a little
off. Points and percentages always follow your broker's own price.
How do you send your strategy's own stop from Pine Script?
Build the order line in the script and pass it as each order's alert_message. Then put
{{strategy.order.alert_message}} under your password in the alert's message box. TradingView's
Pine Script docs say users "must include"
that placeholder when a strategy uses alert_message. This example sends an ATR-based stop and
target with each entry:
//@version=6
strategy("ATR stops for MT5", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
atr = ta.atr(14)
var float stopPrice = na
var float targetPrice = na
if ta.crossover(fast, slow) and strategy.position_size == 0
stopPrice := close - 2 * atr
targetPrice := close + 3 * atr
msg = "long EURUSD q=0.1 slp=" + str.tostring(stopPrice, format.mintick) + " tpp=" + str.tostring(targetPrice, format.mintick)
strategy.entry("Long", strategy.long, alert_message = msg)
strategy.exit("Exit", "Long", stop = stopPrice, limit = targetPrice, alert_message = "flat EURUSD") The alert's message box then holds:
YourWebhookPassword
{{strategy.order.alert_message}} str.tostring(price, format.mintick) rounds the price to the chart's tick size. Give the exit an
alert_message too. Without one, TradingView puts "an empty string" in place of the placeholder,
so that alert arrives with no order line. The flat keeps MetaTrader in step: it closes the
trade when the strategy exits on TradingView, and finds nothing to close if the broker's stop got there
first. Other placeholders, such as the ticker, don't work inside alert_message, so write your
broker's symbol name into the string.
If your chart's feed differs from your broker's, send a distance instead.
math.round((close - stopPrice) / syminfo.mintick) gives it in ticks, which matches
sl= when the chart's tick size equals your broker's point.
How to automate a TradingView strategy covers strategy alerts
step by step.
How do you move the stop to breakeven?
Send a modify line. It changes the stop and target of open trades and pending orders on that
symbol:
YourWebhookPassword
modify EURUSD sl=-1 | Value | What it does |
|---|---|
sl=-1 | Moves the stop to the entry price |
sl=-2 | Removes the stop |
slp=1.0850 | Moves the stop to that price |
sl=200 | Moves the stop to 200 points from the current price |
tp=, tpp= | Change the target the same way |
A modify only touches trades with the same magic number, so add the strategy's
m= if it uses one. Without m=, it changes only trades opened without one, as
our magic number guide explains.
From a strategy, an alert() call can send it once the price reaches your breakeven level.
Its message comes from the script, so the password and the modify line both go in the code.
Keep that script unpublished.
How does the trailing stop work?
Add ts= to the entry line, with the distance in points:
YourWebhookPassword
long EURUSD q=0.1 ts=200 The EA keeps the stop 200 points behind the bid on a long, or above the ask on a short, and only moves it
in your favour. It starts trailing as soon as the trade opens. MetaTrader's own trailing stop works
differently: it waits until the trade is that many points in profit. If a line has both ts= and
sl=, the tighter of the two applies first.
The EA does the trailing, so MetaTrader has to stay running. MetaQuotes says the same of its own version, which "is executed in the trading platform rather than on the server like Stop Loss". If MetaTrader closes, the stop stays where it was last moved. The EA keeps the distance in the trade's comment, so it carries on when it starts again. That's one reason to run MetaTrader on a VPS.
How do you take partial profits?
There are two ways. The first opens two orders with their own targets, one per line:
YourWebhookPassword
long EURUSD q=0.05 sl=300 tp=300
long EURUSD q=0.05 sl=300 tp=900 Each line becomes its own position, so this needs a hedging account. On a netting account, the two orders merge into one position.
The second closes part of a position later, with cq= on a flat line:
YourWebhookPassword
flat EURUSD cq=50% That closes half of each open EURUSD trade with the same magic number. Add t=long or
t=short to close only one side. The EA rounds the size to your broker's lot step and never
closes less than the minimum lot, so a 0.01-lot trade closes in full. In Pine Script, give
strategy.exit() a qty_percent and the matching message, as TradingView's
strategy docs describe for exits in
several parts:
strategy.exit("TP1", "Long", qty_percent = 50, limit = tp1, alert_message = "flat EURUSD cq=50%") Once the first target is taken, modify EURUSD sl=-1 moves the rest to breakeven.
Why does MetaTrader reject a stop?
Usually for one of three reasons:
- It's too close to the price. Brokers set a stops level for each symbol, which MetaQuotes' help calls a "channel of prices (in points) from the current price, inside which one can't place Stop Loss, Take Profit and pending orders". You'll find it in the symbol's Specification.
- Pips were sent as points.
sl=30, meant as 30 pips, is a 3-pip stop on EURUSD, which can fall inside that channel. - The price is on the wrong side. A long's stop has to sit below the bid and a short's above the ask. A price worked out on another feed can miss when the market is close to it.
Inside the channel, MetaQuotes says, the server returns "Invalid Stops" and "will not accept the order". MT5 logs it as return code 10016, "Invalid stops in the request", and MT4 as error 130. Our troubleshooting guide explains the other codes. Test a new stop setup on a demo account before you trade it live.
Frequently asked questions
Is sl=300 in pips or points?
Points. A point is the smallest price step of the symbol, so on a 5-digit EURUSD quote sl=300 is 30 pips. On a gold or Bitcoin quote with 2 decimals, it is a move of 3.00 in the price.
Can I send the stop as a price?
Yes. slp= and tpp= take exact prices, such as slp=1.0780. If a line has both sl= and slp=, the EA uses the price. From a Pine Script strategy, build the prices into alert_message with str.tostring().
Do my stop and target stay if MetaTrader closes?
Yes. The EA sends them with the order, so they sit on your broker's server. A trailing stop is different: the EA moves it, so it stops moving while MetaTrader is closed and carries on when the EA runs again.
How do I move my stop to breakeven from TradingView?
Send modify with sl=-1, such as modify EURUSD sl=-1. It moves the stop to the entry price on open trades on that symbol with the same magic number. sl=-2 removes the stop.
Can an alert size the trade from the stop distance?
Not by itself. qt=percent sizes from a share of your balance, not from the distance to your stop. To risk a fixed amount, work out the lots in Pine Script and send them in q=. On EURUSD with a USD account, one point is worth $1 per standard lot, so risking $100 with a 300-point stop is 0.33 lots.
Why was my order rejected with Invalid stops?
The stop or target was on the wrong side of the price, or inside your broker's stops level, the minimum distance in points. A pip value sent as points, such as sl=30 for 30 pips, often lands there. MT5 reports it as return code 10016 and MT4 as error 130.
Do these commands work on MT4?
Yes. The MT4 and MT5 EAs read the same sl=, tp=, slp=, tpp=, ts=, cq= and modify commands, and both measure distances in points.
Sources
- MetaTrader 5 help: order types (Stop Loss, Take Profit and Trailing Stop)
- MetaTrader 5 help: Market Watch (symbol specification, Digits and Stops level)
- MQL5 docs: trade server return codes
- MQL4 docs: error codes
- Pine Script docs: alerts (alert_message and alert())
- Pine Script docs: strategies (strategy.exit and qty_percent)
All checked November 2026. What the EA does with each parameter comes from our own MT4 and MT5 EA code.
Related guides
- How to connect TradingView to MT5
- How to connect TradingView to MT4
- PineConnector alternative with MT4 support
- Best TradingView to MT5 bridges, compared
- Free TradingView to MT5 bridge: what you get for $0
- Free and cheapest TradingView to MT4 bridges
- TradingView trade copier for MT4 and MT5: three types compared
- How to automate a TradingView strategy on MT4 and MT5
- TradingView to MT5 not working? How to fix it
- Prop-firm EA rules: FTMO, FundedNext and The5ers
- TradingView webhook to MT5 and MT4: URL, message format and examples
- TradingConnector alternative for MT4 and MT5
- WebhookTrade alternative for MT4 and MT5
- How to convert Pine Script to MQL5, and when not to
- Does TradingView's free plan have webhooks? Plans compared
- Do you need a VPS for TradingView to MT5?
- How to automate a TradingView strategy on FTMO
- FundedNext TradingView automation: EA rules and setup
- E8 Markets TradingView automation: EA rules and MT5 setup
- FXIFY TradingView automation: EA rules and MT5 setup
- How to run multiple strategies on one MT5 account with magic numbers
- TradeSgnl alternative: pricing, MT4 support and TradeSgnl vs PineConnector
- How to send TradingView alerts to Telegram and MT5
- MetaConnector alternative: pricing, MT4 support and MetaConnector vs PineConnector
- SignalForge alternative: pricing, hosting and SignalForge vs PineConnector
- TradingView.to alternative: TradingView To Anywhere vs TradingView Link
- TradersPost alternative for MT4 and MT5: TradersPost vs TradingView Link
- AlgoWay alternative for MT4 and MT5: AlgoWay vs TradingView Link
- How to connect TradingView to Exness (MT4 and MT5)
- How to automate TradingView alerts on Pepperstone (MT4 and MT5)
- How to automate TradingView alerts on IC Markets (MT4 and MT5)
- How to automate TradingView alerts on XM (MT4 and MT5)
- How to automate TradingView alerts on Vantage (MT4 and MT5)
- How to automate TradingView alerts on Fusion Markets (MT4 and MT5)
- How to automate TradingView alerts on RoboForex (MT4 and MT5)
- How to automate TradingView alerts on JustMarkets (MT4 and MT5)
- How to automate TradingView alerts on Axi (MT4 and MT5)
- Pricing: plans, limits and what else you pay for
- Full documentation: alert syntax, EA settings and troubleshooting
- FAQ: trials, billing and signal limits