How to Automate TradingView Indicator Alerts on MT5
Create two alerts on the indicator: one on its buy signal with the order line long EURUSD q=0.1,
and one on its sell signal with short EURUSD q=0.1, each under your password. Set both to Once
Per Bar Close with your webhook URL. The EA trades every signal on MT5 and closes the opposite trade first.
How do indicator alerts reach MT5?
An alert on an indicator works like any other TradingView alert. When it fires, TradingView sends its message to your webhook URL, which its help pages describe as a way of "allowing you to trigger external bots or scripts". TradingView Link passes the order line in that message to the EA, which places the trade on your MT4 or MT5 account.
The difference from a strategy is the message. A strategy knows which way each order goes and can put that in the message itself. An indicator only has signals, so each direction gets its own alert with a fixed message. If your script is a strategy, follow our strategy automation guide instead.
Indicators can trigger alerts in three ways, and the setup depends on which ones yours offers:
| Alert source | What fires it | Who writes the message |
|---|---|---|
| Alert conditions | The indicator's own signals, listed under Condition, such as Buy or Sell | You do, in the alert's message box |
| Line crossings | Any plotted line reaching a level or crossing another line | You do, in the alert's message box |
| alert() calls | Signals the script's code sends itself | The script, so it must write an order line the EA reads |
How do you set up the buy and sell alerts?
- Open a chart of the symbol and timeframe you want to trade, with the indicator's settings final. TradingView notes that "If you change an indicator's parameters after creating an alert, the alert will still trigger using the original settings".
- Press Alt + A (Option + A on a Mac), or click Create alert. Under Condition, choose the indicator, then its buy signal.
- In Message, put your webhook password on the first line and the order on the second. Here
q=0.1is 0.1 lots; our lot size guide covers sizing by balance, and the webhook guide has the full format.YourWebhookPassword long EURUSD q=0.1 - Set the trigger to Once Per Bar Close, for the reason explained below.
- Under Notifications, tick Webhook URL and paste the URL from your TradingView Link dashboard. TradingView only allows webhooks "when 2-factor authentication is enabled", and its free Basic plan has none, as our webhook plan guide explains.
- Create the alert, then repeat with the sell signal and
shortin place oflong:YourWebhookPassword short EURUSD q=0.1
Together the two alerts reverse the position on every signal. Before the EA opens a buy, it closes any sell on the same symbol with the same magic number, and the other way round. It runs its session, range and maximum-trade checks first, and if one fails, nothing closes and nothing opens, as the close guide describes.
What if the indicator has no buy or sell signals?
Alert on its lines instead. Any plotted line can be the condition: TradingView's technical alerts fire when a value "Reaches, exceeds, or falls below a certain level", and its conditions include crossings of another line. Under Condition, pick the indicator's line, a crossing, and the level or second line. For example:
- RSI crossing up through 30 sends
long EURUSD q=0.1. - RSI crossing down through 70 sends
short EURUSD q=0.1. - A 20-period moving average crossing the 50-period one needs one alert for each direction.
Each crossing direction is a separate alert with its own message, set up as above.
What about indicators that send alert() calls?
Some scripts offer no conditions and send alerts from their code with the alert() function.
Pine Script's docs say it "allows for dynamic alert messages, works in both indicators and strategies". The
catch is that the script writes the message, so it only trades if the script writes an order line the EA
understands.
If you can edit the script, build the order line in it. This indicator sends a buy or a sell on moving average crossings, with the password and lot size in its inputs, so the password isn't in the code:
//@version=6
indicator("MA cross alerts for MT5", overlay = true)
password = input.string("", "Webhook password")
lots = input.float(0.1, "Lots")
fast = ta.sma(close, 20)
slow = ta.sma(close, 50)
plot(fast, "Fast")
plot(slow, "Slow")
if ta.crossover(fast, slow)
alert(password + "\nlong " + syminfo.ticker + " q=" + str.tostring(lots), alert.freq_once_per_bar_close)
if ta.crossunder(fast, slow)
alert(password + "\nshort " + syminfo.ticker + " q=" + str.tostring(lots), alert.freq_once_per_bar_close) Create one alert on the indicator and pick its alert() function calls under Condition. That single alert
sends both directions. syminfo.ticker is TradingView's name for the symbol, so add your
broker's suffix if it has one, as our symbol mapping guide
shows. alert.freq_once_per_bar_close means "An alert is only triggered when the realtime bar
closes", in the docs' words.
Can the alert set a stop loss from the indicator?
Yes, if the indicator plots a level you'd use as a stop, such as a trailing line under the price. Alert
messages can carry plot values: Pine Script's docs show the {{plot_0}} placeholder, "where the plot
number corresponds to the order of the plot in the script". Send it as slp=, the stop loss
price:
YourWebhookPassword
long EURUSD q=0.1 slp={{plot_0}} Check the value in the alert log before going live, because plot_0 is the script's first plot, which isn't
always the line you notice first. The stop must be below the price for a buy and above it for a sell. The EA
sends the stop with the order, so a stop on the wrong side gets the whole order rejected with 10016, Invalid
stops (130 on MT4), after the opposite trade has already closed. Fixed distances work too:
the stop loss guide covers sl=,
tp= and their price forms.
Which alert trigger should you choose?
Once Per Bar Close. While a bar is open, an indicator's values move with the price, so a signal can appear mid-bar and be gone by the close. An alert that fires mid-bar can trade a signal your chart no longer shows. Pine Script's docs put it plainly: "The simplest way to avoid this type of repainting is to configure the triggering frequency of alerts so they only trigger on the close of the realtime bar".
The trade-off is timing. The order goes in when the bar closes, not when the line first crosses, and on a
4-hour chart that can be hours later, so choose the timeframe with that in mind. For alert conditions and
line crossings, you set the trigger in the alert dialog. Scripts that use alert() set it in
their code, as in the example above.
How do you close trades from indicator signals?
Reversing isn't the only exit. These order lines cover the usual cases, each under your password:
| Signal | Order line |
|---|---|
| Buy signal | long EURUSD q=0.1 |
| Sell signal | short EURUSD q=0.1 |
| Exit signal, close the symbol | flat EURUSD |
| Exit buys only | flat EURUSD t=long |
| Buy with the indicator's line as the stop | long EURUSD q=0.1 slp={{plot_0}} |
flat closes open positions on the symbol with the same magic number, in both directions unless
t= picks one. Our guide to closing trades has the
other options. If two indicators trade the same symbol, give each its own magic number with
m=, so one indicator's sell doesn't close the other's buy, as
the magic number guide shows.
Do indicator alerts keep running?
Not forever. TradingView says "The maximum lifetime of a standard alert is two months", while its Premium and Ultimate plans add an open-ended option. When an alert expires, its signals stop reaching MT5, so note the expiry date and recreate the alerts before then.
Recreate them after changing the indicator's settings too, since existing alerts keep the old ones. To see whether TradingView sent a signal, check the "Webhook status" column in the alert log, then our troubleshooting guide for the EA's side.
Frequently asked questions
Can I automate an invite-only or closed-source indicator?
Yes. You don't need its code: create alerts on its buy and sell conditions or on its plotted lines, and write the order line yourself. The script's code stays hidden either way.
Do I need to know Pine Script?
No, unless the indicator only sends alert() calls in its own format. Alert conditions and line crossings only need the order line in the alert's message box.
Why did my alert open a trade the chart no longer shows?
The alert most likely fired mid-bar, before the signal was final. Set the trigger to Once Per Bar Close so it only fires on signals that are still there when the bar closes.
How many alerts does one indicator need?
Usually one per direction on each chart: a buy alert and a sell alert. A script that sends alert() calls can trade both directions from one alert.
Do TradingView alerts expire?
Yes. A standard alert lasts two months at most, so recreate it before then. TradingView's Premium and Ultimate plans can keep alerts running with no end date.
Can the message include the indicator value?
Yes, with plot placeholders such as {{plot_0}}, which TradingView fills in with the value when the alert fires. Send it as slp= when the indicator plots a stop level.
Does this work the same way on MT4?
Yes. The MT4 EA reads the same order lines and also closes the opposite trade before it opens a new one.
Sources
- TradingView: introduction to TradingView alerts (alert types, settings, lifetime)
- TradingView: how to configure webhook alerts (2-factor authentication, webhook status)
- TradingView: how to use a variable value in alert (placeholders)
- Pine Script docs: alerts (alert conditions, alert(), plot placeholders, repainting)
All checked November 2026. How the EA reverses positions, closes trades and sends stops 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
- TradingView alert stop loss and take profit on MT4 and MT5
- How to close MT4 and MT5 trades from a TradingView alert
- TradingView alert lot size and risk per trade on MT4 and MT5
- TradingView to MT5 symbol mapping: names and suffixes at 9 brokers
- 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