How to Automate TradingView Indicator Alerts on MT5

Last updated · By the TradingView Link team
Short answer

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:

How an indicator can trigger an alert, and who writes the message
Alert sourceWhat fires itWho 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?

  1. 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".
  2. Press Alt + A (Option + A on a Mac), or click Create alert. Under Condition, choose the indicator, then its buy signal.
  3. In Message, put your webhook password on the first line and the order on the second. Here q=0.1 is 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
  4. Set the trigger to Once Per Bar Close, for the reason explained below.
  5. 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.
  6. Create the alert, then repeat with the sell signal and short in place of long:
    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:

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:

Order lines for indicator signals
SignalOrder 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.

Test your indicator alerts on a demo account
Connect TradingView to MT4 or MT5 and send your indicator's buy and sell alerts to a demo account. 5 free alerts a month, no credit card.

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

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